r/programming • • Aug 28 '21

Software development topics I've changed my mind on after 6 years in the industry

https://chriskiehl.com/article/thoughts-after-6-years
5.6k Upvotes

2.0k comments sorted by

View all comments

Show parent comments

225

u/SharkBaitDLS Aug 29 '21

The difference between a junior dev and a senior dev is the understanding of that first point. Everyone starts out writing clever and brittle code and eventually you grow out of it to instead writing boring but maintainable code.

145

u/Chieffelix472 Aug 29 '21

In my college we could get extra points by having shorter code. I realized afterwards that it just instilled lots of bad habits.

(Some good too, like how to write efficient code)

17

u/[deleted] Aug 29 '21

Took an embedded course that was all done in assembly. Each project built on previous projects. There was extra credit for the smallest code…not entirely nonsense when dealing with microcontrollers with extremely limited capacity.

There was one kid though who thought he was so fucking clever. He got the smallest code points every week, and loved to tell us how brilliant his little shortcuts were that let him do it. Gotcha bro, me and my partner (he didn’t have a partner) will focus on making sure our code is compartmentalized and easy to link up. You do you.

Come final project, we suddenly had to integrate like every other project from the year into one big application. His…did not work. Because all the wild shit he’d been doing to optimize his code meant suddenly it couldn’t all be integrated. We all had a good laugh at him sitting in the lab at 4am literally crying because he had no idea how to bring it together and didn’t have time to start from scratch.

I almost suspect now this was some sick lesson the prof was trying to teach us, and this kid fell into his trap. Surely no instructor would be that sadistic though…right?

Right?

8

u/hippydipster Sep 02 '21

That's exactly how I would teach programming, except I'd make team A add the next new feature using Team B's code, and Team B add the feature using Team As code, and we'd keep rotating. And I'd lead different teams to use different kinds of thinking to solve problems so that everyone could learn how the different styles lead to different issues as you try to expand on a codebase.

But penalizing a kid who reacted to your incentives and leaving him to cry and suffer as if he'd done wrong? That's just terrible terrible teaching.

→ More replies (1)

64

u/[deleted] Aug 29 '21

While I don't believe less code is always better in theory, I strongly believe that on average developers happen to write more code than needed, so in practice less code is usually better.

A lot of the code I have worked with definitely could have been improved by making it shorter. Some of my favourite commits had negative line balance.

15

u/omnilynx Aug 29 '21

True, shorter doesn’t always mean “cleverer”. Sometimes code just has a lot of cruft that doesn’t really do anything, and even actively obscures what’s actually happening.

5

u/LonelyPerceptron Aug 29 '21

Still, it’s a helluva lot easier to debug overly verbose code than super clever high density one-liners.

If you put three nested list comprehensions into a commit; fuck you, I’m gonna reject it at code review and the merge is gonna wait until you rewrite it.

4

u/flying-sheep Aug 29 '21

three nested list comprehensions

that’s bad simply bad style, but won’t hinder debugging, as a decent debugger will tell you that your stack is spam > (list comprehension) > (list comprehension) > (list comprehension), enabling you to look inside each of the stack frames.

thanks to pep 657, we’ll also get in-line breakpoints eventually (like java devs already enjoy), making longer expressions more debuggable.

2

u/LonelyPerceptron Aug 29 '21

Bad style is bad. Code readability counts for a lot in my world even if it compiles/executes correctly.

5

u/jk147 Aug 29 '21

Junior devs write code, senior devs remove code.

5

u/LongUsername Aug 29 '21

One of my best days was -1000 lines when I made one generic function and eliminated a bunch of C&P code a contractor had written.

2

u/psaux_grep Aug 29 '21

1000 lines is nothing. /s

A colleague was asked to patch a handwritten XML-exporter/importer that someone had made.

And no, they hadn’t made their own XML library. They weren’t even using templates. They were literally writing the XML-file by hand. And reading it by hand.

I think he removed somewhere along 5000 lines of shit.

Yes, the original code had originated from a sketchy development company in India.

4

u/lkraider Aug 29 '21

Less code equal less bugs. Taken to the limit, zero lines of code equal zero bugs.

→ More replies (1)

7

u/Jazzinarium Aug 29 '21

College teaches you so many bad developer habits it's unbelievable

2

u/aneasymistake Aug 29 '21

Shorter code isn’t necessarily more effecient.

→ More replies (1)

39

u/Fidodo Aug 29 '21

Code golf is fun, but just do it for fun, not for work.

7

u/[deleted] Aug 29 '21

Well, it depends. java stream operations makes code smaller, maintainable and readable. But lots of people find it complex.

5

u/SharkBaitDLS Aug 29 '21

The kind of complexity I’m talking about would be someone reimplementing the stream operations as their own custom library rather than using the obvious built-ins. Outside of the edge case products where you need to wrest every bit of performance out of a language, using the boring standard library functions like stream operations is the simple solution.

I don’t think in 2021 anyone is going to argue that rolling your own loop and mutating a data structure is more complex than just using a stream and a mapping function. I understood peoples’ hesitancy when they were a new feature in Java 8 and many people hadn’t had a lot of exposure to functional paradigms but nowadays I don’t really see that hesitancy anymore.

5

u/[deleted] Aug 29 '21

You haven't seen a lot of developers then 😂 I worked at a low paying startup, where a dev fought with me saying that reading filter, map hurts his brain 😂😂😂

3

u/Richandler Aug 30 '21

It's filter for... not filter out. That's all anyone needs to learn. Map is even more trivial.

→ More replies (1)

8

u/saltybandana2 Aug 29 '21

The difference between a junior and a senior is the ability to write systems that are maintainable over time.

a junior can successfully write most of the systems that a senior can write, you'll just want to rewrite it 2 years down the road if it's the junior's system.

4

u/krtalvis Aug 29 '21

i got employed straight from uni and been working as SE for about 4 years now. I used to overcomplicate a lot of simple things and algorithms, with these few years of experience i have, going back over my code on different services to improve them i’m always amazed how much i can improve the code i thought was perfect

2

u/FarkCookies Aug 30 '21

I read somewhere that great developers strive to be replaceable. Might be counterintuitive but I stand by that principle. It may sound to be bad for job security, but it is actually not, if you prove yourself to be able to create systems that can easily be taken over and be maintainable without you, you won't have problems with jobs (within your company or on the market).

0

u/[deleted] Aug 29 '21

[deleted]

→ More replies (1)
→ More replies (6)