Re: D5 Constant expression expected

From: Maarten Wiltink (maarten_at_kittensandcats.net)
Date: 04/19/04


Date: Mon, 19 Apr 2004 10:02:21 +0200


"Supply and Demand" <matko . lokas @ comhem . se (without blanks!)> wrote in
message news:M3zgc.56503$mU6.233374@newsb.telia.net...

> By the way... do you see any logical reason for Why they ever made
> typed constants... not constant?

Because they could.

In my book, there is one simple and bad reason, one almost as simple
and almost as bad one, and one complicated and simply bad one.

The simple and bad reason is that it saves one or two keystrokes when
you use them in place of global variables. Global variables can't be
declared initialised, you have to do that in the initialization section.
Note that all the elements to do this already existed; no expressive
power was added to the language.

The almost as simple and almost as bad reason is that you can declare
typed constants inside any scope, and they will not be visible (although
they will still exist) outside it. It also keeps the declaration and the
initialisation together. These are considerations in a different domain,
one that I am usually more concerned with than saving keystrokes: purity
of esse^BSlanguage. I'm still not impressed.

The complicated reason is the one pointed out here, which I had never
thought of: that it's possible to manipulate the "constant"'s value
through pointers. I consider this an equally bad reason as the first.
You should not be allowed to ask for a pointer to a constant, and there
should be no predictable, reproducible way to compute it.

So, yes, I can see logical reasons. But not good reasons.

Groetjes,
Maarten Wiltink



Relevant Pages

  • Re: Need Help With Run-Time Errors
    ... Explicit and declare every variable. ... Sometimes it crashes, and sometimes it doesn't. ... which tends to be an indication of a corrupt module (but which can be ... that's another reason that I ...
    (microsoft.public.word.vba.general)
  • Re: The wicked untruths of our church leaders
    ... to declare that anyone is a human being. ... What imho would be especially unscientific would be to draw lines without ... I appear to be better acquainted with reason than you on this. ... care whether you think I'm humble or not nor do I care for your suggestion. ...
    (uk.religion.christian)
  • Re: Properties
    ... Is there any reason why this would not work and not simplify the ... Why should I have to declare any variable most of the time? ... The reason you explicitly declare fields used by a property is that the ... compiler needs to know what the code in the property does. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Properties
    ... There is no preprocessor that converts the second into the first. ... do you think it is better to implicitly declare a field, ... I don't see any reason at all that you can't accomplish what you want to, ... the compiler where and what the field being used in the property definition ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: backup utility for remote hosts
    ... This is the wrong place to declare them. ... smallest applicable scope unless you have a reason not to. ... applies in all programming languages not just Perl). ... > close STDERR; ...
    (comp.lang.perl.misc)