News for hackers. Stuff that matters.
Re:How to Write Unmaintainable Code (2017) by zbentley on Friday August 17, 2018 @08:40AM (#17782332)
> In C, functions are supposed to be idempotent, (without side effects).

What is meant by that statement? Is "idempotent" a mistype/mistakenly selected word? If the author meant "pure" instead, should I file a PR, or consider this some sort of meta-meta-obfuscation? If the author meant "pure", is that actually true of C specifically, or just generally good programming advice (localize side effects to known locations, the fewer the better, don't sprinkle them all over and document where they occur)?

Re:How to Write Unmaintainable Code (2017) by badlukk on Friday August 17, 2018 @09:03AM (#17782467)
C functions shouldn't change behavior based on state, they do the same thing every time. Instead of changing a particular global variable, any variable of that type should be passed in and changed, then returned. It's good programming advice for functional languages. In OO it makes sense to make state changes in object methods, but not usually the best functional approach.
Re:How to Write Unmaintainable Code (2017) by marcosdumay on Friday August 17, 2018 @02:01PM (#17784609)
I think the author meant something like "they are supposed to be pure, so make them not idempotent".
Re:How to Write Unmaintainable Code (2017) by rofo1 on Saturday August 18, 2018 @03:15PM (#17790079)
Idempotent is concept borrowed from mathematics. It just means:

f(f(x))=x

assuming f is a function (binary operators are just functions (maps) in mathematics, too, e.g. +:NxN->N (read: "plus" is a map from the Cartesian product of N by N to N))

Re:How to Write Unmaintainable Code (2017) by jokerx on Friday August 17, 2018 @03:42PM (#17785196)
Code tells "how." Comments tell "why."