Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If your language allows mutation:

1. Immutable first. 2. Data structures should use partial copying [1]. 3. Data structures should be lazy by default. 4. When you've profiled a bottleneck, and identified memory allocation and copying as the bottleneck culprit, then use a mutable data structure internal to the operation (copy your lazy immutable data structure once into the mutable one, taking only the portion of your lazy structure that you need, operate on the mutable structure in place, then return an immutable, lazy copy of that structure out of your operation.

This will isolate the need for mutation reasoning to performance critical parts of your application/library, and let you still reason about the rest of your program with referential integrity, while avoiding performance bottlenecks.

Never use a mutable structure in a mutable reference at the same time. You don't need both.

1. https://www.google.com/url?sa=t&source=web&rct=j&url=https:/...



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: