Const, strings, and other things.
Jarrett Billingsley
kb3ctd2 at yahoo.com
Mon Nov 12 13:21:19 PST 2007
That topic name is _dangerously_ catchy.
Anyway some noobish thoughts were running through my constless brain
today. By constless I mean I'm in the "I've never used const and
haven't really run into any cases where I've thought it
necessary/useful" camp, although I can't deny that there are _some_ uses
for it. But the more I thought about it, the more it seemed to me
that.. well, if we're not trying to be C++, and we're not trying to make
it possible to have user types behave exactly like built-in types, then
maybe a generic const system isn't really all that necessary.
What my thoughts boiled down to is that constness seems useful for
strings and not much else. I suppose it could be useful for other kinds
of arrays, but overwhelmingly the use cases for const seem to be for
strings, and constness helps to make some operations with strings more
efficient. Other than that, constness for other types seems more like a
logical convenience. So you want to return a const(Foo) where Foo is a
class reference? How often do you need to do that? Passing const refs
-- have YOU ever had a bug where you tried to modify a const ref param
that was caught by the const?
The more I hear about const, and the more conversations I watch about
it, the more complex and esoteric it gets. I think that constness for
strings only could cover a large majority of use cases for const without
having to have a pervasive, complex addition to the type system.
(I just keep looking at D2 and seeing this awful const wart on it, and
thinking I'd really like to try it out if it weren't for const. Ugh.)
More information about the Digitalmars-d
mailing list