Hacker News new | ask | show | jobs
by mrkeen 1339 days ago
> I’m pretty sure Clean Code by Uncle Bob has a section on why you should use const to achieve immutable variables.

Doesn't go far enough.

Firstly, it's just advice. I might like it, but it doesn't mean I can get my teammates to do it.

Secondly, if I want to do it, I have to get it right, any mistakes I make are on me.

Thirdly, const is not enough. You'll probably end up with immutable pointers to mutable data, rather than any kind of referential transparency.

A language which helps you get immutability right is a world of difference. It's like the difference between a memory-safe language vs just using C (and a C textbook which recommends that you write memory-safe code)

1 comments

> A language which helps you get immutability right is a world of difference. It's like the difference between a memory-safe language vs just using C (and a C textbook which recommends that you write memory-safe code)

I mean I understood how to get immutability right before I ever picked up an FP language, but I can see how this is a flexible point though. The virtues of immutability really don’t take a long time to extol, and they’re a concept you’re introduced to immediately in MyFirstFPLang™.