views:

1383

answers:

25

Does anyone actually think this is a good reason to "Dumb down" your code? When a manager asks you to make your code simple (in terms of technology skills required to understand it) at the cost of more verbose cluttered code what should you do?

+3  A: 

Yes. It's a very valid reason to take it down a notch. The reality is that a very, very large number of developers (as in most) are at the junior level.

As far as what you should do... Say "Yes Sir" or "Yes Ma'am" and do it. There is only one boss in that relationship.

UPDATE: As some people seem to think that having a jr dev learning advanced topics while wading through obfuscated code I want to throw one more thing in here.

When ANY developer (jr or otherwise) runs into code they don’t understand, their first approach is to refactor it into something that is understandable. This is called the “Wow that code is crap I must rewrite it!” syndrome. I’m willing to bet everyone on this board has experienced it. So, as a business owner, do I want to pay for code to be developed each time a new person comes by or do I want to pay for new features to be added?

Guess which person I’m going to keep around longer.

Chris Lively
Totally. If you want to keep the job, do what your boss says!
hmcclungiii
do what your boss says, but to each his own level of expertise, when you see a manager tell a cook how to do his job you should worry
Ric Tokyo
Wow, both sides of this argument is very insteresting and valid.
Jobo
And no wonder they remain junior level....
icelava
Absolutely not, the junior devs are meant to be able to learn - how are they ever going to do that if they never encounter anything new
1800 INFORMATION
+54  A: 

I highly disagree. Junior developers will end up being Senior developers. How? By encountering advanced topics that aren't taught in school.

My code base now makes heavy use of Inversion of Control containers. I would never revert my code to the old way because a junior developer had issues groking IoC. Instead I would take them out for a beer after work and discuss it. The more the junior dev learns the less hand holding needs to be done.

Here's a blog post discussing this very topic.

Scott Muc
Like your style of taking them out for a beer rather than brow beating and berating them ;)
Simucal
Heh... Over the last year I've learned how much teaching a subject learns the teacher. Every time I stumble explaining a concept it reminds me that I'm no expert and that I can benefit from the questions of a junior/intern.Plus, who wouldn't want to go out for a beer and talk code? ;-)
Scott Muc
Well said brother!
Chuck Conway
Indeed - and if you know that your code is going to be maintained by someone who may not understand it - documentation, documentation, documention... code comments, process flows, etc. go a LONG way.
Greg Hurlman
excellent answer scott.
corymathews
+1 for management style.
WOPR
I want to work for you.
willcodejavaforfood
+1 for wishing you were my super
dragonjujo
+4  A: 

No. In the past, I've learned a lot from seeing the tricks of more experienced developers. I'd much rather have had the opportunity to learn something new from them than have had them dumb things down for me.

Boojum
+4  A: 

Well if you intend to maintain your code forever, never change jobs, never feel the urge to work on something new, and can assure everyone you will never be hit by a truck, then sure there is no need to dumb down that puzzle code.

Robert Gould
+20  A: 

If you're constantly dumbing down your code or designs, it's a pretty good way to make sure your junior developers stay dumb. Challenge them and use it as a mentoring opportunity. Of course, some will never learn, but you've got bigger problems at that point.

It's not just pointy-haired bosses either. As a senior dev, it's often difficult to resist the urge to mommy junior developers. "Oh I'll just do this part because it's way too hard for them", or it'll take them too long, or they'll get way off in the weeds.

And finally, make sure you strike a balance between idiomatic code that uses the full power of a language vs idiomatic code that abuses that power. There's no reason you need to override the || operator just to run its args in two separate threads. At least dumb the code down a little for your older, dumber, future self.

Dave Ray
+8  A: 

Yes readability and being able to easily understand code is a big part of maintainability in my opinion.

Element
+10  A: 

There's a difference between puzzle code and complex code.

I've found that the single biggest issue is that there is a big difference between "easy to understand by reading" versus "well-factored", and that the two goals are often in direct tension with one another. In well-factored code, there is a lot more jumping around between classes and a lot of virtual dispatch, so the path through the code is very non-linear.

Jeffrey Hantin
...but with the right source-code editor (i.e. one that builds up dependency/definition info), jumping around to find the definition of some function being called could be as easy as a click. Alternatively, I've found that stepping through such factored code under a debugger can help...
Reuben
Even if your editor helps you, at some point you need a mental picture of the application. If there is too much jumping around you will have problems ...
Guillaume
That's why well-factored code tends to require descriptive names, thorough unit tests, clear module/namespace boundaries between problem subdomains, and a well-documented set of public interfaces and abstract classes per module/namespace.
Justice
+3  A: 

I disagree with the manager: What needs to be simple is the code, not the technology used to write it.

I would, however, impose a closely related requirement:

  • The internal documentation states clearly what technologies are needed to understand this code, and it gives references to places where those technologies can be learned.

For example, even as a senior developer, I find all matrix codes baffling. But if somebody gives me a reference to the right part of Numerical Recipes, I can puzzle out the details.

Norman Ramsey
+2  A: 

If you dumb down your code, you're going to be stuck working with dummy junior programmers who will never be familiar with advanced coding techniques. If there's any verbose code that's trying to express an inherently complex procedure that you wrote, the aforementioned junior developer probably wouldn't be able to see the forest for the trees anyways. And they'd probably screw up if they had to express a complex concept if all they knew were basic primitive constructs whereas if they knew how to express what they meant tersely and elegantly, the code has a better chance of being correct.

Mark Cidade
A: 

I suggest keeping the code in a "Geeky-level" and comment it well so that the juniors can understand the intention behind the code and simultaneously learn a better way (or a right way) to code, so we have the best of both he worlds.

Shyam
+1  A: 

It depends on the code. Is this something being shipped in your flagship product that requires use of the features your manager wants you to remove for performance reasons? If the answer is yes I would try to have your manager let you keep the code and just write up a document explaining in detail the section of code that is hard to understand. If it's an internal app that needs to be maintained by lots of different people and the complex features can be removed with out negatively affecting the program remove them and pick more important battles to fight.

Jared
+4  A: 

Its a balancing act...
If any 3 people on your team can 'read' your code and know what its doing... no need to change. However if you're the only person who can understand your code (no matter how rad/clever you think it is).. maybe you should take it down a few notches.

Another guideline to help would be to 'Try the simplest thing that works.' All the latest buzz words are nice to know however what it is even more important is having the skill to spot where you could get by without using them. You don't need to spray paint your code with IOC or Frameworks or Design Patterns...

The manager's side of this argument is sorely missed in this thread :) (and for the record.. I'm not one). His/Her major concern being he doesn't want a dark area of code that no one else dares to venture into.. so if you can convince your boss that a few other people on the team can make an arbitrary fix (or better yet.. show an actual bug fixed by someone else) - the mgr should let you off the hook. Disagreeing with your boss is another art :).. but you can talk things out usually.
You dont have to go all the way backward to Lowest Common Denominator.. strike a balance.

Gishu
Robert Gould
A: 

I think it is the manager's way of politely telling you that your code is too obfuscated/complex/jumbled/puzzle code...whatever you want to call it. Sometimes we get so involved writing our codes that we forget that someone else will have to come along and read it later.

Al W
+2  A: 

Scott Muc said:

"I've found that the single biggest issue is that there is a big difference between "easy to understand by reading" versus "well-factored", and that the two goals are often in direct tension with one another. In well-factored code, there is a lot more jumping around between classes and a lot of virtual dispatch, so the path through the code is very non-linear."

Quoted for truth, and I think this is one of the biggest problems with C++ code in general. If you're the one that wrote the code, it's pretty easy to come up with a very complicated set of stuff that is well factored, makes lots of sense if you already know it, works well, and generally resembles a diamond crystal, etc. but which, from the perspective of someone who's trying to figure out how you got there and why things are the way they are and how things work, and how one might make changes that fit into the existing system and satisfy new requirements, is almost completely opaque and impenetrable.

How does this kind of situation help maintainability? That situation is one of my main beefs with C++ programmers. Far better to have a mess of plain C code which can be hacked upon than a diamond crystal of inpenetrably super-factored code which nearly nobody can figure out how to sensibly modify without smashing the crystalline structure.

smcameron
+17  A: 

Well, I think it's reasonable to avoid using "clever" language constructs unless they really, really make the code better - at which point if a junior developer sees it, hopefully they'd ask rather than just being flumoxed.

Here's an alternative way of phrasing it though: "Write your code so that it's easy enough to understand that if you get called at 3am and asked to fix a bug in it, you can still understand it."

Seriously, make it as easy to understand as possible. That doesn't mean a comment every other line - it means a comment where the purpose of a piece of code isn't obvious, and only then where the preferred choice of "well make it obvious then" doesn't work.

Jon Skeet
+1  A: 

One way to "dumb down" code that I actually think is an excellent practice is to use longer variable names and longer function names. Naming variables and functions to make their purpose easily understandable is a significant engineering task, IMHO, and takes extra effort on the part of the original author of the code. Damian Conway has some excellent examples in "Perl Best Practices". Some examples include: Prefer "final_total" to "sum"; prefer "previous_appointment" to "previous_elem", prefer "next_client" to "next_elem". Prefer "sales_records" to "data". Etc. He also pushes for using grammatical templates (Noun-adjective) and staying consistent. Don't use max_displacement one place and then use VelocityMax in another. Index variables need real names too:
sales_record[i] vs sales_record[cancelled_transaction_number]

I frequently "refactor" my code at the end of a development cycle by finding new names for all my functions and variables. In a modern editor it's trivial to change them all, and it's only at the end that I really figure out what I used them for. "Dumbing down" code this way isn't classic C, but it's easier for me when I come back months later asking WTF did I do?

Leonard
A: 

You should just remind your boss that you can build rocket ships or chicken coops, and he will have to pay you the same for either one. Do what they say but generally an environment like that lends itself to people looking for a new environment.

