Thursday 15 January 2009

Two Reasons Why I Prefer C to Java

There are two specific reasons why I prefer C++ to Java: operator overloading and pointers. I strongly believe that these are related to the fact that I started learning C++ first, but I still find them critical to my preference for C++.

Operator overloading, for me, is a critical feature in C++ for providing intuitive code. When creating a mathematical class, such as BigInt, I want to be able to work with variables of that type the same way I work with variables of type int. If + is a meaningful operation on a class, I want to be able to use it. Moreover, I don't want to have to wrap my built-in type int in a class with .add(), .minus(), etc methods so that I can create a template for building rational numbers. I realize that this is a side-effect of my math background, but I believe that I should be able to write math with math symbols wherever possible.

The other irritation I have with Java is that it weakened pointers as found in languages like C++ and Pascal to what it calls a "reference". Anyone who is familiar with pointers in other languages will recognize that Java is using the pointer concept, but weakening it to make the language safer. I realize that this is a deliberate design decision, but it is a decision that irritates me in its implementation. It is both less function than C++ pointers, and more powerful in that it handles garbage collection. For me, losing pointer arithmetic for garbage collection is a bad trade
.

0 comments: