Comments

Back to the High Programmer's Blog

Back to the article

Alan De Smet at 21:18 Nov 12, 2006

Fscking spammers. You're wasting your time. 1: I use rel=nofollow, so you're not getting any Google PageRank for your spam. 2: I flag spam pretty quickly; I'm notified of new comments within a few minutes.

All that said, it's getting a little annoying flagging the spam, so I've added the World's Dumbest CAPTCHA. Inspired by Lawrence Lessig's blog, you just type the magic word (it's "human", for now), into the provided box. It's not great security, but hopefully it's enough. On the up side, it's really easy to implement and really easy to use (I hope. Sorry for the bother, blame the scum willing to piss all over the internet for short term gain.

Peter Keller at 22:31 Nov 14, 2006

If instead of the word "human", the word is random, and you don't tell us what the word is, I bet that'll cut down on the rest of the content free comments that might get posted.

Paul at 12:36 Jan 12, 2007

Excellent article. Just want to send some thanks for clearing that up. (sorry to hear about the spam, sucks)

Ram at 2:40 May 18, 2007

Good Article. Thanks for clarifying.

Christian at 3:38 Aug 3, 2007

Very helpful article: I just spend 3 days entangled in a debugging issue related to mutable and you have put in words what I had been sensing all the way. Thanks a lot!

Bob at 9:11 Aug 28, 2007

Thank you for making this subject clear by presenting clean examples. =)

Andrei MR at 10:32 Aug 29, 2007

Thanks for clarifying 'mutable.' It's nice to know that I continue to never need it. That C++ needs keywords like 'mutable' (like 'virtual') is evidence that C++ is a terrible language.

Alan De Smet at 17:44 Aug 29, 2007

"That C++ needs keywords like 'mutable' (like 'virtual') is evidence that C++ is a terrible language."

Utter nonsense. C++'s const and mutable are a powerful pair of features that allow greater enforcement of programming contracts. This post gives a good example of C++, thanks to const, being able to enforce a programming contract in a way that Java can't. (I've chosen Java because it's frequently regarded as being much better than C++. Admittedly I have no idea what languages you actually prefer over C++.) And once you have const, you'll need (however infrequently) mutable to handle the special cases where an object is logically constant, but for implementation reasons need to change.

Brooks Van Pelt at 5:06 Sep 20, 2007

Alan: I just read your posting, and these comments, and thought I'd add a pertinent comment. I often have to keep sets of data in memory, and typically package each "element of a set" (think struct !) as a class. Once its in a class its easy to store in a set; I just implement operator < so I know which members of the class form the "key" and which are associated data. This works nicely for me until I need to modify the class members which are not a part of the key (obviously I don't want to modify the key!). The compiler I use on our SUN machines here at work complain that I'm trying to modify a const object (the object member in the set). The VC++ compiler I ofter use for initial development doesn't complain about this. I can't decide which is worse: complaining about modifying a non-const member (the compiler can't tell which are key elements and which aren't !), or the lack of complaint (it will allow me to ruin the underlying b-tree structure by modifying a key-member? Sheesh!). I just battled through this this am, and ended up just putting the data into both sides of a map (I know! I know!). When I have a sec I'm going to explore "mutable" on the Sun side to see if it stops complaining. There's no hope for the VC++ side, as its allowing something it really shouldn't! Brooks

Matthew at 7:20 Dec 4, 2007

Nice article, I have seen the best use of mutable when dealing with classes designed to be thread-safe. Since many string and classes of the like (which are very mutable in C++ unlike Java and C#) don't handle being written to and read from at the same time very well, it is nice to have thread synchronization features of the OS to prevent corruption, problem is, without mutable... const functions can't manipulate these structures. To Andrei MR: Java does on the other hand have some point in making the class define the constness of an object rather than the methods, but it also limits the possibilities. Doesn't make either a better languages, just like C++ requires the nasty looking dynamic_cast when trying to reproduce even Java's one class multiple interfaces inheritance if both a base class and a implemented interface have the same base. Java can handle this with nicer looking code and probably better than C++.

Andrew Que at 9:55 Jan 23, 2008

Thanks for that article. I kept asking myself why someone would want the mutable keyword, since it just seemed like a bad idea. The pi example makes sense, although I still see very few places this keyword is a good practice.

Happy coding, A.A.Que

Kenneth Porter at 16:10 Mar 7, 2008

Shouldn't Employee::promote lack the const keyword?

Alan De Smet at 17:22 Mar 7, 2008

Kenneth: You are most certainly correct. Thanks for pointing it out. I've fixed it.

Post Message

Your name:
The word "human": (To fight comment spam you must enter the word "human" in this box.)
Your web site: (optional)
Your email address: (optional)
(Your email address is not displayed to others nor stored. It is only used to display a Gravatar Avatar.)



Supported tags: [B]Bold text[/B]   [I]Italic text[/I]   [TT]Typewriter font[/TT]   [CODE]Preformatted text[/CODE]   [QUOTE]Block quote[/QUOTE]   [QUOTE="Original Author"]Block quote[/QUOTE]   [URL="http://www.example.com"]Example Corporation[/URL]