Jump to content

Talk:Const (computer programming)

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Flex (talk | contribs) at 14:28, 23 June 2005 (Immutabitity). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Other Languages

Anyone know of other languages that support this? Wouter Lievens 10:47, 28 Apr 2005 (UTC)

Strange, I never noticed before you asked: c++ is the only major language I can confirm uses const variables... Maybe it's because it sounds like such an oxymoron. Java seems to have a const keyword, but doesn't use it. Java's final keyword is similar when used with a member variable however. I believe that const may be valid C now since C99, but it'd be better to double-check that. I know of no other language with anything anologous to mutable. Const correctness seems to be a wholly C++ phenomenon. TheIncredibleEdibleOompaLoompa 17:19, 2005 Apr 28 (UTC)
C# also has a const keyword (and a readonly keyword), though it really has nothing like const correctness in C++. IIRC, it makes a reference immutable, not the object itself. OracleofTroy
Yeah Java has final and C# has const but it's not the same. What really matters (in this article) is the const correctness of methods. Wouter Lievens 07:48, 12 May 2005 (UTC)[reply]

Immutabitity

I barely know the semantic of const, so I may be wrong but isn't this article talking about the same thing as immutable object? Of course, there is a difference but I don't think it is much to warrant two separate articles. So I am adding merge tag. Feel free to correct me if necessary. -- Taku 09:55, Jun 23, 2005 (UTC)

Const correctness is a programming technique that maximizes the use of immutable objects and allows for a simple design by contract. It applies in several programming languages, but the only one in widespread use is C++, which is what the bulk of this article covers. I don't think they should be merged necessarily, but I wonder if this article belongs in the Wikipedia rather than a Wikibook on C++. --Flex 11:40, 23 Jun 2005 (UTC)
While I am not C++ guru, this article, it seems to me, is little too verbose. For example, it says "const char *p" is the same as "char const *p", and this is clearly redundant; we are not writing a tutorial. Besides, the article seems to simply have random facts related to const rather than one specific idea (Actually I am not quite getting what this article is trying to say :) For instance, the discussion about volatile seems off-topic; if I understand correctly, it's basically the marker for lessening aggressive optimization. I don't believe that we can simply the content of this page to immutable object without any revision. But I still think it makes more sense to give some context, and for this the merger may help. What do ya think? -- Taku 12:38, Jun 23, 2005 (UTC)
Well, the volatile section is there because C++ also supports "volatile correctness," but its application is much rarer. (Consider: const_cast is so named because it is usually used to strip the const qualifier, thought it can strip volatile qualifier, also. Calling it qual_cast [or something like that] apparently seemed like overkill to the C++ committee.) If it is determined that const correctness deserves its own article, volatile correctness also make an appearance but as a subsection rather than its own article because its use is rare and its usage syntax is basically the same as const's.
Anywho, you're right that the article does tend more toward tutorial and loses sight of explaining const correctness as a concept. Let me try to make some revisions to correct that. Then we can decide if it needs to be merged. Personally, I think the concept of const correctness deserves its own page, but I could be persuaded. --Flex 13:13, 23 Jun 2005 (UTC)
There's an important difference, in that an immutable object is an abstract concept, for it can be enforced (badly) using conventions rather than using language techniques. Const correctness is a technique for implementing partial static verification of object immutability. However, I (as article creator) see no reason why this information cannot be integrated into immutable object. So go ahead if you want. Wouter Lievens 13:40, 23 Jun 2005 (UTC)
Ok, I (as major rewriter) have made the promised changes. What sayest ye now? --Flex 14:28, 23 Jun 2005 (UTC)