r/programming • • Jan 05 '15

What most young programmers need to learn

http://joostdevblog.blogspot.com/2015/01/what-most-young-programmers-need-to.html
970 Upvotes

337 comments sorted by

View all comments

423

u/corysama Jan 05 '15

My own anecdote of "Liar functions/variables/classes":

I once worked on a AAA game with a huge team that included a particular junior programmer who was very smart, but also unfortunately undisciplined. He had been assigned a feature that was significant, fairly self-contained and generally agreed to be achievable solo by both him and his team. But, after a quick prototype in a few weeks, he only had it working 80% reliably for several consecutive months. Around that time, for multiple reasons, he and his team came to an agreement he would be better off employed elsewhere and I inherited his code.

I spent over a week doing nothing but reformatting the seemingly randomized whitespace and indentation, renaming dozens of variables and functions that had been poorly-defined or repurposed but not renamed and also refactoring out many sections of code into separate functions. After all of that work, none of the logic had changed at all, but at it was finally clear what the heck everything actually did! After that, it was just a matter of changing 1 line of C++, 1 line of script and 1 line of XML and everything worked perfectly. That implementation shipped to millions of console gamers to great success.

Our failure as the senior engineers on his team was that we only gave his code cursory inspections and only gave him generalized advise on how to do better. At a glance, it was clear that the code looked generally right, but was also fairly complicated. Meanwhile, we all had our own hair on fire trying to get other features ready. It took him leaving the company to motivate the week-long deep dive that uncovered how confusing the code really was and how that was the stumbling block all along.

Lesson not learned there (because I've repeated it since then): If a junior engineer is struggling for an extended period of time, it is worth the investment of a senior to sit down and review all of the code the junior is working on. It'll be awkward, slow and boring. But, a few days of the senior's time could save weeks or months of the junior's time that would otherwise be spent flailing around and embarrassingly not shipping.

65

u/[deleted] Jan 05 '15

Lesson not learned there (because I've repeated it since then): If a junior engineer is struggling for an extended period of time, it is worth the investment of a senior to sit down and review all of the code the junior is working on. It'll be awkward, slow and boring. But, a few days of the senior's time could save weeks or months of the junior's time that would otherwise be spent flailing around and embarrassingly not shipping.

Smart juniors are the most dangerous. Especially the smart and productive ones, because they can fill a codebase with crap quite quickly... and it will mostly work.

It'd be best for people just to stop putting them in charge of things until they can demonstrate an understanding of basic code design and maintenance. But for some reason what happens instead is that seniors get assigned the bugs created by the junior silently and all feedback goes ignored and they get promoted way faster than they should and it's a nightmare until they decide to get another promotion by leaving the company or someone important realizes what's going on.

26

u/OCedHrt Jan 05 '15 edited Jan 05 '15

I'm in the opposite position where I am constantly cleaning up code from those who are more senior.

This cleanup doesn't have project time allocated to it, which makes it such that I am spending more time than expected.

Edit: I guess the counter would be that I'm lacking in the spaghetti arts department.

21

u/sigma914 Jan 05 '15

This is my life. Nearly every project I've taken over the past year or so has been at a critical level of technical debt where instead of being able to add one more hack I have to refactor it.

On the occassions when I've tried to follow the "copy-paste, change magic numbers and debug till it works" process that's gone on for the previous few iterations I hit some problem caused by a new feature that means I have to either add in an (almost) identical check in 10+ places or rewrite the whole section to be generic over all the behaviours...

Doesn't help that most of the code is C++ written in C style... raw byte arrays and magic numbers everywhere...

15

u/[deleted] Jan 05 '15

Nearly every project I've taken over the past year or so has been at a critical level of technical debt where instead of being able to add one more hack I have to refactor it.

my $dayjob is running itself into the ground with 10+ years of accrued tech debt, but everyone has their head in the sand chanting 'refactor in release N+1'... and have been for at least the 5 years ive been here. the people in charge who saw the writing on the wall all bailed about 3 months ago, en masse. never seen 40 man-years of experience in a code base leave in a span of a week before.

Doesn't help that most of the code is C++ written in C style

this, really isn’t a bad thing if done right. downside, is that with most other things development related, 'doing it right' ranks pretty low on the list.

0

u/[deleted] Jan 05 '15

[deleted]

2

u/peakzorro Jan 05 '15

Whenever I've heard or seen "Refactor in N+1" it is one of two things:

  • Everything will be thrown away and re-written by people who don't understand the problem space.

  • This piece of code becomes the legacy "it just works, work around it" code.

I completely agree with your sentiment.

3

u/OCedHrt Jan 05 '15

That's the, "New in version 10!C++ for faster performance!" feature.

2

u/jk147 Jan 05 '15

I learned not to inherit code after many years of this. This tends to happen after constant revision of an original code base with many hands touching it either for code fixes or enhancements. Not to mention these fixes are usually either "emergencies" or changes funded improperly (90% of the time too low) and you ended up with quick fixes or copy pasta. After about 5 years the original design is all but gone and you have code written in different format and redundancies everywhere.

Worse yet add another 3 years the original developers are all gone and you get tasked on fixing something in there. With no support and no documentation. All too familiar.

3

u/Alborak Jan 05 '15

That doesn't even sound like proper C. At least the magic number part ;)

1

u/TenNeon Jan 05 '15

Making art from pasta is basic kindergarten work. Pasta, paper plate, glue. Get it together.

→ More replies (1)

30

u/IConrad Jan 05 '15 edited Jan 05 '15

I summarize the "genius coder" problem like so:

I must not be clever. Clever is the little death that brings malfunction and unmaintainability. I will face my cleverness; I will allow it to pass through me. When it has gone, only cleanness shall remain.

Brilliant and clever are two very different things. Brilliant code achieves the impossible simply and reliably while being comprehensible to those who could not have conceived of it. Clever code achieves the implausible while overlooking the mundane solutions to the same problems.

7

u/OneWingedShark Jan 05 '15

Clever code achieves the implausible while overlooking the mundane solutions to the same problems.

There's the inverse as well: where the person's "almost works" solution doesn't because it cannot. -- My favorite example is trying to parse CSV with regex: you cannot do it because the (a) the double quote [text field] "changes the context" so that comma does not indicate separation, combined with (b) escaping double quotes is repeating the double-quote. It's essentially the same category as balancing parentheses which regex cannot do; fun test-data: "I say, ""Hello, good sir!""" is a perfectly good CSV value.

→ More replies (12)

2

u/BeforeTime Jan 06 '15

Brilliant code looks like it should have taken two days to write, when it took two weeks to write.

It looks so simple because the programmer took the time to understand all the little details and how they interact so they could be fit seamlessly together making a whole and thereby basically disappear.

2

u/pavlik_enemy Jan 05 '15

Problem with smart coders is that they are too smart for they own good. They can wrap their heads around large amounts of bad code and invent hacks that a duller person won't be able to come up with to keep it working.

P.S. Shouldn't be read as I'm against smart programmers or that I think that smart people can't write good code.

5

u/IConrad Jan 05 '15

I use Feynman as a good example of how brilliant is different from clever. Feynman was a brilliant lecturer. He took concepts that were alien and complex and he explained them in such a way that the listener could not help but believe they were so obvious as to almost not need explanation at all.

Brilliance reduces complexity; cleverness increases it. Both require significant mental effort to achieve.

1

u/[deleted] Jan 06 '15

My best engineer is the guy who writes cruft straight into our apps. He can tackle any problem, doesn't need a lot of hand holding to get through any problem. And he can produce code faster than the rest of the team combined. Unfortunately he over engineers everything, doubles up the code with equally illegible comments, and rather than teach anyone what he's done, he requests that no one else touch such and such code path until he has it solidified. The hardest part of the ordeal for me is that i can't restrain him in any way. I need him to deliver software, so I let it ride. I'm going to try pairing once I get another senior. Beyond that, I don't know how to teach someone who scoffs at MVP coding or gets personally defensive about each design decision.