
-----------------------------------
wtd
Tue Jan 04, 2005 4:06 am

Which programming language should I learn? (Updated)
-----------------------------------
I've seen it asked several times: what programming language should I learn?

I like answering this question, so I thought I'd do so in one place by listing pros and cons for several different languages.  I may also organize it into a chart, but there are a lot of categories and a lot of languages, and some of the scores would be subjective.  :)

Assembly

Pros:


Fast.
Can open up job prospects that many programmers aren't trained for.

Cons:


Not portable.  Your code won't translate between different processors, or often even different operating systems running on the same processor.
Poor documentation.  Docs are often either very scarce or not written for beginners.  Sometimes books on assembly programming can be quite expensive.
Very low-level.  Assembly addresses problems related very specifically to hardware, rather than demonstrating general good software design practices.  What you learn in the process of learning assembly language generally won't apply well to other programming work.

C

Pros:


Fast.  Nearly as fast as assembly, but easier to develop.
It's everywhere.  Nearly every hardware and software platform implements at least some of the C standard.
It's standardized.  There is a standard you can code to, rather than worrying about each compiler actually working on a slightly different "version" of C.

Cons:


Manual memory management.  The most frequent problems students and professionals alike have are with managing memory.  It gets in the way of teaching other general skills.
No string type.  Along with the previous point, this makes it cumbersome to do even basic programming in C without considerable experience.
A relatively limited standard library forces programmers to turn to nonstandard 3rd party extensions, or to reinvent the wheel.
Very limited facilities for code re-use.
Many errors involve code that compiles, but then fails with cryptic linker messages, making it difficult to find the bug that caused them without a significant amount of experience.
No support for object-oriented programming.  It's possible, but the language doesn't help.

Code:

#include 

int main()
{
   puts("Hello world");
   return 0;
}

Adding a simple function/procedure:

#include 

void greet();

int main()
{
   greet();
   return 0;
}

void greet()
{
   puts("Hello world");
}

C++

Pros:


Fast.  Almost as fast, and sometimes as fast as C.
Nearly as widely available as C.
Standardized, though not as long as C has been.
Good support for object-oriented programming, including multiple inheritance.
Amazingly powerful template system.
Standard Template Library.  This collection of classes and functions makes it easy to do powerful things.

Cons:


Lots of sources don't teach standard C++.  Worse, they often teach C concepts which ignore the power of C++ and leave programmers doing more work to write worse code.
Somewhat better for code re-use than C, but not good.
Complex, often tricky syntax which contains many subtle variations.  A simple typo can produce code that compiles, but does something very different than what was intended.
Memory management is a bit better than C, but still presents frequent pitfalls.

Code:

#include 

int main()
{
   std::cout 