<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>const correctness and C++</title>
		<link>http://www.allegro.cc/forums/view/603805</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 19 Apr 2010 10:10:13 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes or No? Discuss!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Sun, 18 Apr 2010 00:47:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Five tons of flax.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (gnolam)</author>
		<pubDate>Sun, 18 Apr 2010 00:48:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ah, I miss const correctness. It was sort of like a little puzzle to play with while you wrote tedious low-level code.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kibiz0r)</author>
		<pubDate>Sun, 18 Apr 2010 00:48:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ah. I was kind of hoping for some enlightened discussion of the topic.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Sun, 18 Apr 2010 00:51:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It helps you out by spitting out errors when you get confused, what else is there to say?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Sun, 18 Apr 2010 00:54:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Useful for what it is: something to help keep you from screwing up. Obviously due to aliasing rules it has no real functional significance, but you know, the same can be said for a lot of syntactic stuff we use. It helps you, the programmer, write code that doesn&#39;t change variables behind the backs of other functions.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Sun, 18 Apr 2010 00:56:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think it makes the code somewhat more readable for other people, if used propertly (ie, don&#39;t bypassing it <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />), since you can explicitly state that a function doesn&#39;t have side effects (though it can still touch global variables, but you don&#39;t have those <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />) or modify the object.</p><p>It would be more useful if it couldn&#39;t be bypased, and that method couldn&#39;t modify global variables or call global/static functions since that would allow compilers to do some optimizations.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Oscar Giner)</author>
		<pubDate>Sun, 18 Apr 2010 01:38:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Const correctness is misleading, to say the least. It&#39;s entirely possible to think that an object is const, whereas some local context uses it as non-const.</p><p>What is better is pureness (the whole context being const).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Sun, 18 Apr 2010 03:07:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>i. hate. constants. They are a jerk to have to deal with, especially when a functions asks for a constant and i need to use a non-constant (which doesn&#39;t happen often, honestly)</p><p>but I wish that constants didnt exist, and they were just regular variables.</p><p>and dislike static too.  But I only hate static because I have yet to figure out how to deal with them in cases other than them being functions. &gt;.&lt;</p><p>just wanted to say that.  I know that pro-programmers must use them all the time for time saving techniques and have no problem, I&#39;m sure. But am I pro? No.  <b>puts on flame retardant suit</b>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (cheatscanner)</author>
		<pubDate>Sun, 18 Apr 2010 12:49:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I like const-correctness. I certainly use it in C++ (and C?). Whether it&#39;s truly useful or not, I can&#39;t say. I think it is, but I could be wrong. I wish a similar, though updated, concept existed in C#. I think in modern, managed languages, the compiler should disallow casting constness away. That way, you could actually rely on the concept. If you declare a variable as const (or cast to const) then you could rely on it not being modified no matter what<span class="ref"><sup>[<a href="#">1</a>]</sup></span>. That would be kind of nice, I think.
</p><div class="ref-block"><h2>References</h2><ol><li>Except for maybe unsafe context, but that&#39;s very rare (I&#39;ve never needed it).</li></ol></div></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Sun, 18 Apr 2010 13:21:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Truly immutable types are possible and desirable in general (several languages have them), but it doesn&#39;t work for practical reasons in C or C++ due to aliasing.</p><p>In C/C++, constness is not really about the type itself, but about the function acting upon an instance of a type. When you declare a function as taking a const something, you&#39;re saying &quot;I promise not to modify this variable in any way&quot;. It&#39;s a kind of primitive contract rather than a type feature. You can still violate that contract if you really want to, but you have to actually explicitly say when you do by using a const cast, making accidental changing of objects much less likely.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Sun, 18 Apr 2010 14:07:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/603805/861306#target">bamccaig</a> said:</div><div class="quote"><p> I wish a similar, though updated, concept existed in C#.</p></div></div><p>You can get some measure of constness in .NET by marking fields as readonly. The convention is for structs to be completely readonly, so if you follow that guideline then you&#39;ve got a set of immutable types.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> the const modifier ... is used in at least three ways: (a) to indicate that an object is read-only, (b) to indicate that a parameter is being passed by reference only for the sake of efficiency and not because it will be modified as a side-effect of the method call, and (c) to indicate that a class method does not, as a side-effect of its invocation, modify any of the non-static class members.</p></div></div><p>So we can accomplish A, but only for fields of classes or structs. B and C, I think, are becoming less of a problem as side-effects make code harder to test. I find myself writing code in a more functional style when I&#39;m doing TDD.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kibiz0r)</author>
		<pubDate>Mon, 19 Apr 2010 01:32:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I understand there are situations where const allows for extra optimizations.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ImLeftFooted)</author>
		<pubDate>Mon, 19 Apr 2010 01:59:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>in haskell everything is a const.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Goalie Ca)</author>
		<pubDate>Mon, 19 Apr 2010 08:40:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve just noticed that in C++ its used a lot whenever a parameter is passed to a method, especially when working with overloading operators. I never work with the latter and rarely use const but if you don&#39;t want a method to change the object being passed then const is the best option, besides saving a copy before passing the object. Very useful indeed, I wonder if Java has a similar problem, most likely not but feel free to let me know.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (verthex)</author>
		<pubDate>Mon, 19 Apr 2010 10:10:13 +0000</pubDate>
	</item>
</rss>
