Re: C++ vs Java
I've been a programmer for 35 years, and I'm competent in C, C++, COBOL,
BASIC, JAVA, PL/1 and others. Here are some things the other people haven't
As was mentioned, in C and C++ the programmer is responsible for allocating
and freeing memory. That memory is usually accessed with a "pointer," a variable
with a memory address in it. I've heard it said more than once that the vast
majority of bugs in C and C++ have to do with memory allocation and reference
errors. My own experience seems to bear that out. One of your respondents
mentioned that JAVA and C# use garbage collection. That means that the programmer
never allocates or frees memory, and never deals with pointers. I've found
that with JAVA, I no longer produce some of the horrific bugs that I did
Programming languages have evolved over time, trying (IMHO) to do two things.
1. - create a language that mimics the way the programmer thinks, and 2.
- guide the programmer’s style of design and coding.
#1 was the idea behind the first modern (“third generation”) programming
language, FORTRAN (“FORmula TRANslation). Statements in FORTRAN are algebraic
equations, which mimics the way an engineer thinks. The next major one was
COBOL, which attempted to mimic the way business accountants think: Statements
look like English.
#2 is actually a significant driving force in the evolution of languages,
and often changes the way that programmers think (thus affecting what happens
in #1). Researchers have discovered that style of programming has a significant
impact on the quality of software. There’ve been at least three revolutions
in programming style.
The first happened in the 50s, I think (it was before my time), and was called
“top-down” programming. It meant that you started with the most general concept
(like a payroll system) and you coded functions at that general level (functions
like “produce payroll check”) even before you’ve created the lower level
routines (like “calculate deductions” and “print”). This meant you had to
write dummy programs (called “stubs”) for the lower level routines. This
is sometimes called “functional” programming because it sees the parts of
the software as a set of functions: “do this function, then do that one.”
The second revolution, called “Structured Programming,” hit the software
business pretty hard in the early 70s, and we’ve never been the same. It
was controversial for a while (because people don’t like to give up old habits),
but now it’s so common that the name is not even used anymore. Everyone practices
structured programming, but doesn’t know it. To write an unstructured program,
you need a “goto” statement, which doesn’t even exist in JAVA. I would love
to show you what a “spaghetti” program looks like. If you follow the thread
of execution, it actually looks like a bowl of spaghetti. When the term "spaghetti"
was first used, everyone laughed long and loud. Nobody had to explain it
to us. We all knew that it referred to our own code.
So when we combined Top-Down with Structured, it was like a regime change.
It literally was a new way of looking at the world. The “case” statement
was invented to facilitate structured programming. “Goto,” which once had
been an essential concept, was now an obscene word. Modula-2 was designed
without it, partially out of arrogance of the inventor (“I won’t have any
gotos on my record,” or something like that). We all thought that we had
learned the ultimate programming style, one that would free us from buggy
code and long development schedules. Today, it’s not the ultimate style.
It’s just good programming practice.
The next revolution was Object Oriented. It began with a language called
“Simscript,” which was for writing simulations. Objects are natural in simulation.
If you want to simulate traffic, for example, you want to have objects called
“cars.” Again, we had to completely change the way we viewed the world. Object
orientation, by nature, is contrary to the functional view. In fact, it made
top-down obsolete. With objects, the best way to design is bottom-up: Start
with the detailed stuff, and work your way up to the more general. So it
literally turned the old way of thinking on its head.
(C++ is the object-oriented version of C)
At least two languages were inspired directly by Simscript. The ones I know
are SmallTalk and Eiffel. SmallTalk is the most famous, but Eiffel is still
going strong and has a loyal following. A new version of Eiffel even works
with the .NET framework.
One of your respondents pointed out that you can still write non-object code
in JAVA. That's true, but it misses the point. When you learn to code in
JAVA, you learn to think in terms of objects. And that makes you a product
of the revolution, whether you know it or not.
Well, I’d love to talk all night about this, but it’s time for me to meet
my girlfriend and go to a movie (two important functions). If you have any
questions you can write me at Jma26@Bigfoot.com.
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL