[erlang-questions] erlang sucks
Kevin Scaldeferri
kevin@REDACTED
Mon Mar 17 17:55:15 CET 2008
On Mar 17, 2008, at 6:31 AM, Jani Hakala wrote:
> attila.rajmund.nohl@REDACTED writes:
>
>> I don't think that immutable variables make it easier to write less
>> buggier code. On the contrary, I often see code like this:
>>
>> HR1=f(HugeRecord),
>> ...
>> g(HR1).
>>
>> Then someone adds a line to modify the HugeRecord and forgets to
>> update
>> the call to 'g':
>>
>> HR1=f(HugeRecord),
>> HR2=f2(HR1),
>> ...
>> g(HR1).
>>
>> Now we have a stupid bug.
>>
> The compiler would warn about that
> Warning: variable 'HR2' is unused
These examples always feel like people are insisting on writing
imperative code in a functional language. Why not:
HR1 = f2(f(HugeRecord)),
...
g(HR1)
There you go: no bug.
-kevin
More information about the erlang-questions
mailing list