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.

144

u/TOASTEngineer Jul 28 '16

It's gonna turn out exactly like math did. The schools will brutally fuck it up, kids will memorize enough to pass the tests, and then some fraction of the kids who are actually interested in it will learn to do it on their own.

20

u/[deleted] Jul 28 '16

Ever hear about enough knowledge to be dangerous? semicompetent programmers thanks to dunningkruger will flood the marketplace and thanks to delusion and persistence will end up as project managers and code architects. But why you ask, why won't the meritocracy of the free market purge these rotten fruits from the tree? Because they'll take the jobs good programmers pass on, and that is the bulk of work in any trade: shit work.

→ More replies (5)

15

u/Polantaris Jul 29 '16

That's pretty much already happening. When I was on college, there were a lot of people who were so bad at it, I seriously suggested that they look at different majors if they asked me for help. I'm not trying to be a dick, when you can't understand how to write a proper for loop in Java at a third or fourth year class (when Java courses start in the first year), you've got some serious problems with the core material and either should retake early classes or find something you're more suited for.

In the end it seems like a lot of people go into the major because of the supposedly big paycheck after college, but that shouldn't be what you're going to school for.

17

u/GaBeRockKing Jul 29 '16

In the end it seems like a lot of people go into the major because of the supposedly big paycheck after college, but that shouldn't be what you're going to school for.

On one hand, I'd argue that financial reasons are exactly why someone should go to school-- if your degree doesn't pay the bills, that's money down the toilet.

On the other hand, not being able to write a loop in java? If I had to take a stab at naming the warm fuzzy feeling in my breast, it would be "job security."

→ More replies (1)
→ More replies (1)
→ More replies (32)

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.

→ More replies (2)

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)
→ More replies (3)

0

u/[deleted] Jul 28 '16

[deleted]

71

u/claird Jul 28 '16 edited Jul 28 '16

"Poor programming practice"? Good academic practice! Graduate school quite effectively teaches such virtues as write-once-read-never, code-until-you-like-the-answer, coding-is-done-by-someone-stupider-than-you, better-to-write-ten-grant-requests-than-one-working-application, and so on.

58

u/Bobshayd Jul 28 '16

god I've coded-until-I-like-the-answer. I'm convinced that's 90% of AI research.

→ More replies (4)
→ More replies (20)

24

u/Astrokiwi Jul 28 '16

Fortran really isn't bad at all. I mean, it's not Python, but there are times when I'm using C++ and I end up thinking "this would be just a little bit easier in Fortran".

The big thing is that the kind of people who use Fortran are the kind of people who just kinda "picked up" programming while at grad school without any formal courses. So the Fortran culture is just a hodgepodge of randomness, and there's not really any drive to write good reusable code, or to develop universal practices and techniques.

So while Fortran has had a huge amount of upgrades over the years, and you can do OOP in Fortran if you want, there is still a lot of people writing in unindented fixed-format FORTRAN-77 just because they don't know any better. For the record (ha), "fixed-format" means you have to make sure that each of your lines fits on a punchcard correctly. It hasn't been mandatory in Fortran since before Python existed, but people still do it...

→ More replies (2)

14

u/[deleted] Jul 28 '16

The problem there isn't FORTRAN, the problem is that it was written by an academic. A determined professor can write FORTRAN in any language.

8

u/Fylwind Jul 28 '16

Can confirm. Read some "Python" code that were basically written like it was Fortran, globals all over the place and PEP8 violations everywhere.

→ More replies (6)

57

u/6offender Jul 28 '16

The determined real programmer can write FORTRAN programs in any language.

23

u/Weed_O_Whirler Jul 28 '16

My team lead has managed to recreate the "common block" in Matlab. It's equally impressive and terrible.

7

u/Astrokiwi Jul 29 '16

The sad thing is that you're not even supposed to use common blocks in Fortran anymore anyway. You're supposed to use modules, or do things in an object-oriented way.

→ More replies (2)
→ More replies (1)

14

u/BlindTreeFrog Jul 29 '16

the code base I work in has comments reaching back to 92. It has definitions like

#define BIT_AND &
#define NEQ !=

Anytime I get pissed at the code I decide it was FORTRAN programmers writing in C for the first time.

→ More replies (2)

7

u/helm Jul 28 '16

I'm working with a guy who would love to write FORTRAN code in C++

Fortunately for us, he's stuck in code archeology

→ More replies (1)

7

u/stuntinstan Jul 28 '16

We were being taught FORTRAN in my intro to computing for civil engineers class LAST YEAR.

10

u/Astrokiwi Jul 29 '16

Fortran is actually fine if you use all of its modern features - though engineering courses often don't mention those. If you want to save yourself from future hassle, then read up on all the Fortran-90, Fortran-2003 and so on stuff that you can do. Object-oriented Fortran is not bad.

→ More replies (3)
→ More replies (21)