views:

348

answers:

9

Whilst working on some generally horrible Javascript code this morning, I came across the following (in multiple places):

// make moveAmount negative
moveAmount = moveAmount - (moveAmount * 2);

I sit directly across from the guy that wrote this; he's been a developer here for seven years. I, on the other hand have just started, am pretty junior and don't claim to know jack.

Nevertheless it has got me wondering about the guy's contortions of simple logic after so many years developing software.

My question is what view others here might take of the overall competancy of a developer that wrote this (3 weeks ago), or does it even reflect at all?

Would anyone point out the convolution?

I, myself, work in constant dread that such judgements be made of me.

+3  A: 

Well it works so you would just look like a p**** if you told him that you dislike that code and probably rightly so :) Then again he might have done that code 7 years ago as the very first JavaScript he wrote, but seriously never judge someone from just ONE LINE of code.

willcodejavaforfood
I definitely wouldn't point it out
mysomic
As Aaron says, there may be some reason that's no longer valid anymore why this code was written like this. Perhaps in some far-off scripting language this code was good. Unless you asked you'll never know.
Martin Peck
I'd point it out. You owe it to your coworkers to be straight with them and try to work together to improve both of you.
mquander
I agree but not in this case since it actually works and to be honest there are worse things you could do
willcodejavaforfood
+1  A: 

It's tempting to find one example and generalize about a developer, but unless he has a track record of this sort of nonsense, I would consider it an isolated incident. Simply ask him why he didn't write :

moveAmount = moveAmount * (-1)
Mike Pone
....or moveAmount = -moveAmount
mysomic
finding// Really Dave (or whoever)?moveAmount = moveAmount * ( moveAmount * 2);might be equally as annoying.
Aiden Bell
+1  A: 

this behavior is different from mountAmount = -moveAmount in the case where 2*moveAmount may cause an overflow if moveAmount was big enough (like 2^32-1 for example).

I don't know if that was his intention though.

yx
+25  A: 

Simple solution: Show him the line of code and ask why he did it. It's an opportunity for both of you to learn something. Maybe there was a bug in a browser or some other issue (rounding comes to mind) so the code might break without this. Or he made a mistake. Either way, asking will clear this up.

And while you're right that other people will judge you from the code they see from you, that is not the only thing they take into consideration (and if it is, then you're working at the wrong place -- leave while you're still sane). They will also see when you're polite, curious, helpful.

These things count more than the code you write: Code can be fixed much more easily than angry co-workers.

Aaron Digulla
Agreed. I'd just politely say "Hey, I came across this line of code and was wondering why you did it this way".
17 of 26
Even if he blushes and then it's fixed in the next commit, the subtle mention gets it fixed, and he might go through old code checking for duhs
Aiden Bell
Another thumbs up. You never know whether there might have been some arcane-but-valid reason for doing it.
fenomas
@17 of 126 - You could make it neutral and just ask "why would it be done this way - is there something I'm missing". That way you're not accusing the guy plus you're giving him the opportunity to potentially show you something you don't know.
ChrisF
Yep, as said elsewhere, there could be a reason (lack of sleep, hacked work around, etc.) he did it this way. A non-confrontational query into why this was done could lead to good things. A mod of an old saying comes to mind: Hate the bad code, not the bad coder! :-)
PTBNL
+1  A: 

If he wrote that when he was first beginning, he gets a pass. If he wrote that recently, he gets a thumbs down from me. The overall competency of the developer is definitely suspect.

Others are saying you can't judge a developer by one line of code, but I say it can certainly cast doubt upon his competence. I'm not suggesting you jump to conclusions, but that type of code is certainly evidence of a mediocre developer at best.

... and as for it being related to being overtired or stressed or whatever... the bottom line is that code quality is important. If he wrote a one-liner like this, what else may have been written that doesn't stand out so easily?

Larsenal
+3  A: 

Your example may be poor code, but I've seen worse (after all, there are circumstances where it will work; some code can't even say that). I think the question you're really asking is: is there any line of code so awful that it means the developer can be deemed incompetent on the basis of that one line?

I say no. I have two children who were terrible sleepers as babies. I've come to work with the flu. I've been at work in death-march mode where I've been working twenty hours in a row. In such circumstances anyone can write a terrible line of code. (This is why such circumstances should be avoided.)

Granted, I would hope I would spot the dreadful code later, and fix it.

JacobM
+1  A: 

Since he wrote it 3 weeks ago, I would say he should be open to criticism for this line. It shows an immaturity that is really inexcusable after 7 years of working professionally.

If he would have at least done this:

moveAmount -= moveAmount * 2;

He would have gotten less flack. It at least shows that he's aware of the other operators and is making some effort to make things more readable.

I don't think that you can always judge people with one line, but the code can tell you so much about a person's aptitude that one line can tell a lot about a person.

Kekoa
Your version is clearly less readable.
Boo
PTBNL
+2  A: 

Regarding the fear of judgement, relax. It's true, we're all going to be judged by someone at some point, whether it's some pointy-haired boss or maleveolent little upstart. The main thing to get to grips with, I think, is how to get something useful out of every such encounter.

Obviously, there are going to be people griping about things for the sake of it, but you'll also find many similar situations where there's something to be learned.

The suggestion above to start a dialogue with your co-worker is excellent; it may directly feed into just such an encounter, from which either, or both of you, may learn something important.

Rob
+1  A: 

I say it will depend on the swallow. If isolated, the line of code you've shown is something I would expect from an exhausted programmer, even if a very competent one. It is an example of something just not very clever and tired people do not so clever things. If, on the other hand that kind of code appears frequently then probably you're working with someone with a twisted mind.

Things that are obvious indications of a bad programmer are related to bad practices. Good programmers will not make huge methods. Even tired, they will try to keep their types loosely coupled. They will avoid exposing public fields instead of exposing them through accessors or properties. They will try inheritance and aggregation as forms of code reuse rather than repeatedly doing copy-paste... The list is long. Those are the kinds of swallows that lead me to almost instantly feel it is summer. :-)

Rui Craveiro