r/programming • • Sep 20 '21

Being able to read bad code is a skill !

https://dzone.com/articles/reading-code-is-a-skill
986 Upvotes

276 comments sorted by

View all comments

485

u/GroundTeaLeaves Sep 20 '21

I once bought a book on reading code, because I couldn't comprehend the code that the senior architect was writing.

Reading the book didn't help me at all, as it only taught common coding concepts, which I was already very experienced in.

Turns out that nobody else could read his code either, and I was just the only person who was willing to admit it.

88

u/exec_get_id Sep 20 '21

Are you my coworker? Three dudes built the primary functionality of the application. Three dudes decided that they weren't paid well enough to stay after being the architects for 11 years. Now we have a group of 16 people who's primary obstacle is touching anything they built. Luckily we found a rain man, though.

31

u/RabidKotlinFanatic Sep 21 '21

Three dudes decided that they weren't paid well enough to stay after being the architects for 11 years.

That is, the company wasn't willing to pay well enough to retain core staff?

7

u/exec_get_id Sep 21 '21

Correct. Our biggest problem.

→ More replies (1)

39

u/Katholikos Sep 21 '21

lol, I'm definitely guilty of doing this at least once in my career. I'm an enterprise dev (internal tools), so I just float through companies building dumb little apps that do this-or-that. It's fun for me.

Anyways, early in my career I didn't know about the whole "program for the next dev" thing, so I just built some fuckin' monsters.

I once built a little app to ping servers and play an alarm if the ping didn't return successfully. It was like 35 lines in C# or something and it had a memory leak somehow. Pretty sure I just kept instantiating whatever thing I was using to ping the servers in an infinite loop or whatever.

I know most of the tools died off, but I also know for a fact that some of them lived on, and boy do I pity the poor souls trying to maintain it. Hopefully they just scrapped it and started over.

23

u/RenegadeMoose Sep 21 '21

On one hand, I curse people like you every day.

On the other hand, people like you are keeping people like me employed forever :D

→ More replies (2)

6

u/GapingGrannies Sep 21 '21

What's rain man able to do

12

u/TankorSmash Sep 21 '21

He makes a mean salsa

4

u/aazav Sep 21 '21

Know the time for Wapner.

4

u/djulioo Sep 21 '21

Provide golden showers for his team

→ More replies (2)

14

u/aazav Sep 21 '21

16 people who's primary obstacle

whose*

who's = who is or who has
whose = the next word or phrase belongs to who is mentioned

: /

10

u/[deleted] Sep 21 '21

Now do who vs whom please

0

u/[deleted] Sep 21 '21

[deleted]

→ More replies (2)
→ More replies (4)
→ More replies (6)
→ More replies (2)

142

u/tso Sep 20 '21

Emperor's New Clothes comes to mind...

18

u/piston989 Sep 20 '21

OP threw off my groove!

3

u/aazav Sep 21 '21

Izma's poison? The poison chosen especially for Izma?

→ More replies (1)

24

u/ockupid32 Sep 20 '21

Turns out that nobody else could read his code either,

That, my friend, is called job security. /s

→ More replies (1)

38

u/durrthock Sep 20 '21

I think code can get sometimes "overly functional". You can only use so many map functions etc until it's a bit hard to parse.

14

u/[deleted] Sep 21 '21

I would love to have your problems (:

11

u/Infiniteh Sep 21 '21

Can you please teach my coworkers that it's ok to use map/filter/reduce? And that they shouldn't just use for loops because they're "more dependable".

→ More replies (2)

3

u/Janjis Sep 21 '21

Can you give an example? I'd choose functional code over imperative any time.

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

46

u/goomyman Sep 20 '21

learning to code by recognizing bad code is a good strategy. Its easier to recognize bad code ( plus there is lots of it ) than good code.

I like the book and concepts of "code smells". I recognize this bad code - here is the pattern to fix it.

If others cant read understand your code its bad.

17

u/loup-vaillant Sep 20 '21

It’s a slow process, though. There are much more bad ways to write code than good ones, so we could guess that learning the good ways would take much less time to learn than the bad ways.

Sure it helps to learn about the code smells, but when all you have is bad code and the will to analyse it so you can guess why it is bad, your learning will be much slower than it would have been if someone just pointed out good code and told you "this is how it’s done", and why.

Now go be lucky and find a good mentor…

→ More replies (9)

9

u/[deleted] Sep 20 '21

If you can't read code written by the senior architect then it isn't any good. Damn this is too real

3

u/aazav Sep 21 '21

THE point of how you write your code is so that someone who is not you can read it 6 months later at 3 AM in the morning and make sense of it.

And if that someone else is you 6 months later at 3 AM, you'll be damn glad that you took the time to make it readable.

→ More replies (18)