Nick Sabalausky wrote:
"Walter Bright" <newshou...@digitalmars.com> wrote in message
news:i9qd8q$1ls...@digitalmars.com...
4. the tokens should be a value type, not a reference type
I'm curious, is your reason for this purely to avoid allocations during
lexing, or are there other reasons too?
It's one big giant reason. Storage allocation gets unbelievably costly in a
lexer. Another is it makes tokens easy to copy. Another one is that classes are
for polymorphic behavior. What kind of polymorphic behavior would one want with
tokens?
If it's mainly to avoid allocations during lexing then, maybe I've
understood wrong, but isn't D2 getting the ability to construct class
objects in-place into pre-allocated memory?
If you do that, might as well make them value types. The only reason classes
exist is to support runtime polymorphism.
C++ made a vast mistake in failing to distinguish between value types and
reference types. Java made a related mistake by failing to acknowledge that
value types have any useful purpose at all (unless they are built-in).