News for hackers. Stuff that matters.
Re:In the Defense of Spaghetti Code (2013) by pmontra on Monday July 22, 2019 @09:09AM (#20497627)
I don't dare to call it spaghetti code because (among the other things) it's split in a lot of functions, but to give an example that's probably equally difficult to everybody, check this Erlang module that parses ASN1 [1]

A few hints about the language for the non-functional crowd, then my point

1) Functions can have multiple definitions and are picked top to bottom. The one that runs is the first one matching the arguments in the call.

2) Variables are Capitalized (and can't be assigned again, big surprise.)

3) Atoms (:symbols in other languages) are lower_cased.

4) The arrow (->), the comma (,) and the dot (.) do (more or less) what Java/C do with their { ; } characters (sorry, I have to keep it short)

You can start from the bottom and go through the get_token, get_line, parse_ComponentTypeLists etc, find where they are called and see how they neatly (IMHO) replace the switch statements in other languages.

Is it easier to understand? Hard to tell: if the problem is difficult the code won't be easy. Is it less tangled? I think it is. My point: some languages are messiers than others.

[1] https://github.com/erlang/otp/blob/master/lib/asn1/src/asn1c...

Re:In the Defense of Spaghetti Code (2013) by _pmf_ on Monday July 22, 2019 @09:32AM (#20497811)
To add to this (for those unfamiliar with Erlang/OTP): Erlang not only has general pattern matching, but also specific support for pattern matching on binary content (down to bitfields). It's better than C and C++ in that regard in more than one way.