preparing for const, final, and invariant
Walter Bright
newshound1 at digitalmars.com
Mon Jun 4 20:22:07 PDT 2007
Charlie wrote:
> I'm appalled, both that this is pretty much assured to be in D , and
> that the community seems to be behind it. I thought that the reason
> Walter didn't want const was because of its added complexity , so
> instead he introduces _3_ new keywords ? Does no one else feel like
> this is using a machine gun to kill a fly ?
>
> I understand the need for immutable data when writing libraries, but
> 'scope const final MyClass myInstance' ?!? Theres got to be a better way.
>
> I know this sounds over-dramatic, but if this is the direction D is
> headed, then count me out. I loved D because if its elegant and
> powerful simplicity, I think D has strayed way to far from its original
> goal.
>
> If anyone feels like _this_ implementation for const ( not the
> usefulness of const mind you ) is not for D, then please speak up or we
> all might end up losing our favorite language.
Actually, I quite empathize with your viewpoint. I worry that the final,
const, invariant thing is too complicated. But there are some mitigating
factors:
1) Just as in C++, you can pretty much ignore final, const, and
invariant if they don't appeal to you. I don't bother using const in my
C++ code.
2) The transitive nature of const means that there are a lot fewer
const's you have to write.
3) Using D's type inference capability, a lot fewer types (and their
attendant const's) need to be written.
4) It provides information that is actually useful to the compiler.
5) Scope has the promise of enabling reference counting to be far more
efficient than is possible in C++.
6) Working together, these features move us towards supporting the
functional programming paradigm better. FP is very important for the
future, as it is very adaptable to parallel programming.
7) They make interfaces much more self-documenting.
8) They can make automated code analysis tools more effective. Automated
code analysis is big business and is getting to be far more important as
security consultants are brought in to analyze code for correctness,
security, etc. Wall Street in particular is very interested in this stuff.
9) So far, in my work to make Phobos const-correct, it hasn't been the
annoyance I thought it would be.
More information about the Digitalmars-d-announce
mailing list