Die, spaghetti-code, die.

I never really got what spaghetti code was until today. That might sound dumb, but it’s a term that is quite widely-used in different contexts so it can be an odd one.
Today, I have been working with code that is devoid of any design, regard for future developers or useful documentation. Like so much PHP, the end result works, so it’s great. Except it’s not.
Imagine each line above is a function or method call, which has its own integral part to play in the execution of a web page (in this case). The entry and exit points are single entities, but what goes on in between is nothing short of scary!

Ideally, I like to see code the main vein of which is there at the start and the end of the app’s execution. Logic can branch from this as far as it wants to get what it needs, but it’s ultimately serving a purpose for the main line. The more I delve into OOP in many languages, the more I realise that procedural code is quite liable to spaghetti, whereas OO is not. That’s not to say it’s impossible, but it’s easier to have one method that sets everything in motion, configures your program and then receives and redirects input in OO than it is procedurally.
Since I started properly getting into OO, I started to liken the execution cycle of a procedural program to a glass of water falling. Everything starts from the same point, but over time everything splays out and does its own thing. Debugging procedural code, therefore, is analogous to blindly cleaning the aforementioned spillage – there is a good chance that the part of the spillage you’re working on has nothing to do with what you’re actually trying to achieve – no matter how relevant it looks!
Unfortunately, I blame PHP for the natural progression of spaghetti code from procedural to half-assed-OO. It’s so easy to get things done without really knowing what you’re doing that it’s actually borderline dangerous. A mishmash of procedural and OO is the absolute worst thing to debug, as it normally combines the horrible execution cycle of procedural apps with the potentially confusing trail of inheritance. Let me tell those who don’t know – it is VERY obvious when you’re working with code written by someone who does not understand inheritance (and I don’t mean what it is, I mean *why* it is) and it almost always makes their half-baked bastardisation of OO impossible to work with.
Have I had a difficult day? You could say that.
