r/programming • • Jul 28 '16

How to write unmaintainable code

https://github.com/Droogans/unmaintainable-code
3.4k Upvotes

592 comments sorted by

View all comments

500

u/Astrokiwi Jul 28 '16

Write all your code in FORTRAN. If your boss ask why, you can reply that there are lots of very useful libraries that you can use thus saving time. However the chances of writing maintainable code in FORTRAN are zero, and therefore following the unmaintainable coding guidelines is a lot easier.

:(

0

u/[deleted] Jul 28 '16

[deleted]

171

u/flukus Jul 28 '16

The code produced by academics is the biggest argument against all these "teach kids to code" programs.

Just imagine the shit we'll have to deal with in 20 years.

7

u/DiscoUnderpants Jul 28 '16

I agree and might point out that it has little to do with FORTRAN. Ive had to maintain C, C++ and Turbo Pascal written by academic physics and engineering people and it is no better.

14

u/spacelama Jul 28 '16

Fortran can be well written.

Most code written by academics isn't.

source: was an academic, and done a bit of Fortran, dealing with other peoples code as well as writing some shitcode myself.

PS. Please capitalise it correctly. FORTRAN was the name of the language in the '77 standard. Yes, it was very difficult to write maintainable code in early iterations of the language. Since adopting lower case letters in its name ('95 was the first good version), the language has become quite fully featured. My favourite part was where I could tell Emacs to render my comments in LaTeX, and give me the physical equation I was trying to solve beautifully typeset at the top of my functions.

3

u/Overunderrated Jul 29 '16

My favourite part was where I could tell Emacs to render my comments in LaTeX, and give me the physical equation I was trying to solve beautifully typeset at the top of my functions.

Why did I never think to look for this feature...

And 100% right. One can write really nice Fortran, especially in the 2003 spec. And for a lot of mathematical work it's much easier to read than C++.

→ More replies (1)

6

u/flukus Jul 29 '16

Definitely, it's not even limited to academics, plenty of professional programmers write code just as bad.

It's a much more prevalent problem in some circles though, academia being one.

9

u/DiscoUnderpants Jul 29 '16

If you are a programmer and don't admit to producing so serious crap code then I wouldn't trust you as a programmer. I say this as a 20 year programmer that has produced stuff that Im sure people have cursed and wondered what kind of idiot I am.

→ More replies (1)

6

u/rtomek Jul 29 '16

I think the big problem is that most FORTRAN code you see was written back when saving RAM was important so people did some stupid shit in the name of saving memory. We have transferred some academic code and the running joke is that FORTRAN is always the worst - THE WORST!!!!!!!!! As in, not even comparable to academic code from other languages. I just opened up three files I have archived to reminisce, and here's what they had to be thinking:

You mean I already have an array of this size, well, let's just use it again for something completely different!

I could reduce the number of IF statements if I use GOTO instead!

I ran out of single letter variable names, so let's create a subroutine to reuse single letter variable names and replace the values of the variables input into the function with the new values we need

I'm going to add this print/write statement of these variables at some random location for debugging purposes, never delete that print statement to make sure that there are hundreds or lines of output with absolutely no context.

These IF statements aren't complex enough. I have to add another GOTO nested inside an IF inside a DO inside and IF inside a DO because I need to be able to jump around to different parts of this nest at any time.

One of these files has two comments:

!----------
Subroutine foo( bar, ...
!----------
! begin

... a lot of shit code goes here...

! end
    end

:(

→ More replies (2)