Linked by Bjorn Raupach on Thu 17th Jul 2008 06:01 UTC
Thread beginning with comment 323539
To view parent comment, click here.
To read all comments associated with this story, please click here.
To view parent comment, click here.
To read all comments associated with this story, please click here.
RE[7]: Never programmed in Java before...
by renox on Fri 18th Jul 2008 14:58
in reply to "RE[6]: Never programmed in Java before..."
Er, not really. const is a standard feature in C++ for declaring, well, constants.
Except that const are not always constants in C++.
It's hardly a hack: certainly no more than inventing silly ways to return multiple values from a function.
I find much more readable to have the input variable on one part of the function and the output variables on another part, of course readability isn't C++ strong point.
RE[8]: Never programmed in Java before...
by ebasconp on Fri 18th Jul 2008 15:40
in reply to "RE[7]: Never programmed in Java before..."
"Er, not really. const is a standard feature in C++ for declaring, well, constants.
Except that const are not always constants in C++.
"
Agree, "const-ness" defines a set of properties and behaviors over our methods and variables.
Let's say:
const Attribute& GetAttribute() const;
A method marked with "const" says: "I will not modify the object state, I will only provide information"; this feature prevents a lot of errors and undesired access because it is hardly viral (for this example, you cannot invoke to a "non-const" method defined in Attribute).
The "const Attribute& " returns a reference to an attribute defined inside our object (a really nice approach to avoid object copy or memory management "ambiguity") If I get a const Attribute& I'm getting a working state and I have not to worry about its memory handling.
"const-ness" should be implemented in other C-like (I knew D implements it partially) languages because provides nice behavior and improves the code readibility too.







Member since:
2005-07-06
Er, not really. const is a standard feature in C++ for declaring, well, constants. Same as it is in C, and it's been that way forever. It's hardly a hack: certainly no more than inventing silly ways to return multiple values from a function.
Also, who said anything about pointers here? C++ supports proper bona fide pass by reference.