jpmcclung
A: 

I learned it the hard way and, in retrospect, find that it was the better way. Let the cycle repeat itself.

Learning
A: 

I agree 100% with the argument. With one major addition: Train your junior developers until they understand your code ;-)

MadKeithV
A: 

I'm talking about using "unusual" technologies. In this case it's JQuery. This issue came up when I was writing a wizard control for user registration. The navigation menu needed to be customised and the current step in the wizard had to have a different css class in the menu. This meant I needed to get access to the currently selected step when generating the menu. My solution was to output the current step index in a hidden html field which could then be read by JQuery in order to customise the css.

I thought that this was much nicer and cleaner than using the databinding syntax in ASP.NET which doesn't have compile-time checking and messes up the layout of the html.

The databinding solutions is "standard" while the JQuery one is "unusual" which means that it's less likely to be understood by a junior.

I'm trying more and more these days to provide the required data for the UI rather than hack it into the UI with databinding which is why I added the hidden field with the current step index.

Jonathan Parker
For what it's worth - I believe for web apps jQuery now is pretty standard. If a junior web developer doesn't know it they should learn it.
DanSingerman
+4  A: 

Your goal should not be for your code to be easy to understand for a junior developer. Instead, it should be easy to understand for a maintainence programmer.

This means:

  • Local "complexity" is okay, when needed. If they see the complex code they'll know they need to dig deeper.
  • Hidden complexity is bad. If you can't see that changing a piece of code will have subtle side effects then maintaining the code will be a nightmare.
  • New technologies that are visible are also okay, when not taken to extremes.

This is because those that maintain code rarely have the same overall understanding of the system. Or the time to develop it.

Darron
+1  A: 

I've known developers who wrote highly obfuscated code that they felt was advanced but which the rest of the team felt was unreadable and unmaintainable. Part of this involved overuse of advanced language features (in C, the ternary operator and the comma operator) and writing in an obscure personal idiom (for example, replacing ptr->item with (*ptr).item everywhere) that no-one else would ever be able to maintain. The author was trying to outsmart the optimizer (which to be fair, was far from good).

Note: I'm not suggesting that "x = (p == NULL) ? "default" : p->value;" is complicated, but when someone uses ternary operators that span many lines, are nested, and make heavy use of the comma operator, code quickly becomes unreadable.

In this sort of case, "dumbing down" the code would have been a good idea. The problem was not advanced algorithms nor advanced language features, but overuse and inappropriate use of advanced language features, and an obscure personal idiom.

However, in the case you are asking about, where the manager's changes make the code more difficult to read and maintain, I agree with you and the others who have responded. I just wanted to point out the alternative that no-one else has mentioned.

Eddie
The ternary operator is advanced? You've really set the bar low there.
brian d foy
The ternary operator is advanced the way this developer used it -- multi-line nested ternary operators. I saw him use ternary operators nested three deep once, with heavy use of the comma operator. I agree that normal use of the ternary is not advanced.
Eddie
+1  A: 

The old quote is appropriate here:

Make everything as simple as possible, but not simpler.

J.F. Sebastian
A: 

It is simply impossible to make progress or to innovate in any industry without doing things that others don't understand. Innovation is necessarily blasphemous. Why? Because if you're doing things that make sense to everyone else around you, the odds are you're not the first one doing it. ;)

That being said, there is a significant difference between doing something that is difficult to understand simply because it's a new or complicated problem versus doing something that's difficult to understand because you're trying to show off or you think confusing people will somehow gain you job security (which I've never seen work, but I've heard of people trying).

Should you make things easy to understand? Yes absolutely, as much as humanly possible. However a program that works and does its job well is the higher priority.

The manager's complaint should never be "don't do this because our junior guys don't understand it" -- it should only ever be "do x instead of y whenever feasible because x is easier to read / understand". This also assumes that x and y are equivalent (accept the same input and produce the same result).

I can't stand when managers do that... I've had three different managers bawl me out for using perfectly normal code the way it was designed to work, not because I was doing anything complicated, but rather only because they felt like it was too much effort for the other guys on our team to go RTFM on the language we were using. As a management strategy, that's totally backwards. It's like being the Holy Roman Catholic church and insisting that the laymen are too dumb to be trusted with literacy.

If you want to know really how ridiculous some of these managers get, try this: I had one manager bawl me out for declaring a variable as a type of "boolean" because he didn't feel the other programmers could handle it. Actually when I asked why, his answer was "because we don't do that here", which is a non-answer, but I interpreted it to mean "dumb it down". They were also berating me for that and similar practices as though it should be obvious that good programming habits were actually "bad" and that I should already know why even though they had never expressed a preferred programming style (either formally or informally). Needless to say, it was a bad job.

Isaac Dealey
A: 

Make sure you can understand what it does 6 months down the road.

When in doubt, COMMENT your code. That's what comments are for.

Dana
Or try to write self-descriptive code, when possible, instead of commenting it...
matma