News for hackers. Stuff that matters.
Re:Hello. I'm a compiler by bitwize on Tuesday February 19, 2013 @12:07PM (#5245448)
Oh God. Don't get me started on const.

    const char * const fuck_this(const char *shit) const;
Thing #1: In C++ the word "const" can mean many things depending on position and inflection: declaring a symbol an actual constant; a pointer argument has in (as opposed to in-out) semantics; a function has no side effects. I keep forgetting which use of const does what.

Thing #2: Each use of const, regardless of meaning, induces a different type. Which makes API design a pain in the ass since you can't pass in stuff that wasn't declared with the same constness if the procedure expects const parameters without casting the parameters. I actually worked on a codebase where a guy broke much of our code by checking in a "fix" for our APIs to make them comply with what he considered best practice regarding constness.

Thing #3: Passed-in pointers and references are not 'const' by default. You should have to declare intent to clobber their referents.

Thing #4: And as someone said downthread, you can cast around it in most cases anyways.

This is why I say, if you're thinking of using C++, reach for Ada instead. Ada's reputation has been necessarily tainted by whiners complaining about its verbosity. But I swear that figuring out a page of Ada code is easier than figuring out a few lines of sufficiently complicated C++. For one thing, in Ada, function/procedure parameters are 'in' (i.e., const) by default, and you must declare intent to modify parameters in side effects by declaring them 'in out'.

There are no comments on this comment yet.