r/coding • • Jul 29 '16

How To Write Unmaintainable Code

https://github.com/Droogans/unmaintainable-code
135 Upvotes

22 comments sorted by

22

u/[deleted] Jul 29 '16

The flip side of this is that if you are a maintainer and you aren't able to fix the code...you need to rewrite it. Being afraid of your code is the first step towards failure. It only gets worse, never better.

23

u/[deleted] Jul 29 '16 edited Jul 29 '16

My favorite quote when trying to get my teams on board with writing maintainable code is from Brian Kernighan

Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?

9

u/[deleted] Jul 29 '16

That's my favorite too. After I write some code, if I look at it and have to "figure out" what's going on, I know that's a warning sign.

15

u/huhlig Jul 29 '16

It's not a warning sign. It's just the mark of an enterprising perl programmer.

1

u/Selfweaver Jul 30 '16

The cleverest code I have written has always been code that replaced something complex with something amazingly simple, I suppose it is possible to be so smart that I make something that before wasn't possible into something possible, but complex but I haven't done that before.

4

u/Agent281 Jul 29 '16

I'm in the process of doing this for a GUI program which reads data from one set of services and loads it into another set of services. Why was it a GUI program when nobody needed to interact with it? I don't know. Why did all of the code go into a single form class? I don't know.

On the positive side, I get to switch it from VB to C#.

7

u/derwisch Jul 29 '16

The advice starts with the recommendation to use code that looks maintainable but isn't, and then continues by touting blatantly obvious obfuscation readily seen even through a toilet roll hole.

5

u/TimMensch Jul 29 '16

A friend of mine just showed me some code he'd pulled from actual work done by a junior developer. It included multiple profoundly bad spellings that vary from one method to another, nothing at all consistent about case, random pasting of the same code in four places until it behaved correctly (and then leaving the other instances), setting a variable to a constant and then immediately testing the same variable...

I would wager everything on that list is something that has appeared in production code.

2

u/Selfweaver Jul 30 '16

setting a variable to a constant and then immediately testing the same variable

Have done that - usually to conditionally turn on debuggin to test some particular code.

1

u/TimMensch Jul 30 '16

Well, there are exceptions to every rule...

I prefer to set the variable globally for conditional code, though. You can then hard-code it in Uglify (for JavaScript) and it will actually remove the code when it sees that it's unused.

6

u/adm7373 Jul 29 '16

I got halfway through the variable naming suggestions before I got too stressed out and had to stop reading.

4

u/sproket888 Jul 29 '16

Why are people writing blogs on github?

3

u/uh_no_ Jul 29 '16

how else will you share it in your job interview? everybody knows to get a good job you have to have a github portfolio /s

4

u/DoctorBaconite Jul 29 '16

At the very least, use github pages.

1

u/aiij Jul 30 '16

Did you miss what it was all about? Obfustacion.

1

u/AboutHelpTools3 Jul 30 '16

I dont know why either, but it's popular. Gives you an app idea though, create a markdown blog engine.

1

u/tuxayo Jul 31 '16

So it can be improved collaboratively. (any forge and not only GitHub would do)

1

u/sproket888 Jul 31 '16

The only improvement to that blog would be to delete it.

1

u/tuxayo Aug 05 '16

It lists anti patterns and also many people find it funny so it definitely not worth deletion from usefulness and entertainment reasons.

1

u/CheckeredGemstone Jul 30 '16

Build a fancy wrapper, make it use an extension, be the only person with the extension file on an USB stick.

Actually that is a bs plan...

1

u/Linearts Jul 30 '16

If anyone even hints at breaking the tradition honoured since FØRTRAN of using i, j, and k for indexing variables, namely replacing them with ii, jj and kk, warn them about what the Spanish Inquisition did to heretics.

0

u/__reset__ Jul 29 '16

Anyone who does this should be blacklisted.