Comment by WalterBright
9 months ago
> Making a fun & interesting games is about rapid prototyping and iteration, Rust's values are everything but that
I found this to be true of C after many, many years coding in C. I noticed that the first selection of data layout stayed throughout the life of the code (with a lot of tweaks, additions, etc.). But didn't really think that much about it.
Until I started writing code in D. It was easy to change the data layout, and I did for experimenting. For example, changing a reference type to a value type, and vice versa. This was easy in D. It's just too much work in C, so it didn't happen.
The reason is simple:
p->b
v.b
To switch between a ref and a value type, you've got to search/replace the -> into ., and the . into ->, and not disturb the dots and arrows of the other types. When dealing with 100,000 lines of code, this is a non-starter.
But with D, both reference and value types are used as:
p.b
v.b
making it easy to switch between the two, and also switching function parameters from values back and forth with references.
I agree, and D with the GC lets me prototype quickly. Its type system gets progressively stricter with constraints, for code that survives. I wouldn't want all the type system to apply to prototype code or a nascent program.
I tend to add in the constraints only after the code works. Two different parts of my brain.
The power of attributes and get/set in languages like C# is similar. It's easy to turn value types into functions. Or to move a value into a subclass and you don't need to do a.b.c (moved c into b) because you can add c => b.c to the a class.
You could hack the C compiler!
https://github.com/tsoding/tic-tac-toe-auto-deref
https://www.youtube.com/watch?v=yKI-VOBBFu8
That's a good example. I actually think dot syntax is really under-utilized sometimes. Although personally, I'd prefer that if v was a reference/pointer to a struct, that v.b simply performs a pointer offset, instead of auto-dereferencing like ->.
In the same idea in Eiffel in a.b, b can be either a member or a function to allow easy replacement.
On the opposite other languages want to have no hidden function call, no hidden pointer dereferencing..
When ever I watch someone coding C(++) all they do is compile and then add remove * and & or change between -> and . when the compiler complains.
Multiply that by all the C(++) coders on the planet and we have lost a billion man hours...