> Programmers: View on spaghetti code?

Programmers: View on spaghetti code?

Posted at: 2014-12-18 
I will admit to having done it right here a few times. When someone is obviously not willing to make any effort to do their own homework, they just want us to do it for them. So once in a while I'll just do it for them in the most obfuscated way I can contrive that still works.

Not really spaghetti code, because it has to be small enough to fit here. But definitely obfuscated ;-)

Have needed to do this on several occaisions. This was primarily when using machine code to patch embedded systems controllers for a legacy system. The software was in ROM with just under 200 bytes of free space spread across 2Mb of program space, so the extra routines had to be fitted into whever there were gaps in the existing code. In some cases every third instruction was a JUMP to another area in ROM. We also had to use some pretty dirty tricks, like re-using opcodes as literals; and re-using operands as opcodes, by jumping into the middle of instructions. I think by the end, we had one byte left! The system code was potentially security sensitive, so this added an extra level of difficulty for anyone trying to reverse engineer it.

Fortunately the system wasn't realtime, so speed wasn't an issue; and approaching end of life so we didn 't have to maintain it for very long.

Sure, where there is complex programing need need that has to be filled quickly I will break things down into sub routines and step through the process using 'CALL' statements to get a working process to the end user quickly. (Kind of like Microsoft and their myriad of DLL 'Dynamic Linking Library' files). then I will take my time setting up the final code to be released for production and wider distribution. Unlike Microsoft my final product does not rely on a lot of outside files and other software installations to work properly.

Yes, I was programming an algorithm that's a trade secret, and I needed to make it difficult for anyone to reverse-engineer by looking at the assembly code generated by the compiler.

15,000 lines of code, subroutines coming out of my ears, especially those that would interfere with other subroutines before having chased the bugs out through bit of a messy last-minute patchwork. The code was bit messy on occasion, but worked with no problems, even though later when I revisited it to try to clean it up, I actually got confused by some of the "bandaids" enough to just let well enough remain be, even though the occasional confusion was not intentional on my part, just due to bit of fatigue-related minor sloppiness I meant to clean up later, but as mentioned, let it remain in a bit of catastrophic, yet very functional, mess.

Every time I do my computer just turns into spaghetti.

Looking for the anti pasta. He is a slippery one.

Programmers - have you ever intentionally programmed something with obfuscation in mind?

That is, have you ever intentionally created spaghetti code?

If so, why and what were you doing?