←back to thread

498 points azhenley | 2 comments | | HN request time: 0.432s | source
Show context
agentultra ◴[] No.45771102[source]
Agree. After working seriously on a large production Haskell codebase for several years I definitely took it for granted. Now that I’m writing stuff in C again I do think immutability should be the default.

const isn’t really it though. It could go further.

replies(2): >>45771974 #>>45772746 #
1. 1718627440 ◴[] No.45772746[source]
Well in C actually you can not mutate something, you can only reassign, as it is always pass-by-value. You need to work around that, by passing a pointer to the object instead. In that sense mutability is kind of a language keyword: '&'. When you want to just get the object, you pass object it, if you need to modify it, you need to pass &object. This is something I hate in C++, that random function invocations can mutate arguments without it being obvious in the call syntax.
replies(1): >>45774487 #
2. astrobe_ ◴[] No.45774487[source]
I think that's why the * is generally preferred over the & for this purpose. It also can give some hints about ownership issues. This "pass by reference" thing is syntactic sugar and sometimes is great to have, but as Perlis said, "Syntactic sugar causes cancer of the semicolon" [1].

[1] https://www.cs.yale.edu/homes/perlis-alan/quotes.html