Ask HN: How do I write quick and dirty, spaghetti code?

4 points by kbrannigan ↗ HN
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.

13 comments

[ 2.7 ms ] story [ 44.9 ms ] thread
In Java write it all in one big file.
I used to obsess over how many queries per second a server could handle, whether a list was using more memory than an array. Which RNG was more random, whether CSS tables were better than flex.

All of those are details to worry about later.

Jeez! It's funny how reading so many HN tech blogs actually limited me, I was trying too hard to be a perfect programmer.

(comment deleted)
Actually I got turned on to single-file Java by HackerRank (where that's the only way you can write Java) so it was about getting better at coding, not getting worse.

It's fun because you have to know a few details about the language that aren't widely known (you can define as many classes as you want in a file, only one of them can be public.) It is handy when you want to write things that are really scripty or self-contained like you might want to do for tests.

I'm not one of them but there are many people who hate Java and hate object-orientation and single-file Java provides many chances to fight orthodoxy. Sometimes people are very happy to see single-file Java but sometimes it really drives people up the wall... If you want to break all the rules for your tribe it's a great foundation to start with.

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.

I don't want to be that extreme. But I see your point.

Do you prefer then to grow organically, or do you enforce then from the start?

(comment deleted)
Start writing it in one cool language, and keep transmogrifying the code base as HN fashions continue to shift to the next cool things.
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.
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.
I'm talking Hacky not buggy.

Inelagant code that works. Just for personal use.

Not code that will run a space station obviously

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)

Perhaps if there was a 'goto' patterns book akind to object oriented design patterns, it'd be clearer when not to goto bad stuff and when to goto good stuff.

About as likely as NULL nil adding to a value greater than 0 in a standard programming language.

aka progressing beyond nil'ist gotos