News for hackers. Stuff that matters.
Re:Please do not attempt to simplify this code by emn13 on Thursday December 27, 2018 @05:32PM (#18773232)
But what if comments pertain to unexpected states the system as a whole can be in?

Kind of the whole problem is when there are weird corner cases going on that straddle function boundaries.

I'm not saying that's a good thing; mind you - but nor is it always trivially avoidable, especially if code needs to be concurrency and/or exception safe -- or in general whenever the statements your function consists of have surprising and opaque behavior based on system state, particularly if said state is hard to grasp due to being implicit or dynamic, or simply large and complex.

Re:Please do not attempt to simplify this code by TeMPOraL on Thursday December 27, 2018 @06:14PM (#18773508)
> Kind of the whole problem is when there are weird corner cases going on that straddle function boundaries.

If the problem has "hub and spokes" topology, i.e. it's relevant to multiple places in code that all reference a single location, put a comment describing the issue in that single location, and everywhere else put a comment with a reference. //Warning. See comment in [that location].

If there's no single best place for the detailed comment, put it in some design notes file, and put a comment with a reference to that file in all the affected places.

DRY can, and should be, applied to comments as well.

Re:Please do not attempt to simplify this code by emn13 on Thursday December 27, 2018 @06:24PM (#18773572)
Centralized comment references sounds like a good+simple idea - I'll try to remember it, and hope I never have to of course ;-).
Re:Please do not attempt to simplify this code by TeMPOraL on Thursday December 27, 2018 @06:29PM (#18773597)
Yeah, references to a centralized document is such an obvious thing... once you read about it. It's another thing I recently picked up from Ousterhout's book, and looking back, I can now see the places in past codebases where I wish I thought of that myself.
Re:Please do not attempt to simplify this code by macintux on Thursday December 27, 2018 @05:47PM (#18773334)
Agreed, but that’s why I prefer writing code that has no global state. In Erlang, for example, it’s unusual (and the language lends itself via pattern matching to having short function clauses).

It gets a little tiresome threading the relevant state to every function that needs it, but it’s worthwhile in the end.

Re:Please do not attempt to simplify this code by emn13 on Thursday December 27, 2018 @06:23PM (#18773561)
Even a pure function has "state" - namely its (arbitrarily complex) inputs. But sure, it's a little less of a landmine.

The fundamental issue remains that sometimes your knowledge about that state (whether the classical kind or a proper parameter) can be complex and dependent on what happened elsewhere, especially if the codebase your in was grown into that situation, and not designed like that per-se. A comprehensible set of preconditions and postconditions isn't always a luxury you have, certainly not at first.