I have been using C++ and Java for several years now. One thing which I can't seem to understand is that why do we need to provide constructors of a class a name? For instance, if I have to define a class FOO
in C++/Java, I'll be forced to provide FOO
as the constructor name. However, since constructor is never explicitly called, what is the sense in compiler forcing me to provide it a name after all.
The abstraction paradigm dictates, we hide unnecessary details from programmers. This is the reason, constructors don't have a return type, since it's already well-defined what a constructor has to return. In the same spirit, why can't we just give a generic name to constructors of all classes - for instance anything meaningful, like initialize()
or maybe just nothing and just arguments ( [arg [,arg]] )
I hope, I'm able to express myself. If someone have any definitive answers, kindly let me know.