HACKER Q&A
📣 kbrannigan

How do I write quick and dirty, spaghetti code?


I want to start a project, with no concern for design patterns, clean code, separation of concerns.

I want to write the most spaghetti, working, hacky code that works. C#, Java, Php, JS or python. What tips do you have? You might need a throwaway for this hahaha.


  👤 pinewurst Accepted Answer ✓
Start writing it in one cool language, and keep transmogrifying the code base as HN fashions continue to shift to the next cool things.

👤 sargstuff
Is't spagetti code a design pattern?

One can make use of design patterns, clean code and separation of concerns and still get working spaghetti code without all the hacky stuff. Much less effort if use C.

Engineered C case studies as goto solutions! https://blog.feabhas.com/2017/02/abusing-c-switch-statement-... https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html

Just have to impliment the program as if it was an OS. aka mix/match abstraction levels!

Mix/match assembler / language macros / foreign language calls to other language libraries

Use C20 ability to assign case statement(s) to a thread (mixed with remote procedure calling and/or function stacks across multiple threads)

Mix & match unicode/non-unicode, hex, ascii, etc. where text is code that can be run.

Mix and match C# language extensions in which same thing can be implimented different ways (e.g. strings, vectors, templating)


👤 Jtsummers
Any language with goto, and skip any notion of structured programming elements except if-statements, including all methods or functions except for main or its equivalent if required. Only make function calls to library functions that you can't get to any other way. if is permitted so that you can have conditional jumps. Bonus points for Fortran and computed gotos. Like this (in pseudocode):

  start:
  x = read(); // hope its a number
  goto x;

  10: ...
  20: ...
  30: ...
  goto start;
If you aren't using goto and labels, it's not spaghetti code.

👤 retrac
Fast hack: use a compiler for a nice language that targets the language in question.

Failing that, design your software with nice abstractions, then do the compiler's job and strip them all out and turn it into a bunch of if/gotos. Preferably with vague (ideally numeric!) label statements.

Otherwise I'm not sure it's actually possible to write anything larger than a couple hundred lines without paying homage to design patterns and consistency, if only in your head. It took me a long time to learn that code's greatest enemy is the task of holding up its own weight.


👤 PaulHoule
In Java write it all in one big file.

👤 faebi
A little bit of meta-programming makes everything nicer and worse at the same time. If you use ruby, you can patch your code into base classes like String and Integer.

👤 kbrannigan
I'm talking Hacky not buggy.

Inelagant code that works. Just for personal use.

Not code that will run a space station obviously