Immutable
Tahirandreas
tahirandreas5 at gmail.com
Mon Jan 13 19:34:54 UTC 2025
On Saturday, 27 March 2021 at 20:44:12 UTC, Brad wrote:
> I was looking through lots of sample code on Rosetta Code. D
> has a lot of solutions out there. That is really nice but it
> has me wondering - coming from other languages that do not
> support the concept of immutability - do real world programmers
> and/or hobbyists really use it as much as I see it on Rosetta
> Code? I know it adds a layer of security to your code, but I
> am still thinking "why?".
>
> Thanks for entertaining a newbie question.
Hey, Brad!
I understand that immutability might seem like overkill to you.
Especially if you're used to languages that don't have it. But
Meta says that using immutable types, like for strings, can
really improve code performance and security.
When strings are arrays of immutable characters, the compiler can
optimize its work with them and not waste resources on copying
data. This is especially useful in large projects where every
little detail matters.
If you're interested, I can recommend some articles and examples
that show how immutability helps in real-world tasks
https://www.bloomberg.com/graphics/2015-paul-ford-what-is-code/
Thanks for bringing up this issue. Immutability is an important
concept in D.
More information about the Digitalmars-d-learn
mailing list