miercuri, 29 iunie 2011

What's the "new" reserved word for in the first place?

This idea came to me today, that i don't see any actual need for the new keyword.

It's used to invoke the the code for creating an object, along with its constructor... but do we actually need it?

Why is "return new Integer(i)"
any more intelligible than
"return Integer(i)"?

Maybe its use has something to do with readability... perhaps it's good because it makes it stupidly obvious that you're not just calling a normal method.

But is it worth the cost of writing a whole nother 4 characters just to make something more obvious?
Well i guess i wouldn't want to guess through source code what "Scraps scraps= Patches(3,4)" means, even if it's a standard to have all your classes named with an initial capital letter.
Is patches a factory method, is is a regular, or is it a constructor....

Yeah, i'd surely put in the effort of writing 4 extra letters for the visibility.

Niciun comentariu:

Trimiteți un comentariu