Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
User Journal

Journal Com2Kid's Journal: Why don't people just add some syntatic sugar to C++? 5

I was reading a really old document and GCC has (had?) this C++ extension that lets you use the .. operator to do things like if( myChar == "A".."Z" ) ...

This is one of the few things I liked about Ada, you get the nice little range operator! You won't believe how handy this is!

int intArray[1..10];

Hey look, no more off by 1 errors!

Now for some types of problems, 0 based arrays are REALLY nice, often times when doing stuff involving the modulus and what not. No problem

int modArray[0..9];

This is a very simple (stupid simple) thing for the compiler to implement. Heck it can be done already using pointers any ways, it is just a pain to set up.

Oh and vectors piss me off because I can't fix their size, anybody know of a data storage type in C++ that gives me the .length() or .size() attribute AND is of a fixed size?

I was reading some C++ stuff on the internet, and this C++ guru dude was bitching about how inefficent Java's syntax for allocating an object was;

ObjType myObj = new ObjType();

He said it was way too redundent and slowed down a programmer's overall coding speed.

Hey now, stuff is CODED once, and DEBUGGED forever-after.

Edit: C++ is internally consistent, in general something needs to be deleted only if it was newed, so that is ONE advantage of limiting use of the new operator. The disadvantage being that you end up with 4+ ways to declare and initialize a variable.

ObjType myObj;

instanciates an instance of myObj, depending on where you declare it at.

Of course, for pointers;

ObjType* myObj = new ObjType;

if you are not using the default constructor:

ObjType* myObj = new ObjType(param a, param b, ... )

Now mind you for non-class types to get a variable assigned a value you do

Type myVar = someValue;

Compare this to Java, there are TWO and ONLY TWO ways to get yourself a variable with an assigned value.

Type myVar = someValue;

Type myVar = new Type();

first form for non-classes, second form for class types.

DONE DONE DONE DONE DONE

Without the equals sign it is ALWAYS a variable declaration NOT initilization, not like in C++ where if you do

ClassType myVar

in a .H file you get a declaration, in a .CPP file you get an initilization (at least under MY compiler, results may vary I guess, at least from the responses I get from classmates + instructor)

Fun, nope. Irritating.

Double edit: Oh and I just love how a foreward declaration of a class is not consistent with how classes are normally declared, since when a class is normally declared it gets initilized, like it or not. (yes this is proper OO in one sense, a class should always have a valid state, but on the other hand, if an uninitilized class is actually USED for anything the program is going to barf anyways, so it is not like data corruption is going to occur!)

Blech! Somebody needs to BASH SUN ON THE HEAD and have them standardize on a MACHINE CODE COMPILER for Java. Wipe the earth of these other languages.

Actually someone just needs to beat Sun upside the head in general.

This discussion has been archived. No new comments can be posted.

Why don't people just add some syntatic sugar to C++?

Comments Filter:

"Survey says..." -- Richard Dawson, weenie, on "Family Feud"

Working...