See My Coffee: A C and Java tale

Anyone with half a brain can tell you that (pick one: C/C++ or Java) is vastly superior to (pick the other). The only problem is that I don’t know all that much about Java. So instead of doing the obvious thing and talking about how “C/C++ is better than Java”, I am going to talk about a few aspects of C++ that annoy the hell out of me.

Fist off why would you have a ‘long‘ data type if it is not required to be any bigger than a regular ‘int‘?  All that is specified is that both int and long must be at least 32bits. Thus if you want to get a 64bit integer you have to use ‘long long‘ (or __int64 if you are using Microsoft Visual C++).  This should really be addressed, and hopefully sometime soon. Though I suppose there are more pressing issues.

Second, I don’t know about you but no one ever told me why you it is poor C++ programming to include a class function’s definition inside the class.  It wasn’t until I was reading Thinking in C++ Vol.1 that it was made clear.  When you do this, the compiler will inline your function.  This means that everywhere you use it the compiler will reproduce the written code, instead of making a function call.  Sure, for small functions this is alright, but for larger ones it can add to code bloat, thus possibly resulting in a slower program.  The “standard” for determining if a function is small is, “does it take up more than one line of code?” If so then don’t inline.

Why are struct and classes the same?  The only difference is that the members of a class default to private, while those of a struct default to public.  Oh well, until they change this I will continue to use struct and then specify private/protected/friend when needed.

Finally, the STL is not quite as vast as the Java API.  But that can be attributed to what the languages were designed for, so I suppose I can live with this “fault”.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: