views:

38293

answers:

241

What are, in your opinion, the worst subjects of widespread ignorance amongst programmers, i.e. things that everyone who aspires to be a professional should know and take seriously, but doesn't?

+114  A: 

Ignorance of the fact that it's really important to let your coworkers know when you're ignorant of something!

Especially when working with new colleagues, one of the hardest things I find is trying to figure out what the person knows and doesn't know.

Richard Ev
+1 for that. It makes for a much better product if everyone on the team knows the ability of the rest of the team.
discorax
The biggest problem with that is, the person who doesn't know ... doesn't know they don't know ... kind of like how stupid people think their smart.
John MacIntyre
Agreed. It can take a while of dealing with someone to realize they do this, but after a while of interaction and cooperation, you realize they never say "I don't know" or "I'll get back to you on that" then...danger, danger...
Stu Thompson
I've been that 'new colleague'. This confuses quite a lot.
Arnis L.
I won't hire anyone who doesn't say "I don't know" at some point during the interview. If you know everything, you can't learn anything, including how to do this job.
Boofus McGoofus
Nothing personal, but I hope I am never being interviewed for a job by someone called "Boofus McGoofus".
harpo
Programmer egotism is so prevalent, it's disgusting. Then again, what should I expect from a culture full of "ninjas" and "rockstars"?
David Rivers
A: 

Ignorance of the fact that questions like this should be community wiki.

arul
Rolled back. If you don't like the answer, vote it down, don't just remove it.
Dan Dyer
+315  A: 

In Java and C# (leaving aside ref/out):

Myth: "Objects are passed by reference"

Reality: "Objects aren't passed at all; references are passed by value"

There's a significant difference, and it's often ignored :(

Even in C everything is passed by value (including pointers).

EDIT (jonskeet): Judging by the comments, it may be worth referring to my article on C# parameter passing. Hopefully this will reduce confusion rather than increasing it...

Jon Skeet
Significant difference? Its the same thing. Explain more on what you think the difference and/or any problems that occur when ignoring it.
Tim Matthews
Perhaps you could explain this significant difference, in terms of what is happening at a lower level.
Shane MacLaughlin
I want some examples on how the difference shows up.
PEZ
please check answers by Litb on pass by reference/value in SO and wikipedia article he has mentioned
yesraaj
+1 though it catches everyone out the first time, it's those who don't take the time to understand afterwards that are ignorant.
seanhodges
@rajKumar: a direct link? Especially for the next person who won't be arsed to go look?
Adriano Varoli Piazza
+1, Very true. It took me a quite a while to understand it myself. (Until it bit me in some code I was writing.)
coobird
http://stackoverflow.com/questions/410593/pass-by-reference-value-in-c and http://stackoverflow.com/questions/373419/whats-the-difference-between-a-parameter-passed-by-reference-vs-passed-by-value answer by Litb
yesraaj
In fairness I've yet to see a single real-world problem caused by someone not understanding this.
Draemon
@Draemon: It leads to people not understanding what happens if you use "ref" on a reference type.
Jon Skeet
@Draemon: The number of times I've tried to explain this and so amazingly often just get glazed looks.
Binary Worrier
P.S. Jon, excellent way of looking at the problem BTW, will use this one from now on. Thanks.
Binary Worrier
'pass by reference' and 'pass a pointer by value' are equivalent in C. Google 'pass by reference'-first hit: http://www.cs.princeton.edu/~lworthin/126/precepts/pass_val_ref.html ; The misunderstanding comes from C++' somewhat confusing concept of references: http://yosefk.com/c++fqa/ref.html#fqa-8.1
Christoph
@Christoph: The thing is, "pass by reference" has a very specific semantic meaning in computer science, and it's *not* the same as passing a pointer by value. The latter is usually used to emulate the former, but there's a difference and people should understand it.
Jon Skeet
@Jon: So your argument is that C doesn't support call-by-reference at all, but you can emulate it using pointers; calling passing pointers by value call-by-reference is then just a slight inaccuracy of language?
Christoph
@Christoph: Just checked - that's exactly what wikipedia says it means...
Christoph
@Christoph: What's the "that" in your previous comment? And while I'd say that calling passing pointers by value call-by-reference is an inaccuracy of language, I'd say it's more important than "just a slight inaccuracy" implies. Being sloppy with language leads to miscommunication.
Jon Skeet
In particular, if you don't know the difference between the two, then seeing Foo(ref StringBuilder x) in C# will leave you confused.
Jon Skeet
java doesn't have a "ref" keyword AFAIK so while it might cause problems (i.e. trying to write a swap method perhaps) it doesn't really fit with all of the above.
wds
@wds: Indeed, Java doesn't have "ref" - but if people are told that parameters are passed by reference, they might *expect* to be able to write a swap method, or make similar changes. Living with that sort of misunderstanding is just a bad idea when it's really not that hard to get it right.
Jon Skeet
@Jon: I just wanted to express that wikipedia agrees with you. As for the inaccuracy being slight: I'm currently programming in C, Java and JavaScript - afaik in none of these languages is disambiguity possible. And coming from C, I interpreted the 'Myth' the-right-way[tm]
Christoph
@Christoph: Righto :) Many people will indeed interpret the myth the right way - particularly if they haven't used languages which have *real* pass by reference. The trouble is when those people then propagate it to people who know the CS definition, and believe what they hear :)
Jon Skeet
I fell prey to this one when learning C# despite coming from years of C++ work. So thanks, Jon, for pointing this out.
Mark Brittingham
@PEZ: write me a method in Java that swaps to integers. void swap(Integer a, Integer b);not so easy a task with pass by value.
Nathan Feger
#define BYREF * - there you go, fixed C for you.
aib
I'm not convinced it's a myth so much as a half-truth. In Java, objects are 'passed by reference' only in the sense that the language doesn't let you talk about objects _except_ via references. The poor choice of phrase is responsible for much misunderstanding, so +1.
Daniel Cassidy
Jon Skeet's pet peeve is that no one understands C# as well as Jon Skeet!
Steven A. Lowe
I think what you are trying to say is that because objects are a referenced type that the ref/out keywords only modify the way the reference works. If so then that is true and I take back what I previously said but I think you could word it better.
Tim Matthews
The point is that ref/out actually work exactly the same with reference types and value types - once you distinguish between a reference and an object, and understand that the value of a parameter/argument can never be an object. (Continued)
Jon Skeet
If you go by the "objects are passed by reference by default" myth, what do you say when "ref" is also specified? "The object is being passed by reference by reference"? The whole thing stems from not understand what the value of the parameter really is. Once you've got that, the rest is easy.
Jon Skeet
Funny, I just had a conversation with two of our new guys explaining this very concept. They looked at me like I was crazy. +1 for you(not that you need it.
Jonathan Beerhalter
void JavaDoesNotSupportPassedByRef(DataTable x) { x = new DataTable("invoice"); }void CsharpDoes(ref DataTable x) { x = new DataTable("invoice"); }DataTable j;JavaDoesNotSupportPassedByRef(j); MessageBox.Show(j.TableName);DataTable c;CsharpDoes(ref c);MessageBox.Show(c.TableName);
Michael Buen
@Jon, if you consider value type and reference type Objects, then reference type Objects are passed by reference and value type Objects are passed by value (the actual object is copied). But the actual reference is passed by value indeed.
Pop Catalin
@Pop: But the point is that the value of the parameter *isn't* an object. It never is. Trying to apply that mental model causes problems - particularly when you then have a StringBuilder ref parameter. Is that passing an object "by double reference"? Separate reference from object and life is better
Jon Skeet
"But the point is that the value of the parameter *isn't* an object. It never is". Yes but that value is an Object reference :). "Trying to apply that mental model causes problems" never had any kind of problems with this model, passing a object by reference or passing reference to an object ...
Pop Catalin
is the same thing for me. "Separate reference from object and life is better" I've never combined them, although they are related.
Pop Catalin
@Pop: Yes, the value is an object reference. And that reference is just copied, so it's pass by value. That's the point. Passing by reference has different semantics when the parameter's value is changed in the method.
Jon Skeet
So breaking it down, objects are passed by reference which is passed by value (default), or by reference (with ref) when the reference is passed by reference which (the second reference is a reference to the first reference) is passed by value. So in the end you have to pass something by value :)...
Pop Catalin
"Objects aren't passed at all" I'd add by value. You seem to say that passing equals copying, so to pass something you have to copy, which is true at hardware level, but passing an object by reference or passing a reference to an object by value, is exactly the same thing, the first definition ...
Pop Catalin
doesn't include how references are passed.
Pop Catalin
Pass by value = copying: the initial value of the parameter is a copy of the value of the argument. Pass by reference = aliasing: the parameter *is* the argument; changes to the value of the parameter are visible in the caller. (Note again that the parameter value isn't an object.)
Jon Skeet
The nicest thing of it all (correct me if I'm wrong cause I certainly can be), if I recall correctly the original statement is FALSE, everything is in fact passed by reference by default due to compiler optimizations who makes sure the code is correctly used and copies only if necessary
Jorge Córdoba
@Jorge: No, I believe you're wrong. For one thing the behaviour has to at least be *as if* they're passed by value unless you've explicitly used "ref"; for another thing I don't believe the JIT does such an optimisation. I'm willing to be persuaded by evidence though :)
Jon Skeet
Bear in mind that most structs are small anyway, and copying a reference is at least as cheap as passing it by reference. This would have to be an optimisation basically tailored for large structs - which are discouraged in the first place. Why waste JITting time looking to optimise that case?
Jon Skeet
another hint about it is to remember by-reference passing means passing the lvalue. thinking of lvalue as a "location value" can help: The value *is actually* a location, but the value does not *store* a location. References in c#/java store locations (the location of the objects they reference)...
Johannes Schaub - litb
contrary, if one passes by-value, what is passed is the value that a location contains. thus, we read out a value of an lvalue, and what we get is an rvalue. i tend to think of it as an "expRession value". if we pass a reference by-value, we read out the value that the reference contains...
Johannes Schaub - litb
the location is lost, because the value is not associated with that location anymore. now, if one would say "objects are passed by value", that can't make sense anymore. because you never read values out of objects in C# (not talking about value-types here) or Java.
Johannes Schaub - litb
... and if one would say "objects are passed by reference" that also isn't true then: what is passed is not the location of the object, but the value contained (rvalue) in the location of the reference storing the location of the object.
Johannes Schaub - litb
"stored location" as the value that says where a location resides and "location" as the location itself is somehow ambiguous. one should find better names for those words. but i'm sure better names were already found and i just don't know about them :)
Johannes Schaub - litb
@litb: I'm afraid to say that confused me rather a lot, and I'm not at all sure I agree with it. You'd have to be clearer about what you mean by "store" etc. My best efforts are in my article (linked in the main answer) - but it's still a confusing topic for many people :(
Jon Skeet
hmm right i see that's not a good idea to post such long things as comments. they just confuse 'cause one can't exlain properly. i guess best matches with your words is: location <=> storage location, stored location <=> value of a variable of reference type, lvalue <=> variable of value type.
Johannes Schaub - litb
i like your and richardson's page about it very much. kudos :) probably my description also was a bit confusing because i tried covering c++ and c# and java all at once. so my stuff doesn't quite match your words. i think i'll write an article too,about c++. anyway thanks for stating your opinion :)
Johannes Schaub - litb
there should be a badge for so many comments :p
fmsf
Geez that's a horrid nit to pick if you're going to include java... You're technically correct, but as implemented in Java, if you remember you are passing references to objects (Forget about passing BY reference if that bugs you--it doesn't have a real meaning in Java) you'll be fine.
Bill K
@BillK: So you're saying that if you ignore the myth and know what's really going on, there won't be a problem? I absolutely agree, and that's hardly surprising. However, people using the wrong terminology confuses people who *don't* know Java but *do* know what the terminology means. (cont)
Jon Skeet
I've seen people get confused by this plenty of times on newsgroups and other forums. Sticking to the right terminology makes life easier for everyone. I don't think it's a "horrid nit to pick" when getting it right aids communication.
Jon Skeet
Actually the real problem is that structs are value types but there's no indication that you have a value type. When you see a function declaration int foo(Bar b); you cannot tell whether Bar is an object or a struct without looking it up. They should have required the struct tag to be sticky (as in C): int foo(struct Bar b) or int foo(ref struct Bar b) so that you always know whether the parameter is reference type or value type. IOW, if the difference between value types and reference types were pounded into the developers' heads, there'd be less confusion.
jmucchiello
@jmucchiello: I can't remember *ever* having a problem due to that. Then again, I generally want to know a certain amount of information about any type I'm dealing with - and class vs struct is a pretty fundamental one.
Jon Skeet
@Jon: I think you've still not answered the question: "What is the _real_ problem that's caused when confusing 'Passed by Reference' with 'Reference Passed by Value'?" The result is the same - you end up with an argument, that is treated as an object, which can be modified.
Kieveli
@Kieveli: no, is it not the sameLook here:http://gist.github.com/219404
kentaromiura
@Kieveli: As kentaromiura says, they're not the same. You need to understand the difference between changing a parameter's value and changing the values within the object referred to by that parameter's value.
Jon Skeet
@Draemon we had this problem once ( was a bug ). One reference value was passed into a function ( passed by value ) and the object was created there and assigned to the reference. Now from the main method the value was still null.
Tanmoy
Funny that I wasn't aware of this semantic issue, yet most of your article's content was obvious to me(and none of the things I didn't know were harmless since I was aware that I didn't know them).
luiscubal
I think people (including myself) are more confused by terminology than anything else: "Objects are references, but not passed by reference; they are passed by reference-value" '...'
BlueRaja - Danny Pflughoeft
@BlueRaja: I agree that terminology is the confusing bit - but it's mostly a matter of separation. Objects *aren't* references any more than my house is the same as a piece of paper with my address written on it :)
Jon Skeet
@Jon: You are pickier than a porcupine (who I can assure you are very picky).
BlueRaja - Danny Pflughoeft
@Jon: +1, I can't believe how many people seem to think this just doesn't matter. How arguments are passed isn't really some esoteric point, it's a fundamental feature of the language. Programmers should care about this stuff!
Tim Goodman
@Jon: +1 - Nice! I didn't realize that there was any confusion about this - a decent developer should understand the semantics of their language, *and* be able to clearly communicate it.
Charles
My stab at explaining this: Aside from ref/out, an object's *reference* (the integral address) is passed by value. For ref/out semantics, that obviously wouldn't work; if you assign another object to the parameter within the function, you've merely changed your *copy* of the reference. That's where the distinction becomes important - if you assign something to the parameter, does it change the caller's reference? That depends - did you pass *by reference* (*with* ref/out), or did you *pass the reference by value* (*without* ref/out)? Learning some C++ will help with understanding this.
Charles
@Charles: Yes, that's spot on. And yes, it makes a difference, and you should absolutely *know* the difference. :)
Jon Skeet
+20  A: 

Not commenting unintuitive code. Not commenting unintuitive interfaces.

Disregarding coding style in interface code. (I am kind of used to seeing it ignored in code, but it creeps me out when even the interfaces other people have to use don't blend)

Inconsistency in naming, and ignorance of the value of consistent naming.

Ronny
Those are universal complaints. Not ignorance. Do you mean "Ignorance of the value of consistent names?" Or ignorance of the importance of "comments"?
S.Lott
Commenting intuitive code is almost as bad!
Draemon
I would say, the problem is not not commenting unintuitive code, but having unintuitive code itself.
DrJokepu
Don't comment bad code; rewrite it to be good code.
bignose
@DrJokepu - Unfortunately, that's a bit idealistic.
Jason Baker
@DrJokepu: You can't *always* avoid unintuitive code. Sometimes you have to do unintuitive things ...
SamB
+404  A: 

Mine is when programmers think only about the code and not about the users. I put usability first, and try my best to make everything as easy and intuitive to use as possible.

Unfortunately, some programmers don't do that; e.g., they use non-descriptive labels for fields (or, don't use labels at all), don't plan and think about the interface layout, and the error messages explain things in a technical manner rather than telling the user what they need to do.

If more programmers read books on usability, marketing, and other such concepts (like I do), the software world would be a much better place.

Click Upvote
That's why I always try to get a decent designer to look at my UI, preferably even make a mockup for me. Then I know my UI is done by a professional. I'm not a frontend developer, I develop the systems that make it work!
Erik van Brakel
I would double-upvote this is I could, because I feel like it's the reason for a vast majority of software failures - the people who write the code don't know/care about the actual purpose of the application and thing people will use it "just because it's cool". Wrong - it needs to solve a problem.
rwmnau
Well said. The end user doesn't give a damn about how clever the programmer is. The program just needs to make their life easier - not more complicated.
Damien
Check out http://www.whysoftwaresucks.com/ if you still haven't done that. :)
Arnis L.
I'm sorry, but I don't think that's the responsibility of the programmers... They're programmers... they have to think about the code... Why do you think all the development tools are getting better at "letting programmers and designers work together on the same project"? If you make the programmers responsible for the user interface, thats when you get those horrible user interfaces! Just don't do it. Hire a designer!
fretje
fretje, usability is not just about the GUI. Usability includes a lot of issues that the programmers are responsibile for such as performance. I once worked at a call center where the commerical application they used to field calls took sometimes as long as ten minutes to move from one screen to another. Do you think such bad performance isn't a problem for the user and wasn't the fault of the programmers (including database designers)? Also many projects don;t have separate interface designers.
HLGEM
I'd recommend buying a copy of "Don't Make Me Think" by Steve Krug for anyone on your team who doesn't think about usability. The $25 will save you a lot of headaches.
KOTJMF
@Arnis L. oh the irony. Showcasing a book about making software less sucky on a horridly unusable website. I'm not reading that.
Darko Z
If I'm developed backend code, I worry about the code. If I'm developing a UI, I worry about the UI. If they're overlapping, I worry about why these two haven't been separated.
Rushyo
The one that made me the angriest is Rhapsody- I don't want a damn playlist folder on every bit of removable media on my machine. It pisses me off when it is my flash-drive because I'm obsessive about my file structure and having it change things without my permission when there isn't even music on the drive makes me furious. The worst was when it discovered that I had linux on an SD card, it put a playlist in the root directory and somehow corrupted my whole install.
apocalypse9
@fretje - that's great when possible, but many programmers (like me) work on enterprise, internal stuff and don't get the help of a designer. I can't make everything beautiful, but I can think about what would make the user's life easier - which is really the whole point of coding anything.
Nathan Long
Marketing has nothing to do with usability. In fact, the world would be a better place if there was less marketing.
Lèse majesté
I agree with your point, but your arrogance is just astounding. The sentiment that *if more people did what I did, the world would be a better place* is beyond egotistical.
Hooray Im Helping
+351  A: 

Ignorance that other programmers may need to maintain your code.

I.e.:

  • Lack of decent method and variable names
  • Lack of comments
  • Moronic structure

Oh, people who think all abstractions are bad. You shouldn't use nHibernate, built in ASP.NET functionality and so on because you lose some control. Why don't they just code everything in assembly...

Edit: I should point out I am not saying that you must use these abstractions, just that there is nothing wrong with using them when it makes sense to (e.g. it's foolish to use nHibernate on a very simple site). It's a judgement call on when an abstraction makes sense, I just think some people are ignorant about the benefits it can bring.

Damien
I feel a compulsive need to keep clicking the up arrow on this post.
Mike Hofer
I'd be in the camp that says you don't need something like nHibernate.. it doesn't take that much more effort to do it with the built in assemblies, and you do have full control (and one less piece of external code to worry about 5 years later). Comparing it to coding in assembly is a huge stretch
John
I was using it as an Example, I guess you don't NEED it, but it helps. My point was basically 'avoid reinventing the wheel'. It is also very hand to treat data is such a way
Damien
@Mike Hofer just make sure you do it an odd number of times
Joe Philllips
Similar sentiment but I always said it as "You are not the last person who will see this code - what do you want THOSE people to think of you?"
David
For that matter, forgetting that _I_ may need to maintain that code. I can forget it pretty quickly, and when I do a bad job in the first place...
thursdaysgeek
Always code as if someone is constantly looking on your screen from behind your back.
Roalt
@Roalt - if someone was constantly looking on my screen from behind my back, I'd hope they wouldn't notice how much time I spend on StackOverflow... :P
BenAlabaster
@Roalt - I think that's perhaps a bit too much. I believe many people would not necessarily be able to concentrate on writing the best solutions. So, my suggestion: Always code as if Jon Skeet reviewed your code in the end of every day - and you couldn't go home until he's happy with the results.
Pukku
When I had summer interns working for me their first responsibility was to maintain last years' intern code. THAT got them thinking...
n8wrl
You don't write code for the computer to read, you write code for the next programmer to read.
Dave
Although in fairness, someone else's code, even if it's great, is always going to be less intuitive to you than your own code.
Nathan Long
I swear that once I wrote a code following some of the advice you can found here: ieng9.ucsd.edu/~cs30x/UnmaintainableCode.html/… I want that anyone other than me couldn't understand what's going on and I was pretty sure that I wouldn't touch that code anymore but a year later I had to slighty modify it, so I need to refactor code like this: ___=-_-__+_+__; too bad with vs it take only 5 minutes, so that article can't be trusted anymore :)
kentaromiura
Yes, yes. And the lack of appreciation that code will be maintained and changed to meet new requirements. I'm regularly making comments on SO in answer to 'how should I do this' questions that point out that you need to think of the best implementation that can be maintained such that it's easiest to update and liable to produce the lowest number of bugs when doing so. A few cycles exchanged now for being kind to your successors is well worth the effort.
Cruachan
Ditto on @Mike Hofer's comment!
Jim G.
+64  A: 

These aren't universal, but are very common:

Lack of knowledge (and interest) about what it takes to operate and support the software once delivered.

Failure to appreciate software has no value in and of itself, but only adds value when it is used for something.

Both of which lead to a lack of interest in what happens to the software once it's compiled, tested and released.

Paul
+1 to that. Was trying to say the same thing, but could not put it so eloquently. Having done both full-on coding, and full-on end-to-end release management, I know which one is the harder job.
toolkit
Yep. I've been a a developer for many years, and also spent several years in hosted infrastructure management so I've seen both sides. Moving to infrastructure management was an eye opener for me - and made me a better developer (I'm back that side of the fence now)
Paul
Wish this had more votes, but also realize the meaning will be lost on many.
Walt Gordon Jones
As an operations guy who has gradually grown development-related appendages over the years, this drives me absolutely _insane_. And I'm convinced that it has little to do with actual operations knowledge, and everything to do with good code: In my experience, hard-to-operate code is almost always a disaster area, and easy-to-operate code is almost always clean and elegant.
Nicholas Knight
+69  A: 

No one knows what the heck an MVC is. A lot of people think they know, but they're usually wrong.

Max
Too true, whenever I talk to other devs about MVC I have to check what definition of Model they are using as I have seen two distinct ones.
Quibblesome
where's a +2 button when you need one??
Javier
I'd love to meet this "Noone" guy that so many people say knows so much. Unfortunately, no one seems to know who he is.
Dour High Arch
@Dour High Arch - I literally laughed out loud! Thanks!
Jere.Jones
Pfffft. No one knows what an MVC is. It's an idea from the 80's that's been bastardized into a web framework. MVC is whatever you/your framework defines it to be.
David
"Most Valuable Coder" (don't kill me)
Bernard
IMO there's no such thing as an MVC web framework. The View is supposed to update in response to changes to the Model by the Controller. That's not possible when the HTTP protocol is completely stateless.
AFAICT, "MVC for Web" is M = DAL/schema/business-logic, V=Smarty template, C=form processor.
chaos
Isn't MVC on channel 271?
Dan
MVC tends to be a multi-layered mess and is often not a very good solution at all. It's a fairly good starting place if you can't figure out what else to do, but don't make it some all-important mantra.
Bill K
@Bill K - But I would argue that it's the best solution for ~90% of all web apps.
Jason Baker
I've seen plenty of code where it looked like a Motor Vehicle Collision took place. I didn't realize the analogy was common enough for the acronym to be widespread amongst programmers.
goldPseudo
@Dour High Arch: Noone is my homeboy.
Wayne Koorts
@Dan: I think that's the QVC.
Stefan Kendall
Isn't MVC a "Move Character" instruction from the IBM s/360 instruction set? (poor cousin of MVCL)
Adrian Pronk
@Bill K, I hope you are not confusing MVC (the pattern) with .NET MVC (a product)?
finnw
MVC is the slightly weaker version of PVC.
Joel Etherton
@user8134: Yes, the HTTP protocol is stateless, but your web application keeps state in some form, usually a database. If it didn't you'd be serving static HTML pages and wouldn't talk about an MVC.
André Caron
+12  A: 

The simpler, the better.

"Make everything as simple as possible, but no simpler." Of course, grandiose, over-architected, extensible-to-the-hilt designs are also ridiculous.
Rob
This answer practices what it preaches. ;)
Luke Dennis
"Only 4 lines of code!"
MPelletier
+7  A: 

In Java : thinking that "synchronized" blocks are only about atomicity when usually the problems are more about visibility

EDIT: Assuming I (Jon Skeet) understand you correctly, this is what I normally talk about as the difference between atomicity and volatility. And yes, it's misunderstood :(

Guillaume
Why comment when you can edit...
Splat
+150  A: 

Ignorance of Polymorphism.

Even in Python (with duck typing!) people still try to write

if type(x) == SomeClassIDefined:
    x.aMethod(arg1)
 elif type(x) == SomeOtherSubclassIDefined:
    x.otherMethod(arg1)
 else:
    x.yetAnother(arg1)

Where, clearly, they should simply rename the three methods to create polymorphic classes. They can eliminate the if and simply

x.renamedMethod(arg1)

Yesterday I saw the "surrogate type check" design pattern.

for arg1 in aBigList:
    if someOption == "x":
        result = someObject.aMethod( arg1 )
    elif someOption == "y":
        result = anotherObject.aMethod( arg1 )
    else:
        result = defaultObject.aMethod( arg1 )

Sigh.

At parameter-parsing main-program-startup time, they should have done this.

if someOption == "x":
    theWorkingObject= someObject
elif someOption == "y":
    theWorkingObject= anotherObject
else:
    theWorkingObject= defaultObject

Then, in the deeply-nested loop they could do this.

for arg1 in aBigList:
    result = theWorkingObject.aMethod( arg1 )

Simpler. Faster. Polymorphic. Pythonic.

S.Lott
Chris Dolan
@Chris Dolan: I left off the "else:" clause to shorten the post. The issue is the if-statements instead of polymorphic classes.
S.Lott
+1 - Thanks for showing examples.
Sean
Well, you really should use a factory to create theWorkingObject from the option's value. And Please, DON'T put the if/else in the factory. Have the working object classes register themselves with the factory at import time, giving the option value as a class attribute. Couldn't be more pythonic.
Ber
Is polymorphism always faster? In C++, it seems that walking the vtable to find the function pointer would amount to nearly the same thing as the if-tree you showed. I'm completely new to Python and I'm probably way off-base, but how can polymorphism avoid the lookup?
Matt J
Polymorphism is always faster. Measure it and see. The function-pointer lookup in C++ is resolved by the compiler with tables; not complex run-time if-statements.
S.Lott
+1 for the term "surrogate type check"And it's not about speed, but about using the tools at hand!
xtofl
+1, but this is more than pythonic. Having a prof to take points off for switch statements was one of the best things college did for my coding.
Chet
This applies to all OO languages really and not only Python.
Spoike
It's a shame in C# that you must actually check the type because it will not do ANY type inferring or anything fancy/nifty like that... Or implement an interface... who wants interfaces all over the place though for single functions?
Earlz
In C++ for example carefuly coded switch statement could be significantly faster than vcall. Why? Possible cache miss when accessing vtable or ability to inline (when functions are simple). However for any higher level language ignoring polymorphism doesn't make sense.
MaR
@Earlz: Polymorphism in C# works very well (just like C, Java, Python, etc.) What the h... are you talking about??
jpbochi
I love that the OP appears ignorant of other kinds of polymorphism and the only two comments to have been upvoted are completely wrong.
Jon Harrop
@Jon Harrop: "Ignorance of Polymorphism" seemed pretty inclusive to me. I'm sorry the example was not one of the "other kinds of polymorphism". Could you perhaps list some of those other kinds? Since I'm talking about people not knowing anything about polymorphism, I suppose numerous examples might be helpful.
S.Lott
@S Lott: I believe there are four major kinds of polymorphism. This post is specifically about subtype polymorphism (e.g. from OOP). Another major kind is parametric polymorphism from ML which is known as "generics" in the context of Java and C#/.NET. Implementations of parametric polymorphism differ and can be fast (e.g. C++, C#) or slow (e.g. Java, OCaml). Finally, the implication that jump tables are faster because they are O(1) compared to O(log n) for decision trees is wrong. Jump tables undermine branch prediction, making them significantly slower for n-way branches with small n (n<16).
Jon Harrop
@Jon Harrop: So you agree that ignorance of polymorphism **is** a pet peeve? Even if the other three kinds of polymorphism are not specifically mentioned? If you agree, what does the comment mean? That ignorance of *all* types of polymorphism is a pet peeve? Or ignorance of any one of them? I'm unclear on how much ignorance you're talking about.
S.Lott
+20  A: 

I agree on the byte<->character issue. There are even several issues in this:

  • "I want to store a byte[] in a String, how do I do that?"
  • "I want to store Chinese characters in a database, but only ever get <?>"
  • "I use UTF-8, but still only get <?>"

The last one is very unfortunate because it comes from half-knowledge. The usual reason for this is that while they use UTF-8 at one point they completely ignore all other places where the encoding would matter.

Joachim Sauer
The first one I want often, but because I want to use string libraries on known strings that are already in byte arrays (they're probably nondeclared UTF-8 but it's safer to treat it is ASCII-8 encoding.
Joshua
There are many ways of encoding arbitrary data in a string. Base64 comes to mind - is a little inefficient though.
Fowl
+616  A: 

The lack of desire to continually improve. I've seen a lot of developers get to a certain level of skill and then just stop learning new things. No reading of blogs, journals, books; it's like they reached a certain skill level and went "yep, I know all I need to know now"

MrWiggles
yeah cant understand it there is always more to learn
alexmac
I call them "career programmers", i.e. they are just doing it for a job rather than because they are interested in it. They might as well be accountants or something. Real programmers are always learning new stuff. It's not just a job - it's a lifestyle :)
U62
What if you know everything, like Jon Skeet? ;)
Coincoin
Then you write books..
Damien
I agree with the need/desire to learn thing, but this applies to everything and not just programming. But, there are also different levels of those people. Some learn more gradually and don't jump at every new thing.
Arthur Thomas
Totally agree with this point, and yet, there has to be a balance. There needs to be time to sleep, eat, spend time with family, and...what am I missing here? Oh yeah, finish writing the code you were paid to write in the last language :)
Bernard Dy
+1! I once was walking down the hall with someone who announced to a whole group of coworkers that he knew everything "important" about CS and had absolutely no interest in learning anything new, ever. It was a point of pride for him, actually.
Mark Brittingham
Hey guys, just to warn you. It does get more annoying to learn this complex stuff as you age. It can still be done, but don't be surprised if some day you hear yourself saying "Meh, I don't really have to deal with that yet..."
Bill K
Amen brother. It annoys the hell out of me when programmers are completely centered around their Job.
Rayne
Even Jon does not know everything. And that gives an opportunity for everyone to be better than him in those areas. Another reason to love IT. :)
Arnis L.
@ Bill: That's the day when you start being too old for the job. You'll age, together with your language of choice, until you're no longer needed, and be replaced by a younger developer - or someone who stayed on his toes and didn't stop moving. Which reminds me, I got to get back to that C# book, my leet C++ skills don't really cut it anymore...
DevSolar
I can't believe that a programmer thinks (s)he knows all (s)he needs!!Stackoverflow, Geeks.ms, geekswithblogs, visualmagazine.com, infoworld, javaworld, mvpms.com.... exist because people want to learn!
yelinna
One thing that *really* annoys me is when I hear "...but I don't have time to learn something new!" My response is usually "yes, but if you took the time to learn all the things you wanted to learn, how much more time would you have on your hands right now?"
Jason Baker
@Bill. Never, I'm 50 and constantly wishing I was 20 years younger because there's just *so* much new stuff to play with. Where am I going to find the time to learn Android, Erlang, CouchDB the Facebook API, Flex ........
Cruachan
@U62 Accountants have to familiarize themselves with new tax laws each year. I could think of way lazier professional jobs, like my old highschool chem teacher who used the same projector notes for 30 years.
darren
I also encounter young programmers accusing older programmers of "not wanting to learn anything new" because they haven't bothered to learn this year's fave new language. We, of course, know that it will be dead and gone by next year, and we won't have wasted valuable braincells on it.
DJClayworth
It is sad when a person fails to understand that change is the only constant in the known universe or understands and just gives up.
Rusty
U62, I have called them 9to5ers in the past. I think Hanselman has called them 501s before.
tyndall
It's pretty arrogant to look down on 'career' programmers' for 'only' working a regular day. Programming is _not_ special. A carpenter or an engineer or an architect are both making things and should be learning, but they can do it 9-5 and so can programmers. A pro sportsman is doing what they love but shouldn't be expected to practise in their free time, stepping away is a valuable thing.
John
@John: I'm not so sure about that. From my experience as an employee, most (but not all) shops consist of merely halfway decent developers and poor coding standards, where learning anything from 9-to-5 is virtually impossible because you aren't allowed to fix their code because they don't understand unit testing, S.O.L.I.D, AOP, Agile, OSS, dynamic proxies, etc... only procedural, highly coupled, bug ridden crappy code. As someone that enjoys creating excellent software under budget, I've *had* to learn everything outside of work to find a job that I love.
Charles
That's your bad luck really. The practicality that you _had_ to learn outside poor workplaces is a far cry from the generalisation that all developers _should_ do it.
John
+175  A: 

The biggest mistake I see new programmers make is trying to prove their code is correct when it obviously isn't. It usually runs like this:

  1. Programmer writes some code. It fails when run.

  2. He then spends several hours staring at his code convincing himself that it's correct.

  3. He asks for help and instead of accepting that it must be wrong, he focuses on why his code must be right and how 'something else' is causing the problem.

My advice: Assume someone else wrote that code and you know it's broken. Find the broken bit...

Denis Hennessy
'something else' is causing the problem -> This is the classic anecdote, " "select" Isn’t Broken" http://www.pragprog.com/the-pragmatic-programmer/extracts/tipshttp://lingpipe-blog.com/2007/06/27/select-isnt-broken-or-horses-not-zebras/
Anthony
Ego-less programming: http://www.codinghorror.com/blog/archives/000584.html
JesperE
Actually, in some cases this might work out pretty good. When you try to explain your code and why it is right to someone, you're forced to re-think every tiny bit while explaining it, and you'll often stumble upon your own error either by yourself or by a comment of the one listening.
Frans-Willem
@Frans-Willem: this has happened to me many times before. And not only with code. It's a good study method too.
Adriano Varoli Piazza
@Frans-Willem, Moranar: me too. too bad such a useful technique often makes you look stupid in front of your coworker though :)
rmeador
Great answer. I started off doing support and QA before I ever DEVELOPED (wrote new) code for a living, and the expierence of it helped me in my every day development. I *ALWAYS* assume my code is broke until I can prove otherwise. :)
LarryF
I worked with a guy years ago who, when shown that his code was broken exclaimed, "Oh no! It could not possibly be my code. I have tested it many times!" He couldn't provide said tests...
Terry Donaghe
In general I agree, but keep in mind that compiler bugs and chip errata do exist in the real world. When doing a lot of work with PICs it was quite common to run into compiler/silicon issues. Luckily Microchip and the compiler vendor where both very responsive and the bugs where fixed quickly.
Trent
Disagree - there's no better way to learn. The thing you learn best, that you never, ever forget, is the thing that you stared at for 2 days believing it must work. Especially when the actual error is plainly there, in the compiler error (sound of hand smacking the forehead).
Steve B.
You can stare at source code you've written yourself for hours and not see what it actually say instead of what you think it says. For some reasons the brain doesn't reparse anew :-S
Thorbjørn Ravn Andersen
Reminds me South Park where Kanye West started to believe he is a gay fish. Anyway - this is quite common problem.
Arnis L.
I think this is a normal human response. "Everything I instructed was so clear, how come you can't execute it? What's wrong with you?" :P I often do this myself, and a lot of my costudents as well. Obviously, it's selfdestructing behaviour as the chance for the computer doing it wrong is 1 to 100000000 or so. This is a mindset you need to let go off when you program, which will take some time if its in your nature.
cwap
I once had it pass a solid proof of correctness, so I looked at the disassembly. Nasty compiler bug.
Joshua
I spent far too much time today figuring out why find("WOBLYN") wasn't working, when "WOBYLN" was clearly in the data. Luckily I've been around the block enough times not to blame Microsoft's implementation of std::multimap. I've found compiler bugs before, but 99.99% of the time that's not it.
Mark Ransom
I once had a conversation with a junior programmer that went something like this. Me: Maybe you should have a second look at this bit of code, there seems to be an error in the logic because we are not getting the correct result from these inputs. Junior: I don't make logic errors, it must be something someone else did. In the end it was a simple logic error (AND vs OR type of thing) but the junior claimed it wasn't his fault because the specification wasn't clear enough. Any excuse will do in a pinch.
NealB
The compiler is seldom broken.
Mats Wiklander
@Joshua, compiler bugs do exist, but it is very few times that this is the cause of the problem at hand.
Thorbjørn Ravn Andersen
@Martin, no, the code is still the same as when written (by you). It just doesn't say what you think it does.
Thorbjørn Ravn Andersen
Oh man if I had a nickel for every time I run into this. Apparently no person writes bad code anymore. It's always the database's fault, or the network, or the coffee maker, or that ditzy blonde up on 9 who hit your car with her door this morning. If there is an error, the likelihood that YOU DID IT is off the chart.
Joel Etherton
Ha! I once had a problem connecting to an old Sybase DB from C#... I tried fixing it for *hours* (logging ODBC, low level debugging, etc.), until I figured that the ODBC driver could have been borked in RAM... So I restarted my machine, and guess what? The code worked as is.
Charles
+456  A: 

The attitude that testing is unnecessary or time consuming

If tests aren't written, then there is no way of knowing when some change in the system breaks something elsewhere. Writing tests saves time and money.

In response to Kendall Helmstetter Gelner's comments: testing actually helps refactoring - if you have tests that tell you what the application should do, then when you refactor, those tests should still pass. This is where I have saved many hours of work, after all, the alternative is no tests or doing manual testing for everything, and that is a massive time sink.

Mr. Matt
So true. So true.
JesperE
I agreed. Definitely true.
Danmaxis
Well, it is boring, but definitely not unnecessary.
Clayton
yeah, it's boring, but its necessary to do boring things sometimes.
Greg
This isn't just a problem for developers. This is a problem with software COMPANIES... The last place I worked for had a QA department of 2 whole guys. And the software suite was so large, that the virus scanner I worked on was just a very small part of the smallest module...
LarryF
I'm a big TDD advocate so don't get me wrong on this one. That there are no tests WRITTEN (in other words automated) doesn't mean that it has not been tested. Just as the fact that there are tests written doesn't guarantee that the right things has been tested.
Patrik Hägne
I left a career in software testing for a developer job simply because of this. Testing never gets the time, money, personnel, respect and recognition it deserves. It's always a battle, you're always the "bringer of bad news", and the better you are at your job, the more bad news you bring.
Marcus L
I don't have time not to test :) http://www.markhneedham.com/blog/2009/04/18/i-dont-have-time-not-to-test/
Chirantan
It's not boring. I enjoy seeing green progress bars. And incrementing count of green tests (if they aren't fail-proof of course) to me is something like collecting stamps to philatelist.
Arnis L.
You write tests to insure that all of an application is tested.But as an application grows, how do you insure that every combination and permutation of paths have been tested?You can't, you've simply moved the problem. Testing has its place but too many people rely far too heavily on testing and end up with a less flexible app as a result, since they have to change both code and tests some refactoring is deemed too expensive because of test drag.
Kendall Helmstetter Gelner
@Kendall You write tests to ensure that the app meets the requirements at a high level (integration / functional) and a low level (unit) - you dont test to make sure it's tested.'Test drag' only comes into it if you have written too much test code. If you get the balance right, then refactoring / adding functionality doesn't mean you have to change that much.
Mr. Matt
I agree that a "good" level of testing is valuable. But far too often when I hear words like yours, they come with the belief that there must be a test for everything, that a desirable goal is 100% coverage. That to me would be a most undesirable goal, for it would indicate a codebase that was utterly ossified and incapable of the simplest transformation beyond what it was.Again testing has it's place, but only as far as it helps the application thrive. Too many people place tests above the application.
Kendall Helmstetter Gelner
@Kendall I'm not an advocate of 100% coverage. That tends to be overkill in most cases, however, I'm not following you when you say that 100% coverage makes a system incapable of being changed.If a project is incapable of being changed, then I can only see that it is because it is badly designed or built rather than because the associated tests are covering everything.I don't think that 100% coverage is some sort of holy grail that needs be attained, rather a balance is needed, and both the tests and system software need to be built in a way that makes maintenance feasible.
Mr. Matt
If code has 100% coverage, especially for stricter types of coverage than line, then pretty much every change breaks at least one test. So you largely lose the protection the tests were supposed to provide against making bad changes with unintended consequences.
soru
A co-worker recently modified almost all business objects. Compiled, checked in. There were unit tests (created by another employee), but with the changes they didn't compile, so his solution was to just take the tests out.The tests would have taken about 5 minutes to modify. Anyway, when I went in with my application, things weren't working. It took me two hours to trace them back to those changes, and then 15 minutes to modify the unit test, find the problem and correct it.His excuse was that we don't have time for unit testing.... Re-read what I wrote above, then re-read the excuse.
MetalMikester
Performance testing is almost always useful. Functionality testing is a sign you haven't reasoned your program through properly. Edsger Dijkstra is very unhappy! :)
Joren
Yeah, but testing should be fun. Exactly like the Haskell Quickcheck stuff is. And because you always test properties, and not function behaviour, your tests are always valid.
Robert Massaioli
+6  A: 

I recently became aware that a lot (and I mean a LOT ) of programmers are not familiarised with the inheritance concept and have absolutely no idea why it is useful.

Sergio
Then again, some people are way too familiar with the concept and insist that everything be superclassed, or have an interface :P
Alex Fort
I agree more with Alex Fort. Inheritance is IMHO the easiest thing to understand in OOP, maybe even too easy.
Rene Saarsoo
Suggesting that everything should have an interface is way different than everything being subclassed. If everything is [somewhat decently] bound to an interface, there aren't many downsides--if the analogy of inheritance is overused, it often leads to a much, much worse design.
Marc Bollinger
I was shocked to see this on here the other day, too. Someone had to ask why they should ever use inheritance? They were of the claim that inheritance wasn't ever necessary!
Nolte Burke
An insufficient understanding of object-oriented principles leads to dodgier designs. There seem to be a good-sized group of people out there who know just enough to be dangerous, but not enough to grasp the wider picture.
Rob
"inheritance wasn't ever necessary!", it isn't, in the same way you don't need both objects and closures. You just have to do the thunking the complier does manually.
Pete Kirkham
Pete, if you follow that train of thought you will be able to conclude that we don't need computers because paper worked just fine ;)
Sergio
some serious thinkers also pretend that inheritance is dangerous. See there page 32 http://www.info.ucl.ac.be/~pvr/VanRoyChapter.pdf. Summary quote : "Instead of Inheritance we recommand to use composition Instead"
kriss
+3  A: 

With large datasets being moved between systems in XML, not understanding the merits of SAX over DOM, and the performance implications of selecting DOM simply because it is easier to implement. I have seen a number totally unnecesary performance bottlenecks and system failures over this, with XML getting blamed rather than the lazy parser implementation.

Shane MacLaughlin
I think you mean *non-lazy* parser implementation, when you should use is not unlike a *lazy* parser...
SamB
+113  A: 

I really don't like it when people are testing the value of a boolean like e.g.

if (isSomeCondition == true)

Not only is it redundant and unnecessarily verbose, but with a language like C# where there's no implicit conversion from e.g. int to bool it can actually lead to errors. In C# you cannot make the classic assignment instead of comparison mistake unless you're testing a bool, so

if (someInt = 0)

will not compile, but

if (isSomeCondition = true)

will (but will probably not yield the desired result). In other words for bools the explicit compare actually makes it easier to make mistakes. Please just use

if (isSomeCondition)

It is easier to read and at least in C# less prone to errors.

Brian Rasmussen
If you think that's bad, how about what I sometimes see: "bool foo = (somecondition) ? true : false;"
Anthony
In VB, I prefer this over the "If Not someFlag Then" style of coding. Its not a problem for me to read the ! in C#, but in vb's English language looking syntax it peeves me.
StingyJack
Actually if your flag is a boolean, you can name it isSomething, or canDoThis, or anythink like that. Then, it's far more natural to read if (isEnabled). The boolean nature is already in the variable name.
Think Before Coding
@StingyJack: I've also seenif (x == true) y = true;else y = false;Ye gods!
Dana
Hey, it's better than: if(true == x)... And yes, I have actually seen that in production code.
LarryF
My gosh I could rant for hours about the stupidity of the "constant on the left" mania...
DrJokepu
what about if(something == false) does that read better than if(!something). Like I know it's obvious, but the thinking is it reads better as you might skip over the !?That's what I'm currently debating. :)
rball
Booleans are so misunderstood...
Martinho Fernandes
@rball: I prefer if(isSomething == false) because someone new to the code may not see the not sign or may not know what it means. I tend to lean towards the "make it as painfully obvious what you are doing".
Nazadus
@Dana - I have to do that sometimes. In Flash a boolean can have 3 values (true, false, null). I find (x == true) or (x != false) useful as a way to coerce it into *just* true or false. Which I use depends on what I want the default to be if it's null.
Herms
@DrJokepu - Mania? I find it's a very useful pattern. Helps protect against a bunch of errors.
Herms
@DrJokepu and @Herms - Ditto. I'm all about constant on the left, as people NOT doing it has caused bugs which I've had to fix.
Daniel Huckstep
@Herms - it's madness like this that drove me slowly insane when programming in Flahs. Booleans with 3 values. What is the world coming to.
RJFalconer
if (true = x) generates a compile error. if (x = true) does not, and is probably not what you meant to type (you probably meant if (x == true)). constants go on the left otherwise you may accidentally assign something you didn't want and never know until the bug report comes in.
shufler
I find the reasoning behind not using `if (!something)` rather a lot of bunkum. If a person new to code cannot understand that, what hope have they got of understanding the rest of it?
James Morris
I have a coworker that insists on doing this because we also use VARIANT_BOOL with its VARIANT_FALSE and (different from "true") VARIANT_TRUE. It's annoying because you can write if(x) and if(!x) with either bool type and always get the right answer, even if someone screwed up and assigned the wrong type of boolean value previously.
Kaz Dragon
@Nazadus: If my coworker does not see the !-operator, than I must wonder what else he will not see and ask whether he's the right one for the job. Also, when the variable is properly named, reading something like _if(!red)_ or _if(not red)_ is much more natural than _if(red == false)_ . I don't force my coworker to become a template wizard, but those are freaking basics.
phresnel
@phresnel: It's far easier to recognize a if(some_bool == false) than it is to recognize if(!some_bool). The coworker I work with is known for blazing through things too fast. Also, we're debating on open sourcing our code so code readability is important. I'll agree if you verbally say "if not red" sounds better however I'd rather lower the chances of someone not seeing the not sign, especially if they don't pay close attention. I have no control over him -- I do, however, have control over the code.
Nazadus
@James: Not all developers know you can do if(!some_bool) much like many developers don't know what a ternary operator is. My opinions on code readability have been worked on in the past year since that post -- I've spent more time thinking about my reasoning on them.
Nazadus
@Nazadus: The unary not operator+"not"-keyword are a absolute basics in C and C++, as they are in every PL . If one doesn't understand such a simple operation, than one might also have problems understanding
phresnel
@phresnel: Let's start off with code readability at 3am. You're still partly sleepy. I argue the odds of missing if (!some_bool) is greater than if (some_bool == false). I don't recall saying they don't understand the not keyword and I don't see that in my comments so I'll let that end there.
Nazadus
@Nazadus: Are you sure those people are really developers and not... management?
James Morris
@James: Very sure. Sadly.
Nazadus
@Nazadus: Then you maybe want to _template<typename T> T div(T lhs, T rhs) { return lhs / rhs; }_ and then in the rest of your code _int main () { int x=div(84,2);_, so divisions are no longer confused with bitwise or's. Also, you haven't mentioned how your boolean logic looks in general, and I gave an example where your style clearly looses w.r.t. readability; I know we shouldn't decide for the one or the other extreme, but I really don't see the point of generating booleans out of other booleans, when simpler logic does the job already.
phresnel
@phresnel: Now you're taking things too far -- let's back up a little. You're example breaks our rules because it makes things more complex than they need to be. Readability is far more important than our standard... so if things get too hairy, we expect the developer to make a decision accordingly -- even if it violates our written standards. I argue that there is a difference in being concise and being clearly readable. If I'm in my right mind at 2pm, you're first example is just fine. If I'm just waking up at 3am, you're second example is better. 5 out of 6 people in the group preferred it.
Nazadus
@phresnel: We may just be weird, but that's how our minds work. This doesn't make your idea or my idea better or worse -- just different. We have customers who would lose more than $250k / hour they were down. So it gets *REALLY* important that you understand each others code at any given hour of the day. In that case, majority wins. Ternaries weren't allowed until the majority knew about them. Mot of the programmers were self taught (preferred over college students due to bad experiences) -- so they never were taught that. This was also straight C. Not C++ or C#. C.
Nazadus
True, and Microsoft VC++ compiler seems to encourage the opposite: http://stackoverflow.com/questions/1847860/why-is-there-a-performance-warning-on-cast-pointer-to-bool/
bobobobo
The person who decided to allow assignment during a conditional check should be shot.
Ian Boyd
@Ian Boyd Harsh, but probably true.
alex
@alex. You're right, of course. i would never shoot a programmer for a design decision. i would settle for an: "Yes, I see now how that has design decision has caused a lot of problems, and if I could do it over again I would have designed it differently."
Ian Boyd
I knew someone who writes `if (false == booleanExpr)`. It looks weird to me... Is there a good reason to write ifs that way?
Phil
@Phil: The reason for doing so is to avoid accidental assignment, as assignment will fail when the bool value is on the left. However, there's really no reason for the explicit boolean compare in the first place. `if (!booleanExpr)` says it all.
Brian Rasmussen
+275  A: 

It easily has to be that 'Commenting bad code is better than actually refactoring it into good code'

willcodejavaforfood
I admit that I will do this on some occasions because each change to a function requires user testing. If I see something bad or not good, I will put a comment with notes so that the when we have time, or the next time that function needs to be updated, it can be done in a more fitting fashion.
StingyJack
@willcodejavaforfood - I've come to believe that any comment is a smell. Code (in any language) should read like English.
ewalshe
@StingyJack - If you had an automated acceptance test suite you would not need to get users involved in testing. If changing something bad would endanger a cycle/iteration/sprint deadline I add a TODO comment. But, they have a tendency to be ignored. Too many TODO style comments is a smell.
ewalshe
Woah i am sooo finangling this into some catchphase, ha
Goosey
It's not *always* better, but it's quicker, cheaper and safer (it's 100% safe, and I don't think anyone has automatic tests that cover 100% of the possible input to their program).
MarkJ
@ewalshe : did you ever try cobol? :)
Mikeage
Sometimes it's necessary to write bad code; if you can't figure out a good way to do something within the deadline it's better to write bad code, get the behaviour specified and comment that it's bad code and how it works. You can always fix it later.
Adam Hawes
@Adam: so long as you realise that sometimes, later = never...
Steve Melnikoff
@Steve that works as long as you mark bad code explicitly and don't add anything on top of it.
Arnis L.
And what with the "If it ain't broke, don't fix it" principle?
fretje
@ewalshe: If code should read as English, comments should be footnotes.
Matchu
Sometimes I comment first so that I can understand well enough to refactor...
Kendall Helmstetter Gelner
@ewalshe: English-reading source only tells you *how*, but neither *what* (comments) nor *why* (documentation).
DevSolar
If I could give 2 votes on this....
chakrit
A lot of the time when I comment bad code, it's a drive-by; I'm in the middle of working on something else, and I've just deciphered what method XYZ does, and I know I'll forget by tomorrow if I don't comment it.
Kyralessa
People actually believe this?
Jeff Davis
This is called a Technical Debt. It's better to fill a ticket into the bug tracking tool (with what would be nice to refactor) than to leave comments that noone will ever read until they read the code.
Jérôme Radix
@Jerome: Nice idea, but when you've got code where the bug database has been lost (I've seen it happen due to the owner getting sold to another company and the code getting released as Open Source) then those comments are all you've got to work on.
Donal Fellows
+76  A: 
  • Programmers not trying to learn the difference of decimal and double

  • Commenting tautologies:

    i = 0; // set i to zero
    
    
    // loop column 80 times
    for(n = 0; n < 80; ++n) putchar(' ');
    

    instead of stating the intent:

    // scroll one line
    for(n = 0; n < 80; ++n) putchar(' ');
    
  • Programmers not knowing that conditions can be simplified(DeMorgan'd), e.g. coding multiple negatives:

    while (keypress != escape_key && keypress != alt_f4_key && keypress != ctrl_w_key)
    

    instead of the one easier to read:

    while (!(keypress == escape_key || keypress == alt_f4_key || keypress == ctrl_w_key))
    

    note: mentally read the construct while(!(...)) as until:

    until (keypress  == escape_key || keypress == alt_f4_key || keypress == ctrl_w_key)
    

    [EDIT: 2009-09-25] related to this question(simplifying the condition):

  • Naming negative variables, e.g. Unpaid, NotFound.

    Using this:

    • If Not Unpaid Then
    • If Not File.NotFound Then

    Instead of what can be easily understood:

    • If Paid Then
    • If File.Found Then
Michael Buen
Actually I would generally prefer the first case if working in something that didn't have until (i.e. C++), in Ruby I would use whatever sounded nicer. But your while example does not always sound/look nice to me.
Daemin
Same here. I'd argue that an extra set of parenthesis would hurt my eyes more, while reading the code.
Dan C.
During my college days, I just #define until to make for readable C/C++ programs.#define until(cond) while(!(cond))so i can use:until (keypress == escape_key || keypress == alt_f4_key || keypress == ctrl_w_key)Same for If, Then, ElseIf, Else, EndIf, etc#define Then ){#define Else }else{
Michael Buen
I've actually wanted a "until" keyword for years -- solely for the purposes of readability and clarity. I think it would make programmer intent much easier to determine.
chris
I concur, sometimes it's easy to express when things should stop, so you must use until. It's like when you have an itching need to put this code on loop header instead: if (keypress == escape_key || key_press == alt_f4_key || keypress == ctrl_w_key) break. Just need to put while(! (conditions) )
Michael Buen
I catch myself doing this on occasion, and I think to myself, "What the hell is wrong with me?" then I fix it @Naming negative variables, e.g. Unpaid, NotFound.
CrashCodes
I disagree with the third. In some languages it gets messy trying to initialize all your booleans to true.
Tim Matthews
Feeling tired at the moment and "* If Not Unpaid Then * If Not File.NotFound Then" blew my mind off literally.
Arnis L.
Thats why I find it such a dream to work in perl code... they have until constructs, and things like: doThis() until(finished());
Ape-inago
@Arnis: please learn what "literally" means.
DisgruntledGoat
Re: negative boolean variables, sometimes its good to name the variable by its default value. So if it's almost always unpaid, go ahead and name the variable UnPaid. But I agree that if possible, it's better to find a name that avoids the double negative, e.g. ReadOnly instead of NotEditable.
Martha
vote=vote+1; // Increment the variable known as vote by 1. ;-)
monojohnny
@Ctrl Alt D-1337: how about innocent until proven guilty? innocent should be initialize to true anyhow. but for this one, you could make a case to just use the guilty as the variable name, so it's easier to initialize it to false. but how could we phrase it? "not guilty while proven innocent", the emphasis on innocence is not as emphasized as it should be :-)
Michael Buen
"Naming negative variables": I cannot say I don't disagree with you.
tokland
+105  A: 

Thinking that it is OK to swallow an exception:

try {
  ...
}
catch (Exception e) {
  e.printStackTrace();
}

The default Eclipse template does this and so many people just catch a checked exception to get their code to compile and then ignore the ticking NPE.

edit: A post by Reinier reminded me of this one:

if (condition1) {
    if (condition2) {
        if (condition3) {
            if (!condition4) {
                if (condition5 || condition6) {
                    if (condition7) {
                        if (condition8) {
                            if (condition9) {
                                if (condition10) {
                                    // do something important
                                    ...
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
ewalshe
This is evil. People do it in so many languages. Failures aren't detected for days -- sometimes when it is too late to fix.
RussellH
God I agree whole-heartedly. I keep trying to convince the team I work with that swallowing exceptions and displaying message boxes is bad because you don't know when some other code is going to call yours and have no idea an exception occurred. I think they still don't get it.
Ben Daniel
I do this occasionally, usually without realizing it. It seems my brain puts the conditions together this way. Of course, once I've got it written out, I refactor it mercilessly.
TokenMacGuy
try{ ... } catch () { /*catching exceptions is for communists*/ }
Arnis L.
-1 for first (i disagree). +1 for 2nd (i agree)
Ian Boyd
Does anyone remember in Classic ASP: On Error Resume Next?
Gineer
Fortunately, VisualStudio allows you to break from execution for any thrown exception. At that point you get to see just how many people are eating unnecessary exceptions.
Pedro
10 Years ago I wrote exactly same code for job interview. After I wrote it and gave it I was like "why did I do that...". Of course I did not get hired...
THEn
Empty else blocks as well. Especially with the comment along the lines of: "we won't reach here."
Matthew
I have done this plenty of times before. For example, say we're sending off some logging messages. If there is potential for failure, you might not want some secondary "action X was performed" message to break a production app.
Jim B-G
ummmm... yeah. I think this would have trouble passing the crap4j metric tests. http://www.youtube.com/watch?v=bV6IhUh0IH4
cdburgess
**Never** catch an exception you don't know how to deal with *properly*, and try to avoid converting exceptions from one type to another (e.g., with causes in Java) as it is just confusing. Of course, sometimes you have to but when you do it you should feel dirty.
Donal Fellows
+84  A: 

Programmers carrying over habits which may be desirable in one language, but aren't in the new one.

Classic example is seeing C# or Java code like this:

if (5 == someValue)

This is usually written by ex-C or C++ developers who are trying to avoid the typo of:

if (someValue = 5)

which is valid C/C++ (although it generates a warning in most compilers). In C# and Java it's just unnecessary, and I believe most people find it harder to read than the more natural:

if (someValue == 5)
Jon Skeet
I don't really see the problem here. Mind you I'm a currently practicing c++ programmer who doesn't use that idiom, but it doesn't bother me either way.
Dan
True, in Java you cannot write 'if(obj = null)' . But you can write wrongly 'if(c = 1)', and I prefer to be consistent in the ordering of the constant versus the variable. However I admit you could catch such errors with findbugs / compiler warnings.
hstoerr
Yo know, I didn't know why people did this and I thought I was in the wrong. Psheesh.
Jonathan C Dickinson
@hstoerr: Try writing that in Java. It won't compile.
Jon Skeet
@hstoerr: The only case where it would make a difference is: "if (flag = true)" - which should be written as "if (flag)" (or "if (!flag)" for the reverse) anyway.
Jon Skeet
@Dan: The problem is that people are making code less readable for a reason which isn't applicable in their language. It's like limiting your variable names to single letters because you happened to use a language with that restriction in the past.
Jon Skeet
@Jon y should one use if (null == someReference) if ..if(someReference) should already work in c++
yesraaj
I think the first time I saw this practice spelled out as Good Practice was in Debugging Applications, or another of the more canonical Microsoft Press books. A whole generation of programmers (that couldn't deduce your argument for themselves) lead astray! ;)
Marc Bollinger
@rajKumar: Good point: I chose a bad example. Oops. Will edit - at which point earlier comments will seem foolish, of course. Ah well :(
Jon Skeet
P Daddy
I agree. I'd rather hunt down the bug, than read code written like that...
LarryF
Another example: C++ enums do not require to use enums like EnumName.EnumValue, it accepts simply EnumValue too, so it makes sense in C++ to have enum value names like EnumNameEnumValue, but in C# this is unnecessary. Still I very often see the following pattern in C#: EnumName.EnumNameEnumValue
DrJokepu
Personally, I don't find it any harder to read.
Bernard
I agree with @Bernard. I prefer the constant first, as it is more important than the variable name for understanding what is being checked.
Kristopher Johnson
I agree with Jon. i don't like it when people that previously programmed java think they should stuff everything into classes - even if all they have are static functions. they feel bad when they put them as free functions in a namespace - but that's the better way in C++!
Johannes Schaub - litb
@litb: Thanks for reading the first sentence - the rest of us have become somewhat distracted by the example, I suspect :)
Jon Skeet
In a weakly typed language, the constant before the var is excellent practice as if you do "if (foo = true)" instead of "if (foo == true)", the bug may not rear it's head for a while. Still I find my first inclination is to put variable first, I wonder why that is.
Dylan
Wanted to comment about distraction too. Well - i guess i did it anyway.
Arnis L.
I dislike this practice even in C++. If you have the willpower to consistently type "if (5 == x)" then you have the willpower to watch the equal-signs and write clear code. The latter is more valuable because it also protects against "if (y = x)".
James M.
This answer is really two pet peeves. The first is the "using practices from LanguageA that make things better in LanguageB that make things worse." The second is the claim that if (5 == x) is bad in Java/C#. I would suggest either adding examples of other things people bring from LanguageA to LanguageB that are bad, or making it clear that the pet peeve is explicitly "When if (5 == x) appears in Java/C#, as it's not really a safeguard as the issue in C/C++ that needs this workaround is not present in Java/C#".
shufler
there can be a reason to write the constant 1st in java, though not with ints. if someValue is null, the test 'if ("A".equals(someValue))' will return false, while the test 'if (someValue.equals("A")) will throw a null pointer.
Steve B.
Sure - but that doesn't count for my criterion of the reason not being desirable in the "new" language :)
Jon Skeet
Our VBScript code is littered with "Dim SomeArray(100) ... For i = 1 to 99 : SomeArray(i) = [stuff] : Next" type nonsense, because one of our programmers in incapable of learning how VBScript arrays are different than C arrays. Granted, the result is pretty benign - arrays just end up being 1 bigger than they need to be - but it's still annoying.
Martha
I always read it as 'testing if five equals something? is the value of five likely to fluctuate??'
matt
I agree. The focus should always be on the variable first, because that is the the cognitive association to interpret the meaning of the value compared to. Otherwise you have to mentally push the value onto your short term memory in your brain until you get to the point where you know what the value is compared to.Variable first is the normal way to express things in English, for instance "My name is X".Would you consider it to be an improvement if announcements at public transportation were changed from "The next stop is X" to "X is the next stop"?
hlovdal
Just don't make such typos and you won't need to use such a weird order.. :P
poke
Since I've read people call this Yoda programming style I'm fully enjoying it.
Sorin Comanescu
In Java writing `if ("hello".equals(world))` is a good way to avoid NPEs.
Shooshpanchick
@Shooshpanchick: So that doesn't come under the criteria of the first sentence - because for that specific case, it *is* desirable.
Jon Skeet
I think this applies to language design as well. The C# switch-break requirement for example. Why are we still putting breaks at the end of our switch blocks and yet implicit fall-through is a compiler error. Why? Because that is the way all other C style languages work.
Mark
+263  A: 

My personal pet peeve (petty but my teeth grind everytime I see it) is verbosely setting booleans, e.g.

bool isValid;
if (percentage >= 0 && percentage <= 100)
   isValid = true;
else
   isValid = false;

whats wrong with

bool isValid = percentage >= 0 && percentage <= 100;

It's soooooo much more succinct and easier on the eye

Binary Worrier
+1, good catch and thanks for telling us about this
Click Upvote
JPHP: I know you're taking the mick, but man I see this all the freaking time.
Binary Worrier
or bool isValid = percentage >= 0
agnieszka
i've seen better though: if(valid == true) return true; else return false; instead of return valid;
agnieszka
@agnieszka: I see you share my pain
Binary Worrier
Agree, but I also want to chime in that for whatever reason, I can't stand the '?' operator. Don't have a good reason.
GWLlosa
I think a lot of coders actually do not know that you can do this. I'll admit that it took me a while before my brain started to compute things like this in my head for me. I.e, I *THINK* in this notation now....
LarryF
+1, I wish more people thought this way!
Pat
Python 3 version:isValid = 0 <= percentage <= 100
Christopher Mahan
OMG this is GOLD! I will always be doing this now :)
Brock Woolf
lol, I sometimes catch myself doing this .... (but I quickly fix it!)
hasen j
I used to do succinct coding like this when I was taking my classes, and somehow, as soon as I got hired, I stopped. I need to start remember all the more better coding I used to in college! (and perhaps my grammer too) :P
Agent Worm
I disagree with this one. It's easier to place a breakpoint on one of these conditions so you can stop the program when the value comes out true. (yes, there are alternatives, but this is easier).I generally don't like complex lines and prefer to break them down.
Uri
-1, Uri has a good point. Besides, this is just a style issue, the compiler will do the real work of optimizing it.
jcollum
Most IDEs allow setting a breakpoint with a condition.
Pete Kirkham
@Uri: "I generally don't like complex lines and prefer to break them down" I actually agree, but I find it hard to imagine a universe where the above statement would be considered complex.
Binary Worrier
jcollum: Yes, it is just a style issue, no one has said anything about trying to optimize the code . . . unless it's optimizing it for human readability, and I think you'll find if you look at the compiler's output it will be harder to read, because thats not what a compiler is for :)
Binary Worrier
Just like to add one vote for Uri. I also generally prefer an explicit if statement over boolean expressions. Mainly for readability.But int this case I'd probably use the isValid = expr version, it's clear enough. If I would return a boolean I would use the if version though.
John Nilsson
At university I would get points retracts when I did it.
Roalt
Your university did you a disservice Roalt.
Erik Forbes
No problem with direct setting of booleans, but I like to add parentheses - I think it makes it more readable.
Mark Ransom
what about: bool x .... if (x == true) ...
JoelFan
Having the if-else you might 1) add more conditions easily, 2) explicitly set for each case what the result should be - specifications change!
Thorbjørn Ravn Andersen
@Thorbjorn "specifications change" - So does code. Change it when the specs change, not before.
Mark Brackett
I dislike unnecessary parentheses which spell out well-known orders-of-operations. This looks more succint and readable to me: bool isValid = percentage >= 0 Would you parenthesize every component of an arithmetic statement? What makes boolean statements any different?
Bryan Watts
@Bryan: I agree completely; @Ian, I rolled back your change, why not add your own personal "Programmer ignorance pet peeve" about folks that don't put parenthesis around all operations? Thanks.
Binary Worrier
-1 agree with Uri
Carlo
@Binary Worrier, even though the single line version isn't the most complex, different people read through code in different ways. A single expression can be easily parsed by people who have a math background or are experienced coders. That's not the point. The expanded version reads more like a sentence than a formula. It's easy to forget that there are plenty of coders without a background in math. It really comes back to the preferred style of the _READER_. Do they prefer reading expressions and formulae or something more like human speech.
Kelly French
@Kelly French: "A single expression can be easily parsed by people who have a math background or are experienced coders. That's not the point". I disagree, that very much is the point. Inexperienced coders will never become experienced coders if they're not exposed to more advanced concepts. Lowering the bar dumbs things down for all of us. People respond better to challenges than most people appreciate, I say raise the bar and we will all advance our skills and understanding :)
Binary Worrier
@agnieszka "`bool isValid = percentage >= 0 `", that has just the same problem as the original!
Wallacoloo
@wallacoloo: I think agnieszka is saying "better" as in "I can beat your bad code sample and give you *an even better* bad code sample"
Binary Worrier
@Binary Worrier: Oh, of course. I suppose the last part of the question (The most concise solution) must have been fresher in my mind, so I assumed he was replying to that.
Wallacoloo
how about `isValid = (0 <= percentact <= 100)` -- I love languages that let me do this
Carson Myers
@Binary Worrier: Sure, though this example is trivial taking your statement to it's logical conclusion gives us the grand results of the International C++ Obfuscation Contest. And that, I would gather we all agree, is just universally bad.
Chris Kaminski
@Chris Kaminski: The logical conclusion of your statement is that we must all plum the depths of every trivial statement we make until we get to a ridiculous extreme :) My "pet peeve" is to do with verbosely setting booleans, so no, I'm not suggesting we *munge* all of our code onto as few lines as possible, that - I agree - would be universally bad :)
Binary Worrier
One of the things with Java is that the Java version of IOCCC will never be as fun or interesting.
Thorbjørn Ravn Andersen
@Uri You said "I generally don't like complex lines and prefer to break them down", let's break the second example down into multiple lines: `bool isValid = percentage >= 0 ` `if (isValid) isValid = true; else isValid = false;` better?
configurator
@Roalt: "At university I would get points retracts when I did it." - that's why I never went to a University - because I wanted be *good* at what I do *and* save some money, all at the same time. (ironic, ain't it?)
Charles
@Charles. Your doctor, university educated? Or did learning as they went along make them "better" than than those *dopy* accredited doctors? I suppose a bit of trial and error never hurt anyone ... how's your appendix Charles?
Binary Worrier
@Binary Worrier: Do you really mean to imply that I do not have common sense? C'mon now, let's be rational. I *would* want my doctor to provide proove that he knows what he's doing. For medical doctors, we have degrees... but even then, that's not saying much; most just believe what they've been told, which isn't always true: saturated fat is bad for you, grains are good for you, etc. A degree ultimately shows that you're capable of attaining a degree. A portfolio of substantial OSS and non-OSS accomplishments shows that you can get valuable shit done as both an employee and software developer
Charles
@Charles: The Dutch university -at that time- didn't cost me that much money, and the experience I got there cannot be described by doing programming instead. I fully agree with the professor back then that setting boolean variables by using if's like above is "considered harmful" (quoting Dykstra).
Roalt
@Erik Forbes. the use of the "if" construction got yourself points retracted, not the elegant assignment way. I cannot see why the university failed on me there.
Roalt
@Roalt: I didn't mean to make a personal jab at you - I apologize if it came off that way. I meant to poke fun at the current state of higher education (Seth Godin shares many of my thoughts on the subject http://bit.ly/9F3XQS).
Charles
@Roalt - I misunderstood; I thought you meant that you got points off if you did it without the IF.
Erik Forbes
Binary Worrier
to the concept by a colleague 10 or more years ago. I keep saying I'll do an Open University degree, but life keeps getting in the way. Bottom line, an excellent developer will always be an excellent developer, an excellent developer + a proper education will be **astounding**.
Binary Worrier
@Binary Worrier: Point(s) taken. Actually, I'd like to take a course or two on compilers and language implementation patterns some time... I just wasn't having a good day when I wrote my initial comment. Too many developers started down their career path because they saw it as button pushing with a high pay rate, stick around for a couple years and then become "Senior Developers". I don't disapprove of getting a degree, but I do disapprove of the *reason* that most people get a degree.
Charles
@Charles: I hear you mate, and we all have days like those. Hope today is a better one. Enjoy :)
Binary Worrier
@Binary Worrier: It sure is :)! Cheers, mate.
Charles
+285  A: 

Complacency with duplicate code. Two blocks of code which are initially identical are a maintenance headache. They are going to gain differences over time due to being used differently, yet there will be cases where the same fix has to be applied to both similar but non-identical parts. You can try distinguishing after the fact between a fix that should have been applied to the other copy of the code but that was overlooked, and a fix that deliberately wasn't applied to both. It will make your head hurt.

I did code reviews of prospective hires a while back, and realised that the main bar that most applicants needed to get above was nothing fancy - not good Object Orientation, appropriate use of Design Patterns or the like, but just plain old factoring of code into well-named, re-usable methods. I.e. avoiding the "100s of lines of repetitive code in button click handler methods" pattern. This was discovered with "structured programming" in the early 1970s, before most of those applicants were born.

Anthony
A-MEN... But, there is a flip side to this too. People who write functions for EVERYTHING. Hate seeing a .cpp file full of 1 line functions... Geez..
LarryF
I had that situation *once* in a production code and thought it wouldn't matter because the method wasn't likely to change anyway and hard to refactor. Man, did I pay for that misconception. :-( Turns out, this single method took more time to maintain than all the rest.
Konrad Rudolph
+1. I used to wish that I could just disable all copy-paste functionality in the environments of some "seasoned" ex-colleagues of mine.
Pukku
On the other hand, trying to maintain a single block of code for two (or more!) clearly distinct purposes may end up being really bad as well: if (flag) { stuff... } else { otherStuff... } minimalAmountOfCommonStuff... if (!flag) { yetMoreStuff... } else if (flag2) { tooMuchStuff }
Pukku
Wish I could vote this up 4 times
Bill K
@LarryF Re. cpp file of 1 line functions. i have to disagree. The value of encapsulation is not directly correlated to the length of the functions.
Walt Gordon Jones
Every IDE should not have copy-paste. cut-paste is enough. And the funny part is I am not joking.
lispmachine
1-line functions are an extreme example, but I write 3-line functions every day.
finnw
Pukku: If a functions is full of "if (flag) { stuff... } else { otherStuff... } ", then it is probably doing too much. If it is split up, the problem goes away.
sleske
@sleske: Yep, I fully agree. My point was just that if the original routine is a long one, and it also requires substantial changes for the new purpose, then it *might* be better to just copy-paste and make the changes there, rather than take the path of flags. Of course, the *best* solution in almost any case would still involve splitting the long mess to smaller functions that only do one thing each. Then, it's really easy to reuse the stuff that both the old and the new function should have in common.
Pukku
@lispmachine: That's like saying no carpenter should have a hammer because it can be used as a weapon. I agree with the goal though; we just need to have Ctrl-V hooked up to an electric shock :)
Adam Neal
Guilty (sometimes).
Jeff Davis
True. But when battling with duplicates be aware of cost of introducing dependecies. (they can hurt even more!)
MaR
@lispmachine. I agree with the sentiment, but then bad programmers would just paste twice :)
MPelletier
If only this was the most upvoted answer! :( This is the SINGLE most important principle in IT, yet how many times and in how many ways violated!Remember: every time you duplicate any kind of information, you shoot yourself in the foot. With a cannon.@LarryF: if YAGNI, I agree. But short functions may serve also intentional programming, not just reuse.
thSoft
+26  A: 

Another Java/.NET one (this SO question is just great for letting off steam...)

Myth: "Value types live on the stack, reference types live on the heap"

Reality: It's more complicated than that.

C# doesn't actually differentiate between the heap/stack behaviour, and the CLR could potentially do funky things with objects which can never escape from the current method. However, taking existing C# behaviour and ignoring special cases like stackalloc and captured variables for anonymous functions and iterator blocks.

First let's talk about variables. Variables have a context - either they're local to a method, or they're static, or they're instance variables as part of either a value type or a reference type.

  • Static variables are always on the heap.
  • Local variables are always on the stack. (Remember I'm ignoring captured variables here :)
  • Instance variables live in the context of their container. For a reference type this will always be on the heap. For a value type it depends...
  • The value of a variable is never an object. If it's a reference type variable, the value of the variable is a reference. The reference may well be on the stack (e.g. if it's a local variable) but the object it refers to (if it's non-null) will be on the heap.
  • Value parameters are on the stack.
  • Reference parameters (i.e. those with ref/out) will vary by caller.

The value of the variable is stored wherever the variable conceptually lives. So an integer variable which is part of an object will always be on the heap (contrary to the myth). A variable which is part of a value type will live wherever that value type instance lives - which may be on the stack (e.g. if the containing instance is the value of a local variable) or on the heap (e.g. if the containing instance is the value of an instance variable in an object).

That's probably a very confusing explanation because I'm rushing to get to lunch, but basically the myth is far too simplistic, partly because it doesn't talk about variables (or more generally expressions) at all. The context is very important.

Jon Skeet
A couple of points of contention: Bullet 1 - static variables are in the program data segment, not on the heap. Bullet 4 - the value of a variable is indeed an object for value types.
P Daddy
I would simplify it to say that variables of value types hold the actual value, and variables of reference types hold a reference to the value, which is itself definitely on the heap (barring stackalloc). Where the variable *itself* lives is another question, but easier to answer...
P Daddy
... Local variables and function parameters are always on the stack. Member variables ("fields") are wherever the object they belong to is. Static variables are in the program data segment. For ref/out params, the parameter itself is on the stack and is a pointer to the variable, which is ...
P Daddy
... wherever it was in the caller. On the whole, though, I think that it's usually rather unimportant to remember whether a particular run of bits actually resides on the stack or on the heap. The difference between value and reference types is more basic than that...
P Daddy
Creating an instance to a reference type will *always* allocate space on the heap (again, ignoring stackalloc), and give one an indirect reference to its value. Creating an instance of a value type will not cause an extra heap allocation (in terms of individual objects on the heap), and ...
P Daddy
... give one the actual value itself.
P Daddy
@PDaddy: Program segment vs heap - are you talking about in .NET, or in native code? I'm not overly worried about that distinction, to be honest - the main thing is they're not on the heap. (I can't remember what terminology Richter uses in CLR via C# - will check that later.)
Jon Skeet
It sounds like we're mostly in agreement though :)
Jon Skeet
Okay, looked it up in CLR via C# - the static variables are part of the type object, which lives on the AppDomain loader heap.
Jon Skeet
.NET vs. native: Both. The compiler has to fix an offset for a variable in order for multiple independent functions to know where it is. Therefore its location must be in the program data segment. There terminology for this in the CLI is surely different, as the implementation is different ...
P Daddy
... Static variables in .NET are defined in the assembly in the "Field" metadata table, and the loader must allocate space for them when the assembly is loaded. But this is in a different place from the GC heap.
P Daddy
Sorry to hijack your post. This is just an issue that, as you say, is poorly understood by many developers. And as you admitted, you were rushing to lunch, and I think the result is not as enlightening as your usual stuff.
P Daddy
i like the "A variable which is part of a value type will live wherever that value type instance lives" part, because it's *exactly* in C++ that way :)
Johannes Schaub - litb
Why do you (again) say "in Java and C#" and then only showing examples of how C# can trip you up? Could you show an example of how this common misunderstanding has caused problems in java code as well, or not list Java in your title?
Bill K
@BillK: In Java people will still be tripped up if they either think that the *object* is copied (and therefore independent) or if they think that an *object* is passed by reference (and therefore assignments to the parameter variable are visible to the called).
Jon Skeet
Bill K
I actually had to correct a college professor about this once. He was trying to teach the class this exact misconception. When individual programmers follow this thinking, I'm not too bothered, but when a teacher who influences dozens to hundreds of students per year thinks this, it really bothers me.
Dan Herbert
A variable refers to an object. For a variable of value type, assignment affects the object, not the variable, whereas for a reference type, assignment affects the variable, not the object. Everything else follows from this.
Daniel Earwicker
@Earwicker: I think that's a bad way of explaining it. A variable has a *value*. The value is either a reference or a value type value. Assignment to a variable always just copies the value from the RHS to the LHS, whether that's a reference or a value type value.
Jon Skeet
I don't know if it would be good as a way of explaining it (e.g. to a beginner) or not, I was just trying to think of a description that mades the fewest assumptions possible about the representation, allowing the representation to be simpler if necessary (e.g. running on the JVM). The compiler could generate all types as reference types, and merely has to treat assignment differently for value types.
Daniel Earwicker
Just came across this old Eric Lippert post that makes the same point - http://blogs.msdn.com/ericlippert/archive/2009/05/04/the-stack-is-an-implementation-detail-part-two.aspx - "The relevant feature of value types is that they have the semantics of being copied by value".
Daniel Earwicker
It's tough to get the straight story from most resources. "CLR via C#" finally cleared this up for me (and I was trying to get clarity, just couldn't find it elsewhere!).
Stephen Swensen
+93  A: 

Performance isn't that much of a problem until performance becomes a problem. No matter how much you talk about premature optimisation people keep on doing it, at all kinds of level- there is nothing virtuous in writing 2000 lines of compiled code when you could have written 20 lines in a dynamic language just to save 20 processor cycles when your processor is running 95% idle anyway.

If the time comes when performance is a problem you can fix it then, but basing all your decisions on the assumption that it will be wastes everybody's time...

glenatron
I don't disagree with you, but I think it's good nature for developers to think in terms of performance oriented code. If it's UI code, or a cmdline util, not such a problem. But scaling should always be considered. It's never easy to go back and fix broken design months or years later...
LarryF
Good design is easy to fix when the problem arises- if it's clean and orthogonal then substituting in a new component/method/whatever to fix a performance bottleneck is relatively easy.
glenatron
Many of the performance problems I've found have been in UI code; scaling also applies if the data set you're visualising is big. The worst offenders are dynamic languages, where you face a massive jump if you want to get closer to the metal once algorithmic improvements are exhausted.
Pete Kirkham
Yeah, that's what MS said with Vista: Don't worry about performance, by the time we'll be done with this thing folks will have plenty of horsepower. While I'm not saying optimize every single line of code, more often than not this kind of attitude is what makes slow / bad software.
pbz
"when your processor is running 95% idle anyway" << I love that!
hasen j
This is a moving target, and you're best to at least be in the right ballpark. Perhaps line optimizing can wait, but architecture decisions need to be on spot.
Walt Gordon Jones
Operating systems are in a different ballpark entirely than most user code — MS got what they deserved for de-emphasizing performance. I agree with this answer, ESPECIALLY if the optimizations come at the expense of readability, productivity, etc. Scalable systems obviously require good design, nobody is disputing that; same story for libraries/frameworks/APIs. The problem is optimizing code where performance is a non-issue, but the programmer optimizes it anyway, "just because". There are better ways to spend that time... (Ironic, isn't it?)
Quinn Taylor
I agree with this as far as micro-optimisation goes. However, performance should be considered when designing your program. If the software is non-trivial and takes a considerable amount of effort it's no good getting it all working in Ruby and only then discovering that there is a fundamental performance problem that would require it to be re-written from scratch in C++ using a completely different algorithm.
Evgeny
It's an interesting point, though, Evgeny - if I got a prototype working in Ruby and found that there was a fundamental performance problem and I needed a different algorithm I would have saved a heck of a lot of time over if I'd used the same process in C++. Prototyping in a quick-to-write short-cycle like Ruby or Python is a great way of checking your design is conceptually sound.
glenatron
Premature optimization is a pure waste of time. However, it is wise to think about performance with every line of code you write, because a lot of performance gains come at almost no additional cost. Furthermore, performance tuning is very time consuming.
Dimitri C.
To me that is more a case of knowing the language you are working with- there are always little performance tweaks in any platform that only really come from knowing it, stuff like using StringBuilders rather than concatenating strings in C# or Java. In cases like that I'd say that it's our job as programmers to know enough about the platform to work in a performant way from the start, which is a little different from an optimisation.
glenatron
there is the issue of efficiency. especially in this day and age... anyone who doesn't do premature optimization is single handedly DESTROYING THE PLANET!!!
matt
I hate when people put down optimization because they're not good at it. Sure, a bunch of obscure bit twiddling all over the place make things unreadable, but there are lots of things one can do that don't impact readability at all, and you should learn to do them out of habit.
phkahler
As I say a couple of comments above, the things that you need to learn to do out of habit are _learning to program_ - I'm not suggesting you shouldn't know the details of working in a performant way with the language and platform you are using, that's just your job. When you have to go out of your way to optimise and you haven't checked that there is a bottleneck first, you're premature.
glenatron
Databases are extremely hard to refactor once they have millions of records and the designed-in performance issues arise. Anyone designing datbases who doesn't consider performance ahead of everything except data integrity is causing harm. Premature optimization doesn't mean don't ever consider performance. There are known performance killers and they should be avoided in the design phase.
HLGEM
I completely agree. As I said a couple of comments above, there is a difference between premature optimisation and just knowing how to do your job. However, you can make judgement calls- if a database performance optimisation was going to make it far harder to write code to work with that database and there is no evidence to suggest that it will be necessary in terms of the overall design, is that optimisation worth the increased cost in terms of developer cycles?
glenatron
+11  A: 

I call it "coding from the hip", but it really is a specific category - a better name may be "overimperative programming" or "structureless programming":

The code is structured as one or more function implementations (e.g. of the main function in a C program, or of a set of user interface event handlers in a .NET end user application). The code inside those functions was written line by line, by determining the next thing that needs to be done, writing a line of code to achieve that, and repeating this until done. When a case distinction needs to be made, an if statement is added, then, line by line, all the code for what happens if the condition holds, then the else clause is added, then the code for the then part is copied over and modified until it is the code for the else part. So complex condition checking appears as an arbitrarily large tree of nested ifs. Iterations were traditionally programmed by jumping back to some point with goto, then tweaking until everything seems to work, but Dijkstra's protest againt this has become too strong so now the tweaking is done with for and while loops. All iterations are programmed by explicitly creating arrays for the data to be used for each case, then filling the array using an integer index variable (without explicit numbers we lose track of where we are, don't we?) followed by another such loop to read and apply the data. More complex data are stored in multidimensional arrays or arrays of arrays and structs; other data structures are absent, pointers are a mahjor source of bugs, when used at all. All variables and arrays are treated like an assembly language writer's memory locations, so they are all global, have meaningless names, or incorrect ones due to being randomly repurposed. Correcting index bounds and array overflows are the programmer's main sources of debugging time. Rewriting and extension code is done by scanning for points at which a change or extension is required, then adding and copy-pasting statements and ifs in the usual way, then tweaking the result until it appears to work.

This is not always a result of ignorance: sometimes the programmer got so little time, or so incrementally, that there wasn't time to think about design, Nor is it always bad: if the resulting code is small enough, there may be nothing wrong with it.

The main danger of starting out programmers on a diet of assembler or C (or an similar subset of some other language) is that they fail to proceed beyond this stage. Most of the well-known programming improvements techniques (no goto, sensible naming, advanced data structures, structured programming, libraries with APIs, object-oriented programming, functional programming, layered architecture, patterns, refactoring, etc.) are attempts to help them do this, either by incremental fixing or by starting out in a radically different way.

I have not seen a better description of this "legacy code creation" technique. +1
rq
+52  A: 

Programmers who build XML using string concatenation.

Guilty of that one myself :(Hey! It was shared hosting with all sorts of goodies switched off.
philistyne
How else are you going to build it? :) Just kidding, just kidding...
LarryF
Start with an infinite lazy string and remove the characters you don't need.
Pete Kirkham
I'm maintaining a piece of software that constructs hundreds of megabytes of xml via string concat in memory in c#. Before I got there, it didn't use StringBuilders, either. Seemed awfully slow for some reason. At least I was able to modify it to stream the xml out to disk, now. Much faster.
Greg D
@Greg D: I hope you fixed it to use XmlWriter or another XML API. "XML is not String - note the difference in spelling" is a good motto.
John Saunders
I do that. Of course I don't intend to parse it with string.
Joshua
Why oh why can't we vote up a single post more than once?
Kibbee
+1! I'd add to that and say "Programmers who build Javascript, SQL, HTML, or any other 'plain-text' content" as well.
Jacob
+101  A: 

Treating coding standards as absolutes is my pet peeve. Coding standards are good things that improve readability, but there are always exceptions to the rule. The classic example is the "one return per function" rule. Sure, it's good to limit the number of returns in a function, but there are situations where multiple returns are preferable to contorting your code to use one return.

Jason Baker
agreed entirely.
Jonathan C Dickinson
I've said it before, but the "One return rule" is not a valid rule http://blogs.conchango.com/anthonysteele/archive/2008/07/14/a-method-should-have-only-one-return-statement-discuss.aspx
Anthony
I am a grave 'rule skeptic', and critically eye all 'rules' that pass under my nose...hammering most of them. I generally concur with Anthony Steele's view of the 'one return rule', although his 'multiple return' example raises issues all its own.
Dan
When you have a sequence of if statements, each with a dependent return, how do you know that multiple conditions do not evaluate true? Have you formally proved that they are mutually exclusive?
Dan
I would establish a set of booleans, each assigned from one of the evaluated conditions, followed by some logic to deal correctly with the implications of various permutations of results. Otherwise, your return value is based on the entirely arbitrary order in which the conditions were coded.
Dan
I think the 'one return' rule is a good "suggestion", but it's not law, or even a rule. I agree that hacking code to GET the one return is not always the best way.
LarryF
I used to believe in the 'one return rule', until my very first code review, and a senior developer took 5+ minutes deciphering my single if statement in front of me.
drhorrible
http://xkcd.com/292/
Donnie H
much like "taking coding standards as absulute" is a peeve... Spitting on coding standards because it does not always apply is just as worst... both are fringing fanaticism, truth lies somewhere in the middle.
Newtopian
I too used to believe in one return per function, but have abandoned it whole-heartedly.
Matthew Flaschen
This is often used as an excuse for refusing to remove bad rules from the coding standards. "It doesn't matter, they're only guidelines" etc.
finnw
"Have you formally proved that they are mutually exclusive?"Yes, when there are only two conditions.
Kendall Helmstetter Gelner
@Peter Mortensen - Just so you know: for loops, while loops, procedure calls, and if statements are also disguised gotos.
Jason Baker
The 'one return rule' is not a coding standard per se. It forms the very basis of Structured Programming: one entry, one exit (instead of gotos). Several returns are disguised gotos. This bad practice comes from the C programming culture and has been carried forward. There is always a way to cleanly use a single return at the end (if nothing else then by refactoring).
Peter Mortensen
@Jason Baker: Yes, but this is about composabilty, not about how the underlying hardware implements it. Control structures with one entry and one exit are much easier to understand than any other form, primarily because they can be used anywhere as a statement without disrupting the control flow.
Peter Mortensen
The "one entry, one exit" rule went down the drain when exceptions were invented. In the presence of exceptions, it makes absolutely no sense.
Gorpik
my favorite in this regard is the people who don't want to use goto so they come up with clever solutions using `break` instead.
erikkallen
One "next" per "for" was once a performance problem for me. Fortunately I was writing in assembler, so I went ahead with what I called a double ended loop. The loop "next" functionality was in both branches after a condition.
phkahler
+8  A: 

There's a couple of things. One is the same thing you pointed out - lack of proper understanding of Unicode, assuming that all text is represented by a lit of single-byte characters (as pointed out by the powers-that-be).

The other is developers who don't take the time to actually understand what something does or how the specs are defined, but just work simply by trial and error until they find something that works for their particular position and just use it. Then get surprised when it fails under different input (and often will go off and add convoluted if-else clauses, after more trial-and-error work of course, to handle all these anomalous data).

Oh, and as a corollary to the above - IE. There are so many elegant, powerful techniques that you have to abandon simply because of poor implementation in that browser - and when they do get fixed (it's getting better, I'll admit) you still can't use them for another few years until the majority of the public stops using the buggy versions. IE 8 looks like it will finally allow you to have a cookie string of more than 4k without effectively deleting all cookies - but how long until one can write code without having to guard against it?

Andrzej Doyle
The number of forum posts I've seen by people frustrated that their divs don't extend to the height of their containing block when they specify height:100%... "but it works in IE" they say. After explaining why IE is wrong I had ppl claim that the standard is wrong and should be changed to match IE.
U62
About your first statement... I present to you, the strlen function in PHP. Try print strlen('я') for instance, it will return 2. print strlen('我') will return 3. Why? Because it counts the number of bytes opposed to the number of characters. This can get REALLY annoying.
Erik van Brakel
@U62: that *might* be a reasonable proposal *if* it were possible to explain what IE actually did...
SamB
+27  A: 

My pet peeve around here is treating crashes as "user errors".

We work with quite complex data structures and GUIs, and sometimes users put in the data that triggers some edge case in the model, or uncovers a bug in the code. The program coredumps. Some of my co-workers simply tell the user not to do it any more - end of the problem.

In my opinion, every such case needs to be debugged, and the crash turned into an error message telling the user what's wrong and how to fix it. It's not the user fault if the model can't handle rates below 1% - the model needs to tell the user about its limitations.

Arkadiy
If possible, write a unit test that catches the bug. Such edge/special cases can indicate insufficient testing, so a good first step can be to see whether or not the corresponding unit test fails with that input.
Rob
According to the reference guide to a well-known OCR library: occasionally, depending on the input document, the library may appear to crash or hang indefinitely. This is perfectly normal.
Daniel Earwicker
+96  A: 

Mine is "bytes and characters are NOT the same thing, nor trivially convertible". I can't count how many times I've seen otherwise competent programmers completely ignore the issue of character encodings, misapply them horribly, or do multiple unnecessary and potentially destructive conversions between them.

The worst case I've seen, an overloaded method for handling XML (simplified):

public void setContent(String xml)
{
    SAXBuilder builder = new SAXBuilder();
    this document = builder.build(
        new InputSource(new StringReader(
        new String(xml.getBytes(), "UTF-8"))));
}

public void setContent(byte[] xml)
{
    this.setContent(new String(xml, "UTF-8"));;
}

Count the number of unnecessary and potentially destructive String/byte[] conversions. Count them!

Depending on the platform default encoding is par of the course for naive Java code, but corrupting the data unless it matches both the platform default encoding and a hardcoded one takes real talent - especially when it would have been less work to just hand the byte[] over to the XML parser and have it use the correct encoding declared in the XML data itself.

I blame it all on the C standard.

Michael Borgwardt
+1. Witness questions of "I've got a StreamReader with a jpeg image in..." No, you've got almost-certainly corrupted data at that point...
Jon Skeet
similar complaints here
dreftymac
back when I was learning C, i had it drilled into my head that 1 byte = 1 character.I was happy with this ignorance for years until I came to make a multilingual website. Wow that was an awakening.
Neil Aitken
In C, it's actually defined that way - hence blaming it on the C standard.
Michael Borgwardt
That's why I like the D language.
Brad Gilbert
The great thing is that Cocoa and .NET make it effortless to start using multi-byte encoding without many hassles at all since they were built for it.
Nick Bedford
Guilty.........
harpo
@Nick: Java also makes it effortless (well, effortless for Java) and has done for a very long time indeed, but some programmers insist on doing a lot of misplaced toil to *put the pain back in* (witness: the answer we're commenting on). Damn, but that's a stupid thing to do.
Donal Fellows
The mere concept of `char` is frightening, and `wchar_t` is an even bigger mistake. Depending on Unicode normalization and encoding, the character may be up to 6 bytes long (and the standard has room for extensions), so holding a character in a fixed-size piece of memory is an error in itself. God I long for a language with no characters and only strings. Oh wait, there's Python!
André Caron
+78  A: 

Many programmers think that writing unintelligible code that ultimately works somehow shows their genius. It's writing clear, understandable code that makes a good programmer.

A related issue are programmers who change old, unintelligible code without cleaning it up. Or not even really understanding what the old code does, as long as their new addition to it works.

Sebastian Dietz
"A related issue are programmers who change old, unintelligible code without cleaning it up"There's a logic to this, any code you change you will then be completely untested. Often, leaving badly written and complex code alone is the best course of action
weiran
@weiran: But if you don't know if your change affects the old code in any way, you can introduce errors just the same. You detect those errors better if the code is readable.
Sebastian Dietz
Bad code is difficult to "clean up" without subtly affecting what it does. Bad code also often has little to no documentation (specs). I find the safest way is to very carefully make your change with delicate incisions, touching as little code as possible (while keeping the code you do add to a higher standard, of course) and leave the rest alone.. Unless you have time for a **lot** of testing.
Blorgbeard
@Blorgbeard: If you are responsible for maintaining this code for several years into the future, it pays to clean up and test thoroughly. You cannot be sure that your delicate incision does not bring the house of cards tumbling down all around you, due to side effects. So you have to test the surrounding code even if you did not clean it up (making it harder to test). But you are right, changing anything in the vicinity of bad code is a risky operation.
Sebastian Dietz
I like to 'write code like GUIs'. If I can use my GUI with ease and I can understand my code with ease then I think I've done an alright job.
Nick Bedford
I believe the second one is called a "hack." It is sometimes necessary.
Jeff Davis
The last one is called "Programming by Coincidence".
Helper Method
+4  A: 

"It seems to work for me, so I won't bother reading manual/specification to do it correctly"

This is why HTML, JavaScript, feeds and HTTP (caching, MIME types) are in such sorry state.

porneL
i for one have better stuff to do than reading specifications the whole day. although i do spend half of my day reading specifications ... but at least my gf gets angry at me for it! and she's right!
nes1983
Careful what you wish for. The internet wouldn't exist if browsers refused to render invalid HTML.
Ian Boyd
porneL
+175  A: 

Ignorance of threading

(As applied to .NET/Java; different phases would apply in functional languages, for example.)

I believe developers go through up to 4 phases of threading knowledge:

  • Complete ignorance - ignore any possibility of problems. Result: race conditions, weirdness.
  • Over-reaction: make every member of every class lock/synchronize. Result: deadlock, code fluff.
  • Caution: reapproach the whole problem. Take a long time thinking over any threading issue. Get it right at least some of the time. Live in a state of fear when dealing with threads.
  • Nirvana: Instinctively do the right thing.

In my experience the last is more of a theoretical goal than an attainable state.

Jon Skeet
I love the wording "Live in a state of fear when dealing with threads" - so true.
Michael Borgwardt
and thinking you are Nirvana probably means Over-reaction?
Jonathan C Dickinson
This is why I would argue that performance reviews should be done after the project is finished. That way the over reactors don't get in the way of progress but their opinions are still valued and taken into account.
Karthik Hariharan
Or just use PLINQ and it is all automatic ;-) Does anyone else share my fear that PLINQ could wind up causing a lot more problems than it solves? People may start using it in web apps, monopolizing resources...
RussellH
"In my experience the last is more of a theoretical goal than an attainable state." -- What happened to FACTS such as Jon Skeet's experience doesn't include any unattainable states?
Windows programmer
"Jon Skeet's experience doesn't include any unattainable states?". It DOES.
Martinho Fernandes
Until futures and async blocks came along, that is...
Martijn
ops... missed sarcasm..... my bad
Harry
You left out the 5th stage: the is no Nirvana. Threading is fine in simple cases, but intractable in the worst case. I say this after years working on hardware concurrency (interrupts, etc) at the hardware level. Believing there is a Nirvana is exactly the kind of hubris that's gets you into trouble.
Walt Gordon Jones
I love this answer, it's so true. +1
DoctaJonez
I daresay I skipped the second stage. Deadlocks, sure. Not so much because of over-reaction though.
Thorarin
I once had a boss who stated "if it's too slow, I start making everything static". There are many things wrong with that statement. But, per threading, he would make instance variables static, which were then modified when another thread came along and tried to use the should-be-instance-but-am-static variable.
Matt
I would actually further divide phase 1 into 2 sub-phases: (1) **complete** ignorance, meaning: when a threading-related error actually occurs, the developer scratches his/her head and thinks, "Weird, what in the world could have caused that?"; and (2) ignorance of how threading actually works, which results in a tendency to label *any* mysterious problem a "threading issue."
Dan Tao
Very nice answer.
zedoo
Couldn't this be abstracted to just about every facet of a programmers education? Didn't we all go through the same four stages with arrays, recursion, static contructors? ok maybe I'm over simplifying but you get the idea.
Neil N
I think there may be a hideously overconfident state in there somewhere a bit further on than "complete ignorance" but before the sickening understanding of weak memory models really dawns. The point at which one naively thinks "Hah, this isn't nearly as hard as they said. I can write a lock-free algorithm..."
Weeble
+32  A: 

I'm surprised by how many professional programmers are weak in math. Growing up I just thought that being good at math was a prerequisite for the job. Everyone I knew who was interested in computers was also good at math, so I just made a mental connection without realizing it.

Bill the Lizard
I'm a professional programmer and I SUCK at math. I do Web programming though (ActionScript/JavaScript/Flex) which is pretty far removed from math. In the early days when programming was simpler there was a greater need for math than today. now it's more like problem-solving and logic.
nerdabilly
Wow, that's a good catch. I agree here, but one can make the arguement that you don't need good math to be a pro programmer, unless you are working in lower levels, say algorithm development, etc. But, it's a skill we ALL should be good at. After all computers *are* ALL math based.
LarryF
Only time I've ever needed math to program was when doing game programming. I always wanted to do that when little, hence I took a ton of math classes. Now I'm a web developer. I use math more now when I'm doing carpentry (mostly trig).
rball
The word refactor comes to mind. The concept of refactoring something is right out of algebra. Combining terms or redistributing to create a more easily solvable expression.
Bill
I SUCK at math. It's WHY I am a programmer. I get the machine to do the math for me.
Genericrich
I must disagree here. There is no rule that says your math skills must be excellent to be a proficient programmer (or even an excellent one). I'd say that a logical mind, a keenness for problem-solving and patience have been far more valuable for me than mathematics.
Dave R.
Math hones a logical mind and problem solving ability. There's nothing wrong with letting the machine do the computations for you, but if you truly suck at math, you probably can't even tell it the right computations to do.
Bill the Lizard
I'll second this one, and add that I can't stand people who are *proud* of sucking at math. Those people end up producing convoluted or plain stupid solutions to problems which would benefit from a little mathematical thinking.
Rob
Been programming for 5 years. The last time I used Calculus or Trig was in school. Math != GoodLogic. Sure math helps develop it, but it's not required.
jcollum
@jcollum: Logic is a branch of math, and you just needed to use it to try and declare that you don't need to use it.
Bill the Lizard
In 30 years of programming, I've needed very little math. But the last time was in a job interview - I've been told I can't code because I couldn't combine the properties of the integers with positional notation and permutations - all of which have been useless to me for 30 years.
John Saunders
Math =/= arithmetic. Being able to add sums in your head isn't as important as knowing what adding is all about. So i guess I question what being "weak in math" is all about.
Ape-inago
Math proficiency is required in certain fields. I never needed math but now that I work on search and machine learning I have been studying Linear Algebra, DifEq, etc... Most developers will never need most of it. But some of the most interesting problems are very mathematically based. You want answers that are only contained in academic papers. Personally working in a space like machine learning at high scale (1000s of computers) is one of the most interesting problem spaces available today.
Steve
Programming is both mathematical and verbal. Math comes into play when you are positioning UI elements on the screen (understanding the interplay between margins, padding, size, and alignment, for example, relies on at least a basic understanding of geometry). If you are doing anything non-trivial with 3D, trigonometry and vector mathematics becomes critical. If you are programming anything that calculates statistics, again, you need math. But you also need to name your variables and methods in a way that is clear to other programmers. So, verbal skills are critical as well.
DanM
I used to love math ... until it got really boring in high school. Though I did love the discrete math course at the university.
hasen j
I think we're confusing "math" with arithmetic here.
Jeff Davis
@Genericrich - No, you get the machine to do the *arithmetic* for you.
Scott Smith
You can be a competent, productive programmer without above-average math skills. This is not to say that you wouldn't likely be a significantly better programmer *with* solid math skills. A good mathematics background helps you understand problems at a higher level and see elegant solutions that you'd otherwise have missed. That's been my experience anyway; whenever I learn a little more math, I soon realize that I'd previously been doing something or other the hard way.
Scott Smith
I honestly don't see how a programmer can be bad at math: almost by definition, a math problem is solvable by programming skills, and reduced to an arithmetic formula, which can be computed with a computer (which I really expect a programmer to own).
Keand64
Disagree too. Most% (if not more) of developments that happen in "businesses" have nothing to do with math . Unless you are programming game engines or IA or some really complex simulations, i don't think you need any math
redben
I think being average at math is sufficient unless you are into game development... Only then is math really important
MikeAbyss
@MikeAbyss: Why only in game development? What about in developing encryption algorithms or missile guidance systems? Shouldn't those guys be good at math too? I'm not saying it's *essential* for all programmers, but it certainly won't hurt most of our careers.
Bill the Lizard
@redben: Even if all you're doing is writing CRUD apps, wouldn't a good foundation in set theory be beneficial? Also, all of the businesses I've worked for (in various industries, like instrumentation, automation and control, defense, robotics, and financial services) have had everything to do with math.
Bill the Lizard
Again, you don't need to be good at mental arithmetic to be a programmer, but maths is certainly part of it, if only because maths and programming use the same parts of the brain. (And logic and maths are pretty much the same thing.)
TRiG
I (with my maths degree) used to agree, until I worked with a much better developer than myself who was clueless at maths. Though there have been several times I've been asked, "Hey Tim - how do you swap the negativeness of an int again? What, really? Just a minus sign in front? Are you sure? Let me test that...", they've been far outweighed by the times I've asked for coding advice from him.
teedyay
+6  A: 

(.NET specific)

Myth: System.Decimal is a fixed-point type.

Reality: System.Decimal is a floating decimal point type, as opposed to System.Single/System.Double which are floating binary point types.

It didn't help that the MSDN documentation was wrong until .NET 2.0. Many people stood by the documentation, regardless of the fact that the exponent is clearly part of the value :(

Jon Skeet
Got that one wrong. In my defense, `Currency` in VB6 was an actual fixed-point type and all the upgrade documents claimed that `System.Decimal` was the equivalent of that (as opposed to the VB6 `Decimal` type that exists as well!
Konrad Rudolph
Yup - and SQL having a fixed-point DECIMAL type doesn't help either - that's even more confusing, as it's fixed in that the exponent isn't in the value, but it's parameterised by the exact type used in the declaration!
Jon Skeet
+8  A: 

In web development, ignorance of proper input sanitation and SQL injection vulnerabilities. In ColdFusion, for example, the language is so easy to learn that it practically welcomes new "programmers" to make this mistake. Much of the beginner documentation reinforced bad usage patterns early on as well. All of the languages that target web development have some kind of SQL injection prevention available, either through a sanitizer of a way to generate prepared statements, but many developers don't know what SQL injection is much less how to prevent it from happening. This leads to defaced sites, increased distribution of malware, and a general tarnishing of the image of web developers as second-class citizens in the programming community.

Justin Scott
+63  A: 

People who constantly rant about "Code should have more comments in it". If developers spent more time paying attention to sensible naming and a reasonable approach to problems, most comments would be unnecessary. If the code requires comments to explain it, then there is a good chance the code has been badly written.

Developers who concatenate loads of method calls inline eg:

int.Parse(MyMethod(GetValue1(someString, someInt).Property1.ToString(), Convert.ToInt32(GetValue1(someString, someInt).Property2), ((ObjectType)AnotherMethod()).PropertyValue).ToString());
Blatfrig
The app I'm working on at the moment has many comments of the "// Increment counter" type. Duh. What would be helpful would be an occasional statement about the intent of the code.
Andrew Kennan
Well said, +1. I think the second should be its own answer.
jcollum
In regards to your comment on comments(HA!). Some of this may stem from the fact that at my uni, your code gets a bad grade if it's not heavily commented. Most of the stuff is so simple that you can't NOT leave comments like "//Increment counter" for fear of a point reduction
prestomation
I don't usually see the inane comments, but I'd like to see more that say why you are doing it a certain way so I know if I should just rewrite your crap, or if you had a clue and I should search for meaning (Actually if you had a clue, your comment would have called out the meaning!)
Bill K
In school I was taught - One comment per line. That course came very close to killing my love of programming.
apocalypse9
@apocalpyse9 - I feel your pain. There is however one example when one comment per line is a good idea: when you're a beginner programming in assembly. :)
Joren
Code should have the right ammount of comments (and the right comment), but, frankly, I prefer a lot of comments over no comments at all, which is very common also
Khelben
"Increment I" is *never* acceptable. Nor is one comment per line. One comment per function ought to mandatory (I don't care how meaningful the name is). One comment per block is usually useful; comments might best describe not what the code does, but why it does it that way; and my personal favourites (even in self-maintained code) are along the lines of "don't be tempted to 'optimize' because...". They explain why a particular design or algorithm was chosen, or why another was tried and failed. Remember whom you write them for - those who much maintain the code
Mawg
+3  A: 

.NET != C++

Saw this yesterday: a programmer wrote some code in VB.NET which passed all parameters ByRef between a few dozen functions. I asked him why he wrote it in that style, and he commented that .NET would make a complete copy of every array parameter before it passed it to another function. I correct him, "yes, it'll make a copy... of the pointer, but not the entire array".

He fought with me on that fact for a few minutes. I decided it wasn't worth my time to "fix" code that wasn't broken, so I left it as is.

Juliet
That sounds like validation of http://stackoverflow.com/questions/423823/whats-your-favorite-programmer-ignorance-pet-peeve#423833
Jon Skeet
I like this one. :)
LarryF
Uh.. The answer, not the code style mentioned... heh..
LarryF
A: 

So many things are very common. For Example, "Do you know programming in assembler?"

  • Confusion between class and object.
  • Doubt about when use heap instead stack.
  • Problems with Scope.
  • To declare boolean variables and after do something this : if (x > 1) a = true else a = false.
  • Briliant phrases like "The language is not much important."

And so on.

Carlos Eduardo Olivieri
A: 

For Pete's sakes please don't use ALLCAPS for any form of constant in C#. Be it enums or const or ANYTHING. If your IDE doesn't tell if something is a const, you should find a new IDE, or failing that a new hobby/workplace/job.

Jonathan C Dickinson
What if your workplace has standards that force this? :)
Kevin Tighe
The same is true for C++ - the all caps notation is to warn you that you're doing a (potentially dangerous) macro expansion. using it for const objects makes macros stand out less.
Ferruccio
Why was this downvoted? Weird … shouldn't really be controversial, if only because of the saying “when in Rome …”: It's simply not C# style.
Konrad Rudolph
If your workspace enforces this you work for lunatics :). Reason it was downvoted? Probably because StackOverflow throws out a big net: they are bound to get a few boots.
Jonathan C Dickinson
Wow, I thought the all caps thing was pretty much universal. Go figure. I guess that's Java hubris :)
fluffels
I still use ALL_CAPS for constants and find it a useful readability aid. You shouldn't have to rely on tooltips in your IDE of choice imo.
Dave R.
@Dave, as long as you are not writing a public API I guess it is fine. In all other instances conform, conform, conform (you don't find ALL_CAPS in the .Net framework).
Jonathan C Dickinson
I kinda like it, but I guess to each his own. I really dislike this.classVariable when it's not necessary for the exact reason you posted (the editor should tell you), so I'm not going to completely disagree, but I'm still using caps for constants.
Bill K
Visual Studio doesn't tell me something is a const - that's why i ALL_CAP them.
Ian Boyd
@Ian - it does. Look at the intellisense icon for the field.
Jonathan C Dickinson
I could not agree more.
SLaks
A: 

That skilled programmers have a better value on business code than on technical code.

Affect your better coders to implement your domain model, they'll make it better, and that's the most important point.

Think Before Coding
+42  A: 

Quickly writing really bad code that works, with a plan to refactor later... when it's done e.g. 100 lines of a function that "i will break into 5 smaller later".

If you do that and then try to refactor after it's working, you usually find yourself in a situation when there are two ways: write it all again (because it's too hard to refactor to really nice code) or leave it this way because it's working... and in many cases it's just left in its crappy version.

agnieszka
if you have unit tests, refactoring becomes a lot easier!
Gregg Lind
I agree this shouldn't be done at work, but I usually do this when I'm coding for fun - quickly roll out new feature so it works and then worry about the elegance of code.
Lukas Stejskal
I only object to this if the developer doesn't actually get around to the refactoring in a timely manner. Granted, that probably describes 95% of developers out there...
Scott Smith
What about just moderately bad code?
harpo
I've lost count of the number of times I've been criticized by "experienced" programmers because I'm slow and meticulous instead of fast and sloppy. Apparently thought and attention to detail = lazy and unproductive. Who knew?
codeelegance
A coworker once quoted this... and now I do ;-) `"There is *nothing* more permanent than temporary"` - e.g. that code that someone says they are just going to add "temporarily" will live on forever.
scunliffe
+53  A: 

Inability to take pride in making mistakes. Instead of simply admitting them and moving on, people go to great lengths to cover their tracks.

Mistakes happen. If you meet a "senior something", then that means (before anything else) that this person has made a whole lot of mistakes and learned from them.

So a few years back, I made the hard decision to stand tall for my blunders and it has worked pretty well so far. When I can't find a bug after staring at the screen for more than an hour, I admit defeat and ask a colleague. This helps to avoid creating a bigger mess by "fixing" the bug by hiding it behind a new one.

"He who asks a question is a fool for five minutes. He who doesn't ask a question stays a fool." -- Old Chinese proverb

Aaron Digulla
Would upvote this more if I could!
Donnelle
+44  A: 

My pet peeve is developers who religiously attach to their language of choice.

As a practical matter, being a professional developer these days (in almost every space, not just web developers) should mean you are multi-lingual and capable/willing to explore other technologies. If you know your favorite language(s) well enough, you should also know where their limitations lay, and attempt to explore other options, instead of hammering a square peg into a round hole. A senior development position (or really, any development position) should come with the expectation that the developer can adapt and learn to fill the role as needed.

This is not just true of languages, but other technologies (app servers, frameworks, etc) as well.

Patrick Lee
Also true of methodologies.
Bill the Lizard
+1 Dogma is a pet peeve of mine in *all parts of life*. Dogma makes you intellectually lazy and inflexible.
jcollum
I disagree. I don't think there's anything wrong with developing a passion for a language; You need that to really understand it deeply.I think a far greater problem is people that attack other languages. That's what makes no sense to me, help people with a language you like and don't belittle people who use other languages you may not like.
Kendall Helmstetter Gelner
+2  A: 

Just one of the most symbolic examples of ignorance in programming (C#):

    private string GetMonth(int Number)
    {
        switch (Number)
        {
            case 1: return "January";
            case 2: return "February";
            //And so on...
            default: return "Invalid";
        }
    }
Carlos Eduardo Olivieri
wouldn't your compiler give you an error if you tried to return a string when it expected an int? I'm pretty sure this wouldn't actually compile
Brock Woolf
@Brock, this would compile. Although I see his point! Resource files (not in this case) and ToString() (which will piggy-back off of Windows Resources) are the best way forward.
Jonathan C Dickinson
I see a couple of issues here. One is "Number" should be lowercase per common naming conventions. Also, it should use a Dictionary<int, string> instead of a big switch block.
James M.
Er, this has GOT to be in the library!
SamB
I would never do it, but behind the veil of ignorance is a tiny gem of hope: this ought to be compiled into a jump table, and in that respect it isn't so different from an anonymous array of strings.
Jon Purdy
Of course, there is a library method, culture-dependant `CultureInfo.CurrentCulture.DateTimeFormat.GetMonth(monthNumber)`
dbkk
+49  A: 

Ignorance of socially acceptable bathing habits.

Nicholas
especially among the french ;-)
Mawg
+9  A: 

Happened recently: The problem can not possibly be in my code, it must be in the library!

pi
Also known as, "SELECT isn't broken" (http://www.pragprog.com/the-pragmatic-programmer/extracts/tips)
Rob
I ran into a problem recently where the documentation was misleading in terms of reloading as it pertains to mod_perl... it doesn't tell you right off that BOTH the source script and the module need to be reloaded, since the cached version of the source script still has references to old 'versions' of the module. IMHO, mod_perl ('s documentation) is broken.
Ape-inago
One of the rules I first learned was "assume your code is wrong, not the library". But over the years I have found so many problems in all sorts of libraries (heck I've found 2 bugs in IIS itself) that I've started considering both.
HeavyWave
@Ape-inago: I could have told you that based on my experience with reload() at the Python REPL :-)
SamB
The hubris-is-a-virtue thing doesn't make sense at all. Programmers should be humble when writing AND when debugging.
LarsH
+15  A: 

My pet peeve is code which is written to join a list/array of strings into a comma separated list and they loop round each item appending the comma (or other separater) and then when they get to the end remove the last separator when it can be easily done in a couple of lines (assuming c#).

        List<string> result = new List<string>();
        // do something if needed
        return string.Join(separator, result.ToArray());

:-)

WestDiscGolf
I think this can be expanded to any situation where someone writes lots of code due to lack of knowledge of built-in functions. Happens all the time in PHP (which is worse because using PHP code to do something is always slower than the equivalent built-in function).
DisgruntledGoat
Also, you don't need to manually remove the last comma. Instead, just add a comma before every element except the first.
Brian
i wouldn't be too hard on developers. The library of functions available in environment **X** is quite enormous.
Ian Boyd
This function is oddly enough not natively available in Java, however the Guava library has a very clean implementation of Joiner.
BjornS
+5  A: 
  1. copy and pasting code
  2. copy and pasting PHP code that prints static HTML

and the infamous:


total++;            // Increment the total.
+176  A: 

Female programmers can't code?

Another peeve of mine comes from the attitude people have toward female programmers, which include among other things:

  • "Programming is too hard for women, since they're obviously emotional rather than logical thinkers"
  • "The best female programmer is never better than an average male programmer"
  • "Women programmers can't be pretty"
  • "Women only choose to be programmers because they are in need of a husband"
  • etc, etc, etc

One of the women on my team is a tech lead, and she commented to me the other day interviewing potential employees. Normally, she and one of the male leads would interview candidates together. Consistently, interviewes would speak in very technical terms to the male lead, and dumb it down when they spoke to her. One candidate managed to describe a weird scenario that caused a stackoverflow exception to the male lead, and reiterate it back to her as "a stack overflow is kinda like filling a balloon with too much air, eventually fills up and finally goes POP!"

I don't know if people have had bad experiences in the past, but I've never seen a perceivable difference in coding style or quality programmers between men and women programmers.

Juliet
I've been programming for over 20 years, and though I've usually been in the minority, it's not a large difference in numbers, and I've NEVER felt discriminated against for being female, and have often been recognized as the best. Maybe because I'm not pretty.
CindyH
I've known some very sharp female programmers. All of them attractive, and would be a dream come true for a guy like me. It's just too bad there aren't more female programmers out there. Maybe you see this because most women can't be nerds. Nerds are usually ugly, and most women just aren't ugly.
LarryF
And I say that with the upmost respect, and as light-hearted as can be said. :)
LarryF
i must say i love to be like the raisin in the cake: the only woman in the department :) i was well prepared for being discriminated as a woman in the company but was very surprised to be treated equally and even get quite a respect among my colleagues.
agnieszka
sadly the people who didn't think of female programmers as equal to male, where the young open-minded friends at the university rather than a bit older people at work. i always thought it would the other way round.
agnieszka
Can't drive either... joking :-D
icelava
My female colleagues look simply like... regular people you meet on the streets. I see no reason sure why they should be uglier or more beautiful simply because of the IT industry.
icelava
I've found that one can be treated more or less with respect, but there's an element of having to work a little harder to "prove yourself" and gain that respect. Case in point, there was a common assumption by peers at my new job that I was a business analyst rather than a developer.
MandyK
Sadly, not just limited to programming.
fluffels
Being a minority in any situation can be tough, the only solution is to be true to yourself and never allow people to place you in a box. I don't what female programmers go through, I've only met two who really cared for it. One of which was incredibly talented.
Bernard
I know 1 female in programming. She can't code so she ended up becoming full time support even though she studied programming.
Tim Matthews
In my experience, the women in programming are some of the BEST programmers. Probably because of the unfortunate peer pressure, etc, only the really good ones stick around....
Brian Postow
You mean the legends are true? Female programmers actually exist?! I'm more than slightly aroused! lol jk
Ben Daniel
I have to know, did the candidate with the stack overflow get the job?
@Dan: I asked the same question, and all I got as a reply was cackling laughter. I'll leave it as an exercise for the reader to derive the underlying meaning from that response.
Juliet
This always annoyed me. In my university course there are exceptionally good and exceptionally bad programmers from both genders. I had great fun team-working with a woman for functional programming coursework, she was easily as good as I am (despite mostly being a Maths student)
Benjamin Confino
I feel blessed to have always worked on mixed-gender development teams. Not least because I rarely run into attitudes that lousy.
abeger
Like Brian said, the female programmers I know kick serious ass. The main difference I've noticed between male and female programmers is that there are far more bad male programmers around. It's like only the top 20% women actually become programmers in the first place.
jalf
Although there are fantastic female programmers and I'd love to see more, someday examine how many females are cooks and how many are chefs... It actually has to do with a male limitation... The need to obsess endless over an art with all his mind and soul. Fewer women seem to obsess like that.
Bill K
I've yet to meet a good female programmer. I've yet to even meet a female programmer at all. There just aren't very many in this industry. There's a lot of reasons I guess, but this post nails one reason.
Adam Hawes
I had a female boss at work, she is brilliant and very sharp (Razer sharp!) BUT she would always be paranoid about being treated inferior and her overreactions would be WW2. Sadly I couldn't stay in the company due to this problem
Harry
@Adam - What is the point in saying "yet to meet a good female programmer" and then say "yet to meet a female programmer at all" I think you should be checking for NULL first!
Harry
@BillK I know a lot of women who obsess like that when it's time to leave the house, whereas I just throw on whatever's around, drag a comb through my hair, and go.
Mark Cidade
I have known 2 female programmers, 1 VERY good and the other may have been good, until she decided not to learn anymore... about 10 years ago... unfortunately she also needs an attitude re-alignment (assumes she is a programming god when in fact just knows the product/business rules very well) and makes even a simple hello sound like a declaration of war...
geocoin
My experience has been that male programmers tend to be deeper thinkers about problems, abstracting to higher and higher levels, while the female programmers just want to solve the problem and go on to the next one. If I'm not doing anything bleeding edge, I prefer the women's approach.
Boofus McGoofus
"Women programmers can't be pretty" - I think similar stereotypes exist for male programmers too.
Jason Baker
Shit. I'm guilty of this :p But c'mon, I'm sure statistics show that most programmers are male. That isn't to say female programmers don't exist, and they can't be pretty.... they just exist in small numbers. With regards to intelligence... well, if the female makes it far enough to become a programmer, then I wouldn't question her intelligence at all.
Mark
My sister-in-law does some Java with her job, and when she sent some code she had written to a coworker who lives in Europe, he replied back thanking for the code, and commented that he must have been confused, he thought she was a woman.
Matt Poush
Some nerdy dudes don't know how to act properly when faced with a real woman
Alex Baranosky
I didn't know they existed :P Seriously though, I've yet to encounter a female programmer in my work environment. There were a two (2) female students in my year class at university at the time. Unfortunately they did nothing to debunk this statement. I know one girl that's decent at PHP, so I try to be open minded ;)
Thorarin
+1 I was talking to some Firefox developers at an Open Source Con. They used simple language at first, but as I kept using "big" words they eventually did too. You'd think, since it was a software convention they'd default to nerd speak, but no they didn't.
Elizabeth Buckwalter
Very broad generalizations here, and I am frankly skeptical that the quotes given by the OP were actually said, unless she works a Congressman.
Jim In Texas
At my college, nearly all female programmers (and engineers from any other discipline) were grossly incompetent. I think this is because the entrance standards for the school were very much lower for women than men, since they wanted to attract more women to the school (it was 75% male). Also, due to that gender disparity, the women were able to skate through classes by getting the men to do their work for them. I only met 1 good female programmer there. Of course the women got job offers a lot faster than the men. Affirmative action harms the very people it's trying to protect.
rmeador
There is an equally good chance that the interview candidate was simplifying the solution for the "team lead" rather than just for the "woman in the room." The assumption that the team lead is not a programmer is often a fair one.
Tom Leys
@Jim I've heard a couple of these quotes. My husband is a Perl and .Net developer and Linux guru. I know a lot more about web development. You know who people ask? Him. Why? You tell me.
Elizabeth Buckwalter
I've noticed this too (even in my own attitudes). I think the root of the issue is that nearly all programmers (regardless of gender) are crappy. Only a small select few are actually really good. If you rarely meet *any* female programmers, your odds of ever bumping into a good one are fairly slim. Under those circumstances, you can sort of understand how some folks could get to thinking that they don't exist at all.
T.E.D.
There is this cultural archetype of women programmers aren't programmers at all. I think this is rather ironic considering the first programmer was a woman (see: Ada Lovelace), and she was so hardcore that she wrote code to a machine that was never completed! The only thing that would make her even more hardcore is if she changed her family name from the wimpy Lovelace to the coolness of Skeet. On another note, I've meet a female programmer and she was pretty much awesome. Her competency and ingenuity was way above par in the team at the time.
Spoike
it can sometimes be a chicken and egg problem ... i've been on an all-male team and when I queried about this situation, I found out that the team had in fact tried to hire female programmers , but when the women found out about the current composition of the team, they decided against accepting the offer. So the team decided to just hire the best programmers they could find and if it was a female, so be it!
Thimmayya
Whenever I've been in a development team those headed by a women have almost always been far better places to work than headed by a man and indeed after a few experiences I used to seek them out if possible. The only exception was one headed by a women with bigger virtual cojones than the rest of the company but together and shoulder pads so wide she would have taken off if she'd have run too fast. That was hell.
Cruachan
That's quite interesting. I never actually met one, but would be happy if there was.
Jeff Davis
I think this perceived disparity exists because guys tend to be more vocal and fanatical about their geek-love (be it fast cars, computer hardware, software languages, frameworks etc). Their opinions are louder, more aggressive and come across more passionately. This doesn't mean they're any more correct, they just believe they are more correct. P.S. Though as a guy I do find only women make generalisations. P.P.S That first ps was a joke. P.P.P.S I'm still giggling over "geek-love"
Binary Worrier
http://xkcd.com/385/ sums it up nicely.
DaveC
this will probably get me in trouble so i thought better and did ctrl-z.
Frederic Daoud
I am a female developer, pretty and awesome. And have loads of confidence. :P
sarahTheButterFly
the geeks who speak simple to female programmers often dont interact with any females other than their own mother - hence its a force of habit. An anectode - trying to fill a position once I interviewed 50+ candidates. Only one woman applied and she got the job because all the other candidates were crap. Women can be good programmers and bad programmers just like any other human being. I'm just sad that this kind of discrimination happens and that our field is not more gender diverse.
Darko Z
+15  A: 

Not to comment code.

Seriously, a whole lot of colleagues stated to me, that "hard to write code should be hard to read", when I asked them, why they do not add comments.

I say: "Documentation is like sex. If it's good, it's very, very good. If it's bad, it's better than nothing!"

bitschnau
Of course, code that was "hard to write" should be as simple to read as possible, because it makes it easier for others to tell whether all that "difficult" code is correct.
Rob
I disagree. Outdated, incorrect comments are worse than no comments.
Hank
Sure, sex with an outdated, incorrect can... ah, let's forget about it. ;-)
bitschnau
It's always been true. Those who write the best code write good comments. In both, they are efficient.
Walt Gordon Jones
comments violate DRY - http://memeagora.blogspot.com/2008/11/comments-code-smell.html There are still places where useful, but few and far between in modern languages.
Maslow
The analogy is good though.
Jeff Davis
Comments don't necessarily violate DRY. Comments should explain why and what while the code should explain how. A comment saying "increment by one" is pointless and annoying, but that doesn't mean that all comments are repeats from the code. They aren't.
Sylverdrag
+7  A: 

In order of gravity:

  1. mindless code duplication, takes first place anytime
  2. badly written logic that contains so many holes it's like Swiss cheese
  3. unnecessary complexity
  4. no comments, or bad ones, making less sense than the code you're trying to understand
FredV
+3  A: 

Code is not just for communicating with the computer, but also with fellow programmers.

You can throw all sorts of rules on comments and variable names at people, but it really doesn't matter that much. Either they grok the above (and don't need rules except perhaps as guidelines) or they don't (and will only obey the letter of the rules).

David Thornley
Optimistic, are we? [re: "grok the above"]
SamB
@SamB: You bet.
David Thornley
+123  A: 

Arrogance.

Stevan Rose
This industry is second only to Wall Street in this regard.
John MacIntyre
Ignorance ("I know everything") or arrogance ("I am the best") alone is curable through experience. The combination is incurable.
Dour High Arch
The combination is also more common. :(
Rob
Well, failure is a good cure for both
bobobobo
On the other hand, this is one of the three virtues of a programmer, acording to Larry Wall.
Gorpik
Except where arrogance leads us to believe we're great, which in turn leads us to improve or stay great. Arrogance and motivation go hand in hand.
tsilb
@tsilb - I think your confusing confidence with arrogence: an arrogent person has no desire to improve.
Keand64
I love how the guys I work with think what they do is akin to rocket science. Arrogance = cowardice and fear in my eyes.
DJTripleThreat
@Gorpik No it's not, the three are: Laziness, Impatience and Hubris http://c2.com/cgi/wiki?LazinessImpatienceHubris
epatel
@epatel: I know, but arrogance and hubris are more or less the same.
Gorpik
@Gorpik The thing is that if you read what Wall meant it's more about making sure you create good stuff so people can't criticize you. I interpret arrogance as you don't care what people say because you believe you are the best.
epatel
@epatel: In my dictionary, hubris is "overbearing pride or presumption", while arrogance is "overbearing pride evidenced by a superior manner toward inferiors". I understand that Wall is a linguist, so he chose the exact word for his (ironic) sentence; but the meanings are very similar.
Gorpik
+8  A: 

People that think it is OK to not comment code because of reason X.

I have heard all kinds of pithy statements like "Comments are lies", "Write more readable code instead of commenting", or "Name your variables and functions correctly and you don't need to comment". Bull hockey! Writing readable code, and using good naming of functions and variables are good ideas. But leaving out comments is not.

I don't know how many times I have had to examine a block of code for minutes/hours trying to figure out what it does and why it does it, when a simple comment would saved me most of my time.

In C#/.NET, I hate the lack of metadata comments on functions and properties. Being able to bring up IntelliSense and find a short set of comments about a function is invaluable to your fellow programmers.

Of course I am guilty of not adequately commenting code throughout my career. I probably wrote some code yesterday that I didn't comment. But the attitude that this is OK for some reason X is completely wrong.

P.S.

I also hate the other school of thought, the "Leave detailed comments on everything" camp. I had a couple of computer science professors like this back in the days of college. If the line count of comments in a function equals that of the code, you have a problem.

Jason Jackson
I think this is what you mean by "C# metadata comments" http://msdn.microsoft.com/en-us/library/z04awywx.aspx
chakrit
This would have been my pet peeve too. I'm sick and tired of programmers saying "the code should speak for itself", which is veiled arrogance (i.e. if you can't understand this code, you aren't worthy to work on it). Suitable comments are vital in any project, whether it's assembler or Visual Basic.
Dave R.
@chakrit: right. I say metadata since these comments are compiled into the assembly as metadata.
Jason Jackson
The "More readable code" saying is not "dont comment at all", but rather "dont write comments that say what the code is doing", which should be obvious from the code itself. Comments should explain WHY the code does what it does, not what.
AviD
Re: comments as long as the code, I'm not sure that applies to short functions...
SamB
+30  A: 

Naming. Naming of classes, methods, functions, variables or modules. The name should be simple and easy to understand. And it should actually hint at its intended use. I hate it when I have to stare at some piece of code for much too long just to find out that it does something totally different than its name suggested.

unbeknown
Or something totally irrelevant, and a simple name would have told you so. Two- and Three-letter function names are just *awesome*.
anonymous coward
And if you change the essence of what a function does, please rename it to reflect its new role in life.
Ferruccio
So I shouldn't just name everything after myself?
Kevin Panko
You are right. When choosing meaningful names for functions, classes, variables and symbolic constants, source code comments are largely superfluous: the documentation is built into the actual code.
Dimitri C.
@Kevin: `class Malkovich { private Malkovich _malkovich; public (Malkovich malkovich) { _malkovich = malkovich; } }`
Daniel Earwicker
I've supported Mets1, Mets2, Mets3, Yankees1, Yankees2...
Kelly French
@anonymous coward Well, "sin" and "cos" are acceptable in a math module.
luiscubal
@luiscubal You're right. Guess that's where "hard limits" break down. I was referring to a different context, wherein the "function of the function" isn't evident by it's name. In a math module, it makes more since to have a function name like "cos". In a data aggregation module that reads Excel and CSV files, it's harder to tell what `inl()` does.
anonymous coward
+7  A: 

Copying and pasting duplicate code throughout a series of similar classes, rather than using inheritance or composition to put the required functionality in one place. That can be very difficult to refactor!

MattK
and difficult to maintain. If whatever that code does needs to change, the developer needs to apply it to each copy, if need be. Some could be missed.
paquetp
+23  A: 

Hello, my name is Nathan and I am a recovering "No" developer. ( <-- current pet peeve)

I used to hear a request for a feature and I'd say "No!". Then I'd say, "It cannot be done!", or "that's not how the product works".

Finally, worn down as the business guy convinces me that if we cannot do this we'll go out of business, I decide to think about it for a minute and code it up while he's going on and on trying to convince me about why this is such a good idea. I tell him, it'll be in the next release, and he leaves exasperated but happy.

Now, I try to be a "Yes" developer.

note: The business guy is often the developer on your team that wrote the framework you have to use that doesn't quite fit the bug you just got assigned.

Nathan Feger
Great answer. I agree with you here, however, I've never accepted NO from a programmer, even when I was QA, and manegement. I see it that we are "DEVELOPERS". We can DO ANYTHING. We write the code!. But, there's always that pesky time and cost issue, etc... :)
LarryF
I saw the other side of this at my last company. Every time a client requested a feature, it was implemented - and the resulting bloat effectively killed the product.
Ethan
Nathan, try not to come too far the other direction. Saying YES to everything can get you into a lot more trouble. ;-)
John MacIntyre
Computers are problem-solving tools. Software exists to allow the computer to solve our problem. If the software isn't solving one of the problems we're having, then what use is it to us?
Rob
I agree too much yes may be a bad thing. But hopefully, yeses tempered with real estimates and quality project prioritization will keep them under check.
Nathan Feger
The reason he's the business guy instead of developer is because he can't handle corner cases.
Joshua
@Ethan: It's not the programmers job to say 'No', unless they're their own marketing department and/or customer.
Jamie
The problem is "No, it can't be done" usually translates to "I'm a programmer, you're a peon. I don't need to explain myself to you." In most cases, a "Yes, we can do that, BUT..." is the best answer.
Jason Baker
Yes but it will take (X) period of time. Is it more imortant than already planned features? Which do you want to bump? Would this be ok in a later release when we can devote the (X) period of time to it that it really needs. That's the angle I try to take.
railsninja
"No" is what I am currently saying to anything the business guys bring me :) Sometimes it's too unclear whether it should be me or them who should worry about for the future of the product !!
Vijay Dev
@Rob: "If the software isn't solving one of the problems we're having, then what use is it to us?" Just because you can, doesn't mean that you should. If we implemented every customer feature request, our records management application would include it's own solitaire implementation by now...and it would read mail.
Mike Spross
@ LarryF I disagree. There are something you don't have control about.Like even if you have enough time and resource you can not hide Silverlight/Flash default fullscreen message. Simply because you dont have control over the plugin user uses.
Tanmoy
The correct answer to the question "Can we do X ?" is often "Yes, we can do Y.". If the person asking the question doesn't understand the difference between X and Y, you escaped using the N-word.
MSalters
Why not just answer honestly?
Jeff Davis
There is also a corollary to this, and that are the people who say "Yes, we can do that" to everything the customer asks for, regardless of whether it makes sense or is possible. A good programmer not only says, "Yes" or "No" but also makes suggestions - "No, we can't do that, but we could do *this*, which I think meets your requirements in a better way".
Dan Diplo
Sometimes Yes isn't the right answer. I've been asked to do things that exceeded available storage by a factor of 3 (and for very little gain, also.) I've also been asked to make a report of how things were going that might as well have used a handful of dice--it was attempting to derive useful data a few data points that had a *LOT* of random variation in them.
Loren Pechtel
This plays into the need for developers to understand their user community / business. So they can think about it and say: "No WE don't want this, WE want that". or "Yes, I was wondering when WE'd get to implement this feature".
Stephen Swensen
+23  A: 

Programmers that are so religious towards some programming construct they won't hear the other side. Example: stored procedure zealots.

Maudite
Stored procedures rock!!! :)
Walt Gordon Jones
I hold my hand up to this one, cause I use stored procedures for all DB access in my projects.
Bryan
Agreed. Learning all the ways to do something comes in handy. All the time.
Jeff Davis
i'll create a stored procedure when the query has well defined inputs.
Ian Boyd
@ian, i'm not saying strode procs are bad, but i have worked with people who believe that is the only way you should touch a database. They took it to the extreme and wouldn't look at most ORM's.
Maudite
Or webservices! "My web application IS the middle tier, but I don't understand that so I'll slow down the system and development at that by adding a FOURTH tier in front of the database... it's more secure after all, promise."
Stephen Swensen
I love this answer because I've interviewed so many candidates who claim that stored procedures is the "ONLY" way to go. Nevermind being able to articulate in what situations sprocs shine and where they may hinder. Nothing is a silver bullet...why do so many developers believe sprocs are the exception to this rule?
wilmoore
+196  A: 

How does a computer work.

If you are a programmer, you need to know how the hell a computer works. You need knowledge of function and behavior, as far as it concerns computer programs. RAM, CPU, cache, I/O, DMA, PIO, interrupts, etc.

You don't need to know assembly in particular, but concepts like flags, registers, branches, stacks, stack pointer, instruction pointer, memory, pages, DMA, interrupts, semaphore/lock support and things like that must be understood.

I don't care if your language abstracts memory management, if your database framework abstracts disk access or even if you use a framework abstracting distributed computing. It still gets run by computers and suffers from computers limitations, which does impact how your software works.

Daniel
if this topic doesn't interest someone, he doesn't need to know it. You're better off focusing on what you do best, and hire someone else to take care of things you don't like. A gynecologist doesn't know how the brain works and a neurosurgeon doesnt know how vaginas work
Click Upvote
well, that's not true. every doctor knows basics about brains and vaginas and is just specialised in the area he's chosen. and i would agree with Daniel.
agnieszka
Do not even need to go so deep. Just knowing rudimentary OS features or TCP/IP networking config is a challenge to many.
icelava
Word! I wish I had more than one up vote!
Booji Boy
You have my up-vote, although I do not agree with the particulars as much as the principle. It would be nice if all programmers had an education in Theory of Computation, for instance.
Parappa
You'll never need to know how locks work if all you do is write single-threaded programs that do not interact with anything else. But if you ever get to do a multithreaded program, you won't even KNOW there was something you needed to know. And, then... BOOM.So, just learn how it works.
Daniel
@Click UpvoteIf you don't understand how computers work you won't know whyfor (i = 0; i < len; i++) for (j = 0; j < width; j++) a[i, j] = 1;is much slower thanfor (i = 0; i < len; i++) for (j = 0; j < width; j++) a[j, i] = 1;for large arrays. Think about the cache.
RussellH
@RusselH: I thought about the cache, and what you're saying seemed like madness. So I wrote a C program to do what you're saying, and the a[j, i] = 1 loop ran about half as fast the the a[i, j] = 1 loop. Am I missing something, or did you mean the opposite of what you said?
chaos
@Click Upvote: neurosurgeons do not procreate?
Akusete
@chaos -- Thanks - I meant the opposite of what I said!
RussellH
@chaos and @RussellH -- It seems that this would be true in Fortran, as it lays out the arrays in memory in a different order.
Daniel
A neurosurgeon may not know how to insert an IUD, and a gynecologist may not be able to remove a brain tumor, but both of them can close an incision or set a broken bone.
Adam Jaskiewicz
i agree to an extend, but i'm not convinced this is truely necessary. Do you need to understand the origin of words in a language to use them?
Harry
@Harry: Apples and oranges. The "origin" is not "running" these words, and it's not going to come back to bite you if you misuse a word.
Mark
Knowing this stuff even if you never actually do anything with it explicitly gives you more of an understanding of why certain blocks of code may be slow or may be able to be optimised, for example.
Nick Bedford
I disagree with this answer. I've been programming since 1997 in Java, Smalltalk, Ruby, and now Objective-C, and I don't know how a computer works at a low level. I don't have any trouble debugging my software when it starts eating up memory or slowing down, as those issues occur within the higher-level language I am coding in.I could see this knowledge being necessary if you're writing lower-level code such as OS or drivers, but not if you're writing in a high level language for an end-user application.
Chris Garrett
A programmer doesn't have to know _all_ about the computer at an instant, but they should want to discover what is underneath the layer that they're using.I can get by using a compiler, but it was after taking a compiler course that when I made the mistake of using a list<vector<int>> that I realized why the compiler went nuts.
Calyth
@ChrisGarrett I agree that most of the time, you will not need to know too many low level things. But, when it comes to debugging problems, I find that more knowledge is better. There are diminishing returns past a certain point -- learning how electrons carry energy tells you how the computer works, but it is a lot more useful to hardware engineers than it is to us.
Kevin Panko
Whereas you may or may not know all that, just mentioning you're a programmer to somebody often triggers a "oh, you know what, I have been having this problem here with this old piece of kit, I wonder if you know how to fix it, shall I bring it over within the next 30 mins?" response. Most annoying, having to explain that you don't actually build computers but build web applications instead and getting a blank stare...
Dimitar Christoff
Programmers cannot expect to know *everything*. It's more important to know your limits so you recognize when you need some outside help. If I get a flat tire, I know how to fix that. But if my brakes stop working its time for me to call a mechanic.
Kevin Babcock
+1 for agnieszka for use of the word 'vagina' on stack overflow.
Simon
Programmers and vaginas in one sentence: has to be an oxymoron!
Mitch Wheat
@Mitch Wheat: Not if you're DHH - friggin' sexy Danish bastard :).
Charles
+3  A: 

The power of Google. Or Find in Files.

MSN
Who needs to ctrl-F to find something when you could just take endless amounts of time looking through it on your own? :-P
Evan Fosmark
I meant as opposed to asking me :)MSN
MSN
http://tinyurl.com/67ewkc
Kevin Panko
+6  A: 

The idea that using On Error Resume Next means you don't have to check for errors. I have to maintain a cesspit of VBScript and the guy before me just littered On Error Resume Next everywhere, without bothering to do any error checking at all.

Wayne M
"On Error Resume Next" is the VB equivalent of "here be dragons", or perhaps, "dodgy shit coming up".
Rob
+49  A: 

The web is stateless and the browser isn't part of your app.

I find a lot of programmers get caught up in their framework of choice and they ignore, forget, or never understood that each request to a web application is like a brand new program running. We (or our framework) have to do a lot of work to maintain state and simulate a "logged in" experience. Some of that work involves having the browser store stuff and give it back to us, but we cannot rely on the browser doing the right thing.

Plus too many programmers don't even know the difference between code that runs on the server and code that runs in the browser. I have had arguments with programmers who insist that ColdFusion, PHP, or VBScript code that is inline in an HTML page is run in the browser.

--
bmb

bmb
"Ouch" to the second one!
nlaq
This goes back to the answer above about knowing how computer work at the machine level mapped onto knowing how networking works.
jmucchiello
I came in to "help" with an existing project where the primary developer would do string concatenation in PHP to display email addresses (previously 3+ parts, in variables) so that "web/spam crawlers can't read them". Stuff like: echo $prefix . "@" . $domain . ".com";
anonymous coward
I hate to blame the programmers for this, however blameworthy it may be; I think a large part of the problem is when you have frameworks and development tools that try to let you pretend you can control what happens on the browser.I'm talking to *you*, Visual Studio; I've watched developers who should know better be confused by the magic you almost succeed in doing.
JasonFruit
Just an FYI, but VBScript that is inline in an HTML page CAN be run in the browser (if it's IE).
Jason Baker
As far as I know, VBScript can only be run in IE if it's inside <script> tags and that's not what I meant by "inline". My bad, I guess. See anonymous coward's comment -- that is really my point.
bmb
VBScript != ASP
Jeff Davis
How about programmers which try accessing server files in client code?
Sorin Comanescu
+41  A: 

One of my biggies is that many programmers don't understand internationalization. Even when an app is supposedly built with it in mind, it's usually not done right.

  • There will be string concatenation to form sentences that might work fine in English, but the word order is wrong in other languages (should be using some kind of templated substitution). Or they'll blindly add "s" to the end of a word to make it plural -- that doesn't even work well in English, much less other languages.
  • They'll support multiple currencies (and currency symbols), but assume the decimal marker is always a period or that the currency symbol always goes at the front of the number.
  • Dates will be written in an ambiguous order (usually the American way of month/day/year).
  • I know I've seen more of these, but I can't think of them right now... maybe I'll edit it as I think of them.

I didn't have time to read more than the first page of answers, so please pardon me if this is a duplicate.

rmeador
2009-06-18T23:06EST
Ape-inago
Not only does s not always plural things but you can end up with subject/verb disagreements. The last time I ended up having to deal with cleanly handling plurals I wrote it to have optional text to only be used on singular cases and optional text to only be used on plural cases.
Loren Pechtel
Some languages have singular, dual, and plural (three or more).
TRiG
In English programs that doesn't currently intended for internationalization, I usually would just do "3 item(s)" so there will be no need for complex logic that could hamper internationalization in the future.
Lie Ryan
+3  A: 

The myth that writing the code is the main part, while debuggin is just an extra.

They are both faces of the same coin. If one is shitty, the overall result will suck.

Demian Garcia
+5  A: 

Poorly named variables/classes/methods where the programmer is trying to stay within some artificial 8 character limit. This combined with extremely verbose (and often unnecessary) comments is one of my biggest pet peeves.

Karthik Hariharan
Do people actually do this?! Now?
thursdaysgeek
+74  A: 

Believing that catching and ignoring exceptions means preventing a bug. In most cases the exception means that there is a bug in the code. Ignoring the exception is just like looking the other way. This is especially true if the code catches the base class Exception.

Or to put it another way: some people seem to be more willing to let the application continue in a undefined and possible illegal state than accepting the fact that there's a bug in the code, which should be addressed.

Brian Rasmussen
I worked with a programmer who "fixed" an access violation by adding a signal handler that allowed the program to continue. This brought me great sadness.
Kristopher Johnson
Amen! You end up with systems that appear to be working, but under the hood huge errors are happening all the time! And the ones who coded it actually think that's good because a big ugly stack trace doesn't appear on the screen!
Charlie Flowers
If that's true (and it may be), then bug-free code could not throw an exception. If that's the case, checked exceptions are a waste of time and you wouldn't be forced to catch them, so you'd never see a catch and ignore. Perfect circular logic there--I like it.
Bill K
If trying to read a non-existing file throws an exception, it's not yet a bug. The problem is believing that if you write try/catch you already solved the bug and that actually handling the exception is just extra fluff.
Patrick Huizinga
I understand, I was just taking exception to the statement that "Most times an exception indicates an error". If Checked exceptions didn't exist, that would be true, but with Checked there could be dozens of reasons and many don't need to be handled in most programs.
Bill K
This is acceptable if the data is transient or unimportant - for example I have a program that analyses the "differences" in motion between two webcam frames. I doesn't matter if I don't do anything when I catch the exception when one of the pixels goes wrong because I don't necessarily need every single pixel correct.
Callum Rogers
@C Rogers: I should have stressed that this is often done by catching all exceptions and ignoring them. There are situations in which you may catch one or few specific exceptions and ignore those. I'll reword my answer.
Brian Rasmussen
Also: testing for invalid situations, and just giving up. If a parameter shouldn't null, it's best to fail (gracefully if possible), rather than just "if(foo==null)return;". Diagnosing a silent "app isn't crashing but isn't working in this particular area" becomes a nightmare.
stusmith
This is rampant among the outsourced developers I've worked with. In one project, these folks had surrounded every method (we're talking thousands here) with a try-catch_all-do_nothing_and_return block. We were swamped with bugs, and I suggested that we remove these as one of the first steps. They were horrified, arguing that these were necessary or the program would crash!
Scott Smith
+6  A: 

People don't understand the possibilities of disjoint-union types, perhaps because the support in C, C++, and Java is so abominable, and in a dynamically typed scripting language, everything is a disjoint-union type, so they disappear into the woodwork. Programming with disjoint unions and pattern matching is one of the great pleasures of a language like F#, Haskell, or ML.

Norman Ramsey
+1: union types are underappreciated. I can't tell you how many bulky class hierarchies I've had to define in C# when I could have written in the same thing in F# with 5 lines of code.
Juliet
+5  A: 

Reinventing the wheel when microdesigning a components of an enterprise application. Examples from J2EE apps : various custom ways to read a property file, component-specific custom made logging, database connection pool written from scratch, various attemps to custom build an authentication mechanisms, etc. Always wondered what was wrong with standard means we already had for these tasks...

david a.
+6  A: 

Inexperienced programmers are apt to believe the terrible fallacy that there is such a thing as placeholder code, which they dutifully demarcate from the rest of the project with a giant TODO comment. Such code is generally rife with half-assed algorithms, lousy variable names, random comments, ugly formatting, and scads of corner-case bugs.

What these programmers have yet to realize is that on a commercial software project, the schedule pressures will eliminate any time to go back and clean up that code. When the testers find bugs in that functionality, the programmers will have only enough time to apply the minimally-invasive fix for each bug. Eventually, that placeholder code will have survived weeks of testing and therefore deemed a low priority for refactoring.

Nobody expects beautiful, bug-free code. Just try not to commit any code to the source tree that you wouldn't want to ship in the final product.

mseery
http://www.elearnspanishlanguage.com/grammar/todo.html TODO is such a good word. 'anything' or 'everything' code.
Pete Kirkham
I have been doing software for 15 years and *I* believe in placeholder code. Its the correct way to code for Agile and TDD. Just write the minimal amount of code to meet the requirements and unit tests. If the placeholder has bugs it isn't being tested enough. If its O(n-cubed) performance, that's another agile development pass to fix, and if its slow, at least it works.
Zan Lynx
Agreed. Point taken.
mseery
I guess I approach TODO differently. In my code "TODO" comments mean something is not yet done to some constraint (like the specs have not been delivered), but must be done before the project is ready - a project cannot go into production if the source still has "TODO" comments. On the other hand I have FUTURE comments which indicate "nice to have" TODOs - places where I'm reminding myself or future programmers of improvements that *could* be made.
David
I believe in placeholder code, however, my placeholder code does not actually do much. Typically, it will terminate the program (with a message -- hopefully) if reached ...
SamB
+5  A: 

Lazy naming conventions

I can't stand it when programmers try to take short cuts when naming their methods and variables.

AA is not an acceptable variable name.

Being descriptive saves time later when you have to re-read your code or if someone else has to figure out what you wrote.

PS. Related to this is putting good descriptions infront of your mthods. You have no reason not to in VS2005+ it practically does it for you if you hit ''' infront of the method name.

Middletone
or /// if you're using C#. ;-)
Patrik
OTOH, documentation that your IDE "practically does for you" is useless. One of my pet peeves is API documentation that helpfully explains a method fooBarTheBaz() with "FooBars the Baz" and that's it. But I definitely agree with the statement that functions/methods and variables need to be given reasonable names and summary comments. I've been struggling to modify another's code recently, and ended up rewriting much of it because I could not figure out how it worked.
LarsH
+2  A: 

Most programmers don't seem to realize that any database product based around SQL is not a relational database. Somehow the whole concept of a relational database gets smeared because of how awful SQL is. Web developers now want to use new untested database paradigms because they just can't stand the idea of using a "relational" (that is, an SQL-based) database. Go ahead and read the SQL standard and try and find any occurance of the word "Relation" or "Relational"

In reality, there has never been a mainstream relational database. There's a couple research programs (like rel) that implement the relational concepts. But it's all got this kind of grampa's suspenders air about it, that nobody wants to touch, because it's just not hip to be mathematically and logically rigorous nowadays.

Breton
This doesn't make any sense. SQL certainly is "relational".
JosephStyons
Then don't you get it? isn't this raising any alarms? You're an ignorant programmer! You can start at the wikipedia entry for "Relational Model" and then read any of the books of Chris Date. Quickly!
Breton
+1 because it is HUGELY Controversial, and according to the classic definition of the Relational Model, he has a point.
Binary Worrier
Controversial? Maybe. I have noticed there's a lot of fuss and bother about it. Only one side seems to have any rational and compelling arguments though. The otherside only seems to have "because", and occasionally "Performance", though that second one never has any figures to back it up.
Breton
I don't think that web developers have a problem with SQL databases because they are offended by the lack of relational purity in commercial RDBMS's -- I think they are just not interested in any kind of database at all.
David Aldridge
You don't miss what you don't know anything about. "Ignorance is bliss", as they say.
Breton
@David: I think they just want magic.
SamB
+26  A: 

Programmers that are commissioned to write an enhancement, but end up rewriting the program because they "don't like" the way the original was written.

jpmcclung
Dear lord, a thousand times, yes! Especially for reasons of language bigotry. It's even better when the "rewrite" is of poorer quality.
Rob
You are implying that the original did not need to be rewritten. What if the need for the enhancement shows that a refactoring is warranted, and that the resulting (refactored) program would be better designed than the original with a hack applied on top?
Ether
He didn't say refactored; he said rewritten. There's a difference.
JasonFruit
You have to wonder about the position of management in such cases.
Jeff Davis
Yeah, I've done that once. :-/
Paul Nathan
It would certainly be annoying if someone got into the habit of doing this, yes... but it's not *always* the wrong choice. What if the original was in assembler?
SamB
I am more talking about a lack of "code empathy". Unwillingness to understand the current code and how it works. Rewriting code you don't understand.
jpmcclung
+598  A: 

My Application Owns the Computer

A pervasive attitude among programmers is that the only reason people own a computer is to run their application. Symptoms include:

  • Usurping shared resources like the desktop, system folders, task bar, registry, ... ("The whole machine is for my use.")

  • Can't turn off the app ("The only reason the machine would be on is to run my app, so I'll install an auto-startup service, a startup app, an Explorer plug-in, ...").

  • Resource hogging ("I can just grab exclusive access to files, database, or network connections when I launch and keep everything open.")

  • Interrupts workflow with pop-up messages, tooltips, alert balloons, taskbar messages, status messages, sound effects, ... ("Look at me! I'm working! Do you see me? I'm doing something!!")

  • Collateral damage ("I don't use that so I'll delete it.")

  • Race conditions ("Anything I do will stay that way forever until I change it.")

  • Security breaches ("I can expose everything on the machine, since I am the only one that will ever access it.")

  • Lack of interoperability ("My app has everything it needs so I don't need to support file export or cut and paste.")

  • No deployment ("I will never have to update or uninstall my app; they'll just get a new machine.")

  • Inner-Platform Effect (app takes over standard OS functionality like network connections, user authentication, deploying third-party software, UI look and feel, et al.)

Dour High Arch
I work mostly on server side stuff and know that my applications will pretty much have a VM to themselves. However, that knowledge would not justify doing any of the things you list.
ewalshe
Wish I could upvote this twice!You could write a book just on Adobe with regard to their installs:* Stealing registered extensions* Installing unrelated software (Yahoo toolbar)* Creating icons on desktop.* installs a memory resident start up widget to "Quick launch" their app.
JohnFx
Further, I can't stand it when applications pollute my documents folder and use it as an app data folder. There's a folder called APPDATA that exists EXACTLY FOR THAT PURPOSE. GO AWAY.
Matt Olenik
Matt,+1 to that! The other comments too... @Dour, consider adding these to your answer too...
AviD
It's a community wiki, you're allowed to add to it.
Dour High Arch
I consider apps (mostly Microsoft) that create folders in "My Documents" to violate this principle. If it were for application data, it would be called "Application Data". Oh, wait, there is one already!
StuffMaster
Related to this is the "quick start" option (automatically checked most of the time) in large apps. By pushing the start up time of the app into the start up of the computer, you punish the user every time, but they never know it's your app's fault. Unbelievable!
Kai
Yes i have given up on having the document folder for my usage. I can't stand seeing all of the application crap in there. So i just ignore it's existance and use my own folders outside of that structure
Harry
Fot the resource hogging, I think MSN messenger is an excelent example. Try sending a file to a friend while you have it open... exactly, you can't. You can not send files that are opened.. Why is that? I can email files I have open, why can't I send them through messenger...
Pim Jager
MSN Messenger is respecting a locked file in this instance. And i really don't see how this relates to MSN Messenger being a resource hog. But hey rant away my friend
Harry
Don't forget DRM, which is functionally indistinguishable from illegal computer hacking.
Mason Wheeler
This is especially true with software that comes with for example a webcam or other device - software which the user didn't explicitly ask for.
Jesper
I am on Vista, so I basically just ignore the Documents folder and create my own sub directories of the Personal folder.
MiffTheFox
After installing this application/update you must restart your computer. Now.
rojoca
Amen to that! I would upvote this twice or thrice if I could.
Pekka
That's what open source is for :)
static_rtti
Programs should not use the clipboard for interprocess communications, Brice.
aaaa bbbb
Pro Tools (de facto standard music production software) enumerates all hard drive volumes mounted on your Mac and creates a folder called 'Digidesign Database' in the root of every single one. It also locks all such volumes so you can't unmount them. It also notices when you plug in a removable drive and does the same thing. So plug a USB stick, a phone, a camera, anything drive-like, and Pro Tools will leave a little folder turd on it and stop you from unmounting the device... well, now you're running Pro Tools it's not like you'll be using the computer for anything else, right?
Daniel Earwicker
Boy this is one that really pisses me off. What's worse, I've sat in meetings with people from marketing, sales, you name it, who have said things like "we don't want to include an uninstall option - that shows lack of confidence in our product", or "we don't want to prompt the user before installing our toolbar - they might answer 'no'". I just want to punch them.
Scott Smith
Tell this to the McAfee developers, please. My work machine has no less than 12 simultaneous McAfee processes running on it at any time, and at least once a day a couple of those processes will go nuts and lock up my CPU for about a minute. I so hate that software.
Charles
Symantec software does that, too. Well, the retail crap does; interestingly the corporate product is fairly well-behaved.
staticsan
The ever worst is microsoft, when they decide that a certain software really can't be installed only on your system drive. Regardless of space it is just so necessary to have some of the files on say you music disc. And even worse when they decide that installing the operating system on one partition or drive would not suffice. See that encrypted drive there? Lets format it to ntfs and put boot.ini on it hurray... Now I see above that Pro Tools tries to compete with that. There is one more thing that irritates me. Side by side installinng of .net framework, but that is an order of mag smaller.
ufotds
+22  A: 

Unintuitive variable names!. God I hate it.
Have you ever read someone's code, (if it's looking for a bug it's even worse), and wondering what the hell "nfi" (NumberFormatInfo), "par" (parameter), "mkAtt" (make attribute) mean? I even saw XML yesterday containing data with attributes n and v (for name and value) and a comment above that n stands for name and v stands for value...
people, if you've got intellisense, why are you so afraid to write a full, understandable name? I admit I'm a bit obsessed with nice variable names, but it's just because it's sooo easy to read if you write your code properly.

I prefer

foreach (string parameterId in idsToNames.Keys)

to

foreach (string key in parameters.Keys)

or

foreach (string p in pars.Keys)
agnieszka
sorry for a duplicate
agnieszka
What's wrong with the latter? In the context of the loop the meaning of a one-letter loop variable should be crystal clear. No need for a more descriptive but also longer name.
Konrad Rudolph
well it confuses me if i read the part inside foreach and someone uses methods of p and i have no idea what p is (parameter, part, position, point?) until i get back to the foreach line, check that it's an item from pars and then check what pars keys are (that they're for example parameter ids).
agnieszka
p doesn't tell me what it is but id or even parameterId is much more descriptive. p can be anything beginning with p and parameterId is probably an id of a parameter.
agnieszka
I fully agree, there's no cost in giving your variables nice names and you get all the benefits from making them readable. A guy on our team declares single letter variable names i, j and k all the time. I had to maintain his code while he was away and saw j.ToPoint(k), I thought "what the hell is j? Why can I convert it to a point? and why does it accept a k??? I refactored the hell outta that code and he didn't recognise it when he came back. Seeing my tidy code made him change his ways though :-)
DoctaJonez
Well, short variable names *do* have their place. http://ssdl-wiki.cs.technion.ac.il/wiki/index.php/Terse_variable_naming discusses this.
Brian
I see this a lot more with LINQ now: list.Where(i => i.FirstName... I totally understand i as a counter in for (int i = 0;..., but why is everything an "i"?
Jim B-G
In the XML case, the attributes could be repeated thousands of times in a single file, and there it might be a win to use one-letter names ...
SamB
oh yes of course, you can find lots of places where one-letter variable names do have their place. i was just describing the situation where there is no reasonable explanation, just a programmers habit - and it happens!
agnieszka
+6  A: 

Far and away: construction-time optimization.

I can't count the number of times that I've encountered early loop termination, strange handling of variables, direct access to class members, breakdown of hierarchies, etc... generated in the name of optimization. This seems to be one of those things that every book on programming mentions and that nobody follows.

People, if you're writing a net-centric app, or doing heavy DB accesses, or waiting for a user, particulary in multithreaded apps, you will be spending FAR more time waiting for networked I/O than processing data. With that kind of performance profile, any sort of optimization at all will be essentially unnoticed in terms of performance. It's much more important to write code your mother can read. In this mindset, optimization is fine - you can return early from that linear search through a list if the looked for element is the second one you see - but it must be simple and obvious. Think of how much money and stress you can save yourself, and your company, if any time person B picks up person A's code, person B can understand it on the first read.

Matt
Except optimizations that reduce the amount of time spent waiting by either lowering the number of round trips or allowing more of them to happen concurrently with other things, of course...
SamB
+15  A: 

Selective Standards Religion

A developer will crusade for the standards of their chosen technology stack, and completely ignore or even disparage standards outside their primary focus.


Web Developer: "Most DB people are clueless! They don't know the first thing about CSS. Most just use tables to position everything! Haven't these people heard of Standards?"

"What difference does it make whether I use the SQL standard or Product X's proprietary command to retrieve the report data? I get the same result, don't I? I don't even need to worry about the database - my ORM deals with all that."


Backend Developer/DBA: "These UI scripters can't even spell 'relationship'. If even one of them knows the definition of third-normal-form, I'd be stunned."

"The scripters keep nagging me about changing my sales report pages to support their niche browser - why can't they just get with the program and use Browser Y?"


Note - these are examples, and are by no means comprehensive.

The moral of the story is to understand that most technology areas have standards, and you will only improve your skills and value by learning them. Even when you choose to go against the standard, you will be doing it from a position of knowledge, not ignorance.

JeremyDWill
+17  A: 

I have three: Web programmers who don't know HTML and Javascript, but instead depend on frameworks that they don't really understand - they don't know what the framework is producing on the client.

Application programmers who don't understand that the computer doesn't run their source code (they don't understand the compilation/interpretation step)

SQL programmers who don't write SQL - ie. they write procedural languages using SQL syntax.

I suppose I could go on forever with this, but those are the top three

Jasmine
+3  A: 

Programmers that have absolutely no idea whatsoever what "malloc" means/refers to.

+22  A: 

Short "else" clause after a long "if" clause, especially when the else just throws an exception. I prefer to detect the error case first and throw the exception which tends to limit nesting of subsequent code.

s_t_e_v_e
I totally agree, it is about testing exceptions and not the normal case, http://stackoverflow.com/questions/114342/what-are-code-smells-what-is-the-best-way-to-correct-them/223881#223881
hlovdal
+150  A: 

Thinking that customers know what they want

Don't take the customer's words literally. Understand the problem, talk about it with others, think of many creative solutions, and implement the solution that works best for most users.

Sean
Taking the customers words literally is disastrous. Not everything the customer utters is a requirement, in fact somethings should be transparent to the user and determined entirely by the programmers.
Bernard
Conversely, I've seen horrendous examples of (individuals, small teams) assuming they alone know what the customer needs, without deigning to analyse the problem in any detail before spouting off a list of "user requirements".
Rob
Shame I can't give you a bounty myself for this one. Soooo many people don't understand this, and to all sorts of stupid things because that's a literal translation of what the customer said they wanted.
T.E.D.
usually it's sales types who take the customers word as verbatim... then try to tell you(r team) that theirs is OMG THE MOST IMPORTANT FEATURE EVAR!!!111!!!11!one GET IT DONE NOW OMGWTFBBQROFL
geocoin
as a corollary thinking that the Business analyst / architect / Programmer actually understood what the customer wanted after a 5 minutes talk with him. I've seen 6 months project with whole teams based on these 5 minutes discussion... guess what the customer said when he finally got it... "WTF is that !!"
Newtopian
I always laugh at people who say they need to get "the requirements" from "the customer". I tell them "Customers don't have requirements, they have problems."
phkahler
How about the stakeholders who want to dictate exactly how an application should be implemented? Pet user peeve perhaps!
Phil
And never get requirements from just managers either, they have no idea what their users actually need.
HLGEM
+339  A: 

Label1, Label2, ... Label126, ...

Button1, Button2, ...

ooohhhhh ... I just want to smack somebody! ;-)

John MacIntyre
Lazy variable naming sucks. Often times I see $sqla and $sqlb when the letters a and b have no relationship to what those two variables are used for.
Bernard
I'll admit I tend to only rename the controls that are used in code. So the buttons get renamed but the labels don't (usually).
Cameron MacFarland
+1 AutoID is the devil!
Josh
+10 if I could, button1_click is demons work.
TreeUK
This is mainly from a drag and drop mentality
Harry
What if you have 126 labels and you don't know what they are for until runtime?
Jasmine
@Jasmine-If you are talking about dynamic controls, then naming them still isn't too much to expect.
John MacIntyre
@Jasmine-If you're talking about some super form with 126+ labels added at design time where the same form is used for everything -)
John MacIntyre
I agree, Harry. This is the fundamental problem with UI designers. The code they generate is unreadable.
Matthew Flaschen
That's it, I'm going back through all my old code and renaming my labels to Label126. Is that still considered lazy? :P
BenAlabaster
@balabaster - No, but I'm sure I can come up with another adjective to describe you. ;-)
John MacIntyre
@Jasmine - If you've got 126 labels on your form, runtime or otherwise, I think your form needs refactoring...
BenAlabaster
Yeah... I don't see the problem here. As long as those labels don't appear in the code, you can refactor them as soon as they become useful.
Mark
I used to completely remove the IDs of ASP.NET controls I don't reference in code. This works fine, except the Visual Studio designer doesn't like it :(
Thorarin
I must admit, naming Label controls is really tedious :P but yes. Seeing label1,2,3,25... in your Intellisense is messy
Nick Bedford
+1 I hate numerical variables. Grrrrrr
Elizabeth Buckwalter
Very similar http://stackoverflow.com/questions/1556672/most-horrifying-line-of-code-you-have-ever-seen/1556684#1556684
John MacIntyre
Who says you have to see Label1, Label2, etc. in your Intellisense? Set GenerateMember to false on those labels and you don't have to see them in Intellisense.
Kyralessa
@Kyralessa-This is more working on somebody else's code.
John MacIntyre
When it comes to working on somebody else's code, I'd be overjoyed if my biggest worry is having a plethora of Label controls on a form.
Kyralessa
@Kyralessa-agreed
John MacIntyre
@Jasmine - If you've got 126 labels that are only clear in meaning on runtime, then maybe an array would be better?
luiscubal
+5  A: 

if .... else-if .... else-if .... else

with a nesting hierarchy of four to ten levels, spanning several thousands of lines.

Your complete permutation of all branching logic in a method/function.

Hello, ever heard of polymorphism? Wait, you don't even know how to derive classes?

icelava
the only case I see this as valid is in a situation where you have some type of state diagram and you need to implement it in vhdl or some other type of hardware language.
Ape-inago
sorry, these are high-level business applications
icelava
... well, it's not as if we have `goto` anymore!
Robert L
+7  A: 

"All I need for debugging is a print statement."

Scott Evernden
Ever see "the only debugging tool that works to debug this is writing out to a port on the processor that turns this LED on or off"
Joshua
@Joshua: Yes. It can get worse though, if you work with FPGAs.
Paul Nathan
+4  A: 

Displaying a message box instead of raising an exception when a method fails to do it's job. For example, a Save() method in a Form simply showing a message box, instead of raising an exception, because the user hasn't filled in some required field, etc.

Because they don't raise an exception, any code calling the Save method has no freaking idea that the Save failed or why it failed!

Typically at this point I'd expect at least one person to say that exceptions should be used "exceptionally", i.e. rarely. If you follow this philosophy then you still need some way to tell your calling code that you failed, which results in changing your method signature so it returns failure details either as a result or an out parameter, etc. And of-course your calling code will need to tell it's calling code that it failed and so on. Ahh hello world, this is exactly what exceptions are built for!

Maybe this thinking doesn't work in all frameworks (like web, etc) but in Delphi Windows applications it's perfect as unhandled exceptions don't crash the application, once they travel back to the main message loop the app simply shows a presentable message box to the user with the error details, they click OK and program flow continues to process messages again.

Ben Daniel
For more details, see my blog post on this subject: http://bendaniel.name/2008/04/raising-exceptions-for-invalid-user.html
Ben Daniel
You should create 2 different functions: one to validate and one for saving. Shorter functions and no hassle to figure it out why is was a problem
PoweRoy
@PowerRoy: Splitting your code up doesn't get around this fundamental problem. This is difficult to explain in a 300 character comment (this is my 5th attempt and I'm giving up now, lol) but suffice it to say if you follow my link hopefully you'll understand. :)
Ben Daniel
Another way to put this is that you have to know at what level to convert from an exception to a dialog. Some people choose too early.
Bill K
+36  A: 
...the single worst subject of widespread ignorance amongst programmers...
  • "the business domain doesn't matter" aka "the business reasons don't matter" aka "the business is none of my business"
Steven A. Lowe
Well, it is your bosses business :)
jcollum
@[jcollum]: i assume you're joking - failure to understand the business domain can be catastrophic; a good understanding of the business domain will make you and your work much more valuable ;-)
Steven A. Lowe
I hate the corollary even worse: "I had to rush this out for business reasons. Sorry it sucks."
Jason Baker
@Steven - what is perhaps more shocking is the extent to which the people who run businesses often have exactly the same attitude. Anyone with an MBA can supposedly run any division of any business - no understanding of the domain required!
Daniel Earwicker
Does this actually happen?
Jeff Davis
@[Jeff Davis]: all too often
Steven A. Lowe
+3  A: 

Overengineering, usually to make unnecessary optimizations.

These are usually done by seniour developers. These usually add a lot of complexity with adding minimal (if any at all) speed improvements. What's worse, is that after these are done, someone other unlucky developer gets stuck with the "optimized" code.

Timur Fanshteyn
+18  A: 

In C#, when Visual Studio's default names are left in, and I have to figure out what button23 does, and why it reads from TextBox13 by flipping back and forth between the code and visual views of Form1.cs.

drhorrible
+30  A: 

Programmers who write help pages thus:-

This page allows you to add a foo. To add a foo, enter the name of your new foo in the field labeled "Foo Name". Select a the type of the foo from the list and click "Save".

WW
This can be appropriate in some cases, but yeah, 99% of the time, someone's written only the super-obvious in the docs, and completely left out the important stuff like "what a foo is" and "why".
MGOwen
It's even worse when it's the *technical writer* who is writing help pages like that.
Daniel Vandersluis
You've just given me an idea for a compression algorithm that would work well on the MSDN library
finnw
Sounds like the entirety of the dotnetCHARTING documentation. Fine library but the help couldn't be more obtuse if it tried.
Jim Dagg
@Daniel - Actually, I think it often *is* the technical writer who writes help pages like that, typically because he/she doesn't know anything more than the name of the action and because (due to some combination of organizational and personal weaknesses) he/she does not have access to anyone who could provide more information. Arguably, a good technical writer should quit when stuck in such a situation, just on principle. However, I can't blame him/her for keeping the job until a better position becomes available. ;-)
Joe Carnahan
+6  A: 

Lack of focus on the customer and their needs.

If I'm aspiring to be a professional then there are many soft skills I should acquire along with the technical skills. Formost among these the ability to develop an effective working relationship with my customer, whether internal or external.

I might write the best code in the world, but if it isn't what the customer needed then I'm not doing a professional job.

My pet peeve is how quickly we all forget the customer as soon as we click on that icon for our IDE.

it depends
all to frequently it is a complete lack of interest!
Stu Thompson
+6  A: 

My biggest pet peeve is developers who think that because they put together a solution for small company x that

  • said solution will scale to all scenarios
  • they are now architects, where real architects (I'm not one) are a whole other breed

A smaller subset is developers who are too lazy to learn and insist on coming to a senior (read: busier) developer to get them to solve ALL their problems. (key point ALL, of course they should rely on the hot shots for help with hard problems)

Robert MacLean
+6  A: 

My pet peeve, one that I care for and nurture has got to be "Well we have done it like that for years". Technology moves on, so should programmers. I don't mean use the new version because it is the new version. I used to hear it a lot from a VB programmer that clung onto VB6 with a vengeance. He didn't want to leave the bloated, dated and very slow VB app that he had due to it being perfectly good when it wrote it X years ago.

Khainestar
One of my peeves is the exact opposite. Managers who think that applications have to be constantly "upgraded to the latest platforms" even if the existing applications are working perfectly with no issues whatsoever.
Vulcan Eager
You have to draw a line though. After 5 years, with the language no longer supported, and the system is very slow and bloated. It is time to nail down the lid and write a new version.
Khainestar
Yeah, it's not a good idea to be stuck with a program you can't compile without searching for a disk you haven't used in years...
SamB
+35  A: 

People who still use Hungarian Notation for variables, like strName and dblAmount, in strongly typed, reflection-rich languages like c# and java, even if these days there are powerful IDEs and intellisense and etc.

axel_c
Hell yeah, this needs to die. It still creeps in with UI components too and that's generally accepted and it sucks. I think the _ before private fields is hungarian and needs to go, but it's debatable.
jcollum
What about the purpose of not having to go back to a variables declaration to find out what kind of representation it uses?
Sebastian Ganslandt
I personally find shorter names much better than TheOneObviousButALittleLongNameForAVariable.
ldigas
@Sebastian: if you have to "go back" a long way then your function is too long ;) In most cases you should be able to see the variable declaration on-screen.
DisgruntledGoat
@jcollum: The _ before private fields is OK in languages that aren't case sensitive like VB.NET (because you can't differentiate by case, e.g.: a public property FirstName and a private string firstName). It still looks ugly to me, but it's better than privateFirstName or something.
MGOwen
+1 - I work with a team who develops only in VB.Net, and I cannot understand why every object variable must be o[DataTypeName].
Matt Hamsmith
We condcuct lots of paper-based code walkthroughs and peer reviews, and variable prefixes like "dbl" and "i" are crucial to understand what's going on. On paper, you have no IDE, no IntelliSense and no reflection. I *love* Hungarian notation.
CesarGon
I always ask those Hungarian users why they don't add a type prefix for custom classes. I never get an answer.
Dimitri C.
@Dimitri. I add a prefix for custom classes :O IE: proCurrent = new Product(); It's actually more succinct than a descriptive name. The class prefix makes a lot of sense to me.
Jeff Davis
When reading code i don't have the insight of the compiler or reflection to know what kind of variable it is. `nRow` and `sRow` are different for a reason.
Ian Boyd
@Cesar - But wouldn't the type of the variable be on the paper-based code, wherever it was declared?
Keand64
@Keand64: You don't peer review the whole application in a single go; you do one chunk of code today, another one tomorrow, etc. The variables that you find being used in the code under review are not necessarily declared in the same chunk of code. A common example of this is a property-backing private field in a class (in C#). In addition, the purpose of code reviews is, partially, to assess the understandability of code. Being able to determine *instantly* what type a variable is, without having to find its declaration, is important. Easy with the IDE, should be as easy on paper.
CesarGon
@CesarGon - it sounds like your complaint is more with your code review method (using paper) than with variables not telling you their types. Why not do the code reviews in the IDE?
Zak
@Zak: No; our code review approach is paper-based on purpose. We try to maximise the amount of "knowledge in the head" to "knowledge in the world" ratio by avoiding tool support: this is a proven technique to assess the cognitive complexity of an artefact, and it works by placing as much effort as possible on the person and relying as little as possible on the tools. If something is too complex, you will realise *for sure*. [If I had complaints about our code review approach, I would change it! :-)]
CesarGon
@Cesar: So you want your code review to be as complex as possible for the person doing it, but you want Hungarian notation to make it easier to follow the code... there is something wrong here.
Sylverdrag
Actually, the real idea behind Hungarian Notation is not about types, have a look here : http://www.joelonsoftware.com/articles/Wrong.htmlWhen used the way it was meant to be used originally, HN can be really useful.
Drealmer
Installing and setting up a particular IDE just to take a look at the code of an open-source project using intellisense is a huge time sink. And that's assuming the IDE that the code was written for still exists and is affordable. Good code should be understandable when opened in a text editor. Whether that's accomplished via Hungarian notation or sthg different.
LarsH
+3  A: 

So far in my years of development I have found that I resent most those programmers who can't keep deadlines. It's OK to go over because of some unforeseen trouble, but to look into the eye and say:"It will be finished tomorrow" and then start coding next week is not acceptable.

Riho
The problem isn't that programmers can't keep deadlines, it's that they can't make schedules. He never should have said it would be done tomorrow, he should have said "Two weeks".
Bill K
Unfortunately i tend to be one of those 60% of the time. I have a whole lot of books on time management. I hope i'll make it someday. :p
redben
The bigger problem is managers who promise deadlines without consulting the developers in question first.
FerretallicA
+41  A: 

Use of inheritance when composition or external functions are more appropriate

(I would have thought someone else would have brought this up by now, but I browsed through the four pages already up and didn't see it - apologies if I missed it.)

It is still so common to see someone think along the lines of, "I need a string that also lets me do X", so they inherit from string and add their X method.

Or, I want a queue class that works in a multithreaded environment. Inherit from Queue (or whatever you have) and added overloads that aquire and release locks.

In the first instance it is more appropriate to have an free function (or static a method in languages that don't have free functions) that takes the string as a parameter (along with any other parameters) and work with the public interface.

In the second, write your threaded queue as a new class that contains the raw queue class, and expose the interface that is appropriate. Sometimes this involves a lot of forwarding methods - but that in itself should not be the reason for chosing inheritance.

Inheritance should be reserved for the case where your new class has a superset interface (could be the same), and for callers who only see the static type of the base class the behaviour should make sense (so it is substituteable in the Liskov sense). Furthermore, at least some (some would say all) of the method would necessarily depend on some of the protected state/ interface. That is - if you could implement all new methods using only the public interface, you are not changing the behaviour of existing methods for base class clients, and no new state is introduce, why do you need to inherit?

As an aside, some languages support constructs such as C#'s extension methods, which can also be more appropriate in some cases, and also open to mis-use - but that's another subject.

Phil Nash
Well said, the GOF guys would applaud this.
jcollum
What's wrong with using inheritance for a synchronized queue? Same interface, modified behaviour. Possibly some additional methods. That looks like a good candidate for inheritance.
finnw
You are so right. I think it is a shame C# doesn't support standalone functions, although the extension methods feature helps a lot.
Dimitri C.
+33  A: 

Ignorance of thoroughness

"That isn't a condition I should account for, the user should never do that".

"I just write new code, other parts of the development cycle aren't my job (analysis, testing, planning, documenting)".

"I just get the job done. I don't worry about the fact that someone will have to continue to maintain this code, or that business rules can change".

How did I come to think developers are ignorant of thoroughness? Because I've made plenty of those mistakes myself!

Bernard Dy
The user should never do that? and you should not be letting them!
DFectuoso
+1 Admitting one's own past errors is one thing that just a few do !
redben
I ask the developers, "How do you want the app to react to condition X?" to stay away from "They shouldn't ever do that" type of thinking. We're responsible for the applications behavior, not the users.
Kelly French
+7  A: 

The idea that "intuitive" interfaces can actually exist. Sorry, but every interface is learned.

Although it is true that this idea usually comes to me from a business analyst...

Bernard
Yeah, we had a client recently with a requirement for a CMS that was "so intuitive that it could be used without any training". It's not possible.
Dan Diplo
Users never start in a blank state. The world around them and every other bit of software they have ever used taught them to expect certain patterns. Even if you can make the philosophical argument that these are not inherent to users, in practice, there are ways to lay out an interface so that most users will be able to use just by looking at it. That's what we call an intuitive interface.
Sylverdrag
The problem is that set of "expected patterns" varies greatly by the experiences of the users, and there is no one "experience" that fits "most" people. You have to know your target users very well and design to their expectations, however the larger your user base the more people you will fail to please. We all have different experiences.
Bernard
+10  A: 

Using a collection of If conditions instead of regular expression. I already saw a +1000 line function that could be reduced to 2 regular expressions.

This is a specific example of the generalization "code which does not need to be written will necessarily not have any bugs in it". The one thing better than well-written, bug-free code is code that never needs to be written at all!
Ether
Watch it or you'll remove my hand-tuned FSA in the bottleneck.
Joshua
@Joshua: presumably you have a comment on that FSA stating why it exists in that form, possibly giving the regex that you wish you could use along with the reason that you can't use it?
SamB
Yeah I've got a bottleneck comment.
Joshua
+23  A: 
  1. Windows people who still think Linux is command-line only.
  2. Linux people who complain about Windows not being distributed with build tools, not realising that for some years MS has made an extremely high-quality, highly standard-conforming and highly optimizing C/C++ compiler and IDE available for free.
j_random_hacker
Tell me more about this build env for windows, please! (add a link)
Gregg Lind
Gregg: Added the link to Visual C++ Express Edition. (BTW it's the first thing that comes up when you google "microsoft c++ free"...)
j_random_hacker
This can be generalised, in part, to "Linux/Windows zealots who extol the virtues of their platform and ridicule all others, without having used said platform (ever, in a reasonable number of releases), and have no idea that it also does X, Y and Z."
Rob
I totally agree Rob.
j_random_hacker
I just read a blog post the other day about a windows user who tried Ubuntu. It only took him 20 mins to get to a point where he was forced to do something at the command line. It's not command-line-only but you damn well better be command-line-friendly. Why have a GUI if you're not using it??
jcollum
@jcollum: Interesting, do you have a link to that blog?
j_random_hacker
On point #2: making available for download does not constitute distributing with; as a developer, you can't count on anything not distributed with the OS as reliably being there.
A. Scagnelli
@A. Scagnelli: You're right, it's one more moving part that can fail, but I think that's a minor point. These days a PC without an internet connection is like a PC without a screen -- yes, they exist, but they're highly atypical. (Leaving MSVC++ out of the distro could even be construed as a feature -- non-technical users already complain about Windows being bloated.)
j_random_hacker
@A. Scagnelli: It's just the ide and compiler. The libraries you're building for are already included with windows. If you're doing a binary distribution, what does it matter if a compiler is there or not?
Joel Coehoorn
I am often surprised by Windows programmers who think OSX is a cooperatively multitasked system with no memory protection between processes simply because that's the way the classic Mac OS worked.
Ferruccio
@j_random_hacker: Having a Internet connection, still isn't an excuse. My connection is 1 meg, and I can't get faster here. If I didn't copy all my stuff to disc, it would be a day or two between system setup, andbeing able to do all I want. That's not acceptable.
Macha
@Macha: I don't deny that that is a problem for you, but unfortunately for you, you're an outlier -- the vast majority of MS's customers (a) are not developers and (b) have decent internet connectivity anyway. Also many complain about "unnecessarily bloated" MS software. So in 95% of cases, leaving out the compiler and IDE makes sense, do you agree?
j_random_hacker
@jcollum: "Why have a GUI if you're not using it?" -- You bought a mouse; you have to use it at least sometimes.
amphetamachine
@j_random_hacker: I'm sorry, I totally forgot to follow up. Can't find the blog.
jcollum
@j_random_hacker: if only the "express" referred to the download/installation speed -- it's rather big and takes rather long to install ...
SamB
@A. Scagnelli: *nix systems don't always have the compiler installed, either, much less the libraries you need. The difference is the ease with which most distros allow you to rectify this...
SamB
+12  A: 

Not using loop continuation statements. Imagine, a multi-screen method, that continues to indent near-endlessly.

while (someCondition) {
   if (myOtherCondition) {       
      if (yetAnotherCondition) {
           doSomethingWorthwhile();
       }
   } 
}

versus

while (someCondition) {
    if (!(myOtherCondition && yetAnotherCondition))
        continue;

    doSomethingWorthwhile();
}
segy
im off to refactor some code brb... there. I love how my code looks now, ty!
DFectuoso
I totally agree, it is about testing exceptions and not the normal case, http://stackoverflow.com/questions/114342/what-are-code-smells-what-is-the-best-way-to-correct-them/223881#223881
hlovdal
why not move all three conditions into the while statement?
Benjamin Confino
that would terminate looping. this is for cases when your iterating over a collection where some elements may not need the loop action. effectively it acts as a filter.
segy
"The real wtf" is the multiscreen while statement. continue tends to indicate something is wrong.
Tom Hawtin - tackline
If I could upvote this ten times, I would.
Shadowfirebird
@Tom Hawtin: what would you do? Use `goto` instead?
SamB
@SamB In place of a `continue`? No.
Tom Hawtin - tackline
+11  A: 

In no specific order:

  • People who pick a certain technology for a project just to get it on their resume. We have this one unmaintainable app at work because the developer (who left about 6 months after starting the project) decided he needed to write it in something neither he nor anybody else knew.

  • People who believe that there is one true way to do something and that everybody else who doesn't agree is either stupid, ignorant, or a heretic.

  • Premature/Nonsensical optimization strategies. This was taken to its extreme by one of my former co-workers at a Java job (I love Java, this has nothing to do with the language). He refused to use interfaces, non-final methods, or non-final classes. He believed everything (EVERYTHING) should be cached to the extent that he wouldn't create objects and would cache even the simplest things. He believed that all this made his code "more performant" (is that even a word?!). Of course, he wouldn't cite any sort of proof that this was the way to do it, nor would he prove that his code needed this optimization in the first place. Code like this is a joy to test, by the way.

  • Job title as a defense. Same job as the last part, we had this guy who was convinced that java.lang.String had some kind of bug in it. When I tried to point out that it might be his code instead, he started in with the "I'm a Lead Developer, and if I say it's in String, that's where it is. You need to follow me. I'M A LEAD DEVELOPER!"

Todd
I feel your pain.
John Boker
i feel your pain too but i think number 2 is very subjective and actually thinking like that will make you pass in some of the greatest knoledge in programming =(. Theres so much people in this business not making what they should that the good people shield themself from words
DFectuoso
+3  A: 

I've found that a lot of programmers don't know about the for loop. They'd rather use:

Dim i as Integer = 0
Do Until i > 10
    'do stuff
    i = i + 1
Loop

And when I tried to let one know about the for loop he got mad and said he wasn't going to rewrite all his code just to use a different kind of loop.

John Boker
Haha lol! You serious?
Jonathan C Dickinson
maybe im using the term "programmer" loosely. :)
John Boker
+7  A: 

The belief that functional programming is new and the belief that functional programming is the end-all be-all to programming.

BobbyShaftoe
People are gonna shout at me for saying this, but the same applies to OOP as well. Or any other. There is no "one true way" in anything (except driving on the highway)
ldigas
You're totally right. And as I read it I couldn't help thinking: "The belief that Java programming is new and the belief that Java programming is the end-all be-all to programming." but can't post that as my own answer now :) For those that did not notice, I re-used Bobby's words ;)
Peter Perháč
Bobby, do you really think that's a problem though? I think a far bigger issue is developer's reluctance to learn something as different from what they're used to and is widely established (e.g. OOP, .NET, Java etc.) as FP languages are. If you have someone willing to learn an FP language chances are they're open minded and not liable to believe that there is *any* "end-all-be-all"
Phil
@BobbyShaftoe: don't worry, they'll calm down after having known Haskell for a few years ;-P. They might still think it's the best thing since sliced bread, but they'll have learned that it doesn't solve everything by a long shot, and isn't always the easiest or best way to approach something...
SamB
+2  A: 

My pet peeve is a sort of brain-washing that most programmers don't even realize has happened to them - namely that the von Neumann machine is the only paradigm that is available when developing applications. The first data processing applications using machinery were what was called "unit record", and involved data (punched cards) flowing between processing stations, and the early computers were just another type of station in such networks. However, as time went on, computers became more powerful. Also the von Neumann architecture had so many successes, both practical and theoretical, that people came to believe this was the way computers had to be! However, complex applications are extremely difficult to get right, especially in the area of asynchronous processing - which is exactly what the von Neumann machine has trouble with! On the other hand, since supposedly computers can do anything, if people are having trouble getting them to work, it has to be the fault of the programmers, not the paradigm... Now, we can see the von Neumann paradigm starting to run out of steam, and programmers are going to have to be deprogrammed, and "go back to the future" - to what is both an earlier, and a more powerful, paradigm - namely that of data chunks flowing between multiple cores, multiple computers, multiple networks, world-wide, and 24/7. Paradoxically, based on our experience with FBP and similar technologies, we are finding that such systems both perform better, and are easier to develop and maintain.

Paul Morrison
-1 for a poorly formatted answer. Ever heard of paragraphs or bulleted lists? // And while we're on the subject, I sincerely hope that you pack a fair amount of whitespace into your code; because if it's anything like this post, it would *surely* be difficult to read!
Jim G.
+14  A: 

The end-user experience. Most developers have a flat-out disdain of the end-user when it is the end-user who is the entire point of the development effort.

+11  A: 

Blowing off restrictions/constraints for a framework/library/API/subsystem that are clearly spelled out by its authors in its documentation is a big problem. As a corollary to this, I would include: simply not even bothering to read the documentation.

Here are some examples of mistakes I see cause problems over and over again in Java programming:

  1. Concurrency issues (e.g. modifying things that are non-reentrant from the wrong thread)
  2. Failing to close things properly; a.) either totally omitting the call due to extreme laziness, or b.) failing to structure it in a properly constructed try-catch-finally statement.
  3. Mishandling exceptions; a.) putting things in a catch (Exception ex) statement block that belong in finally, b.) doing catch (Exception ex) and then doing nothing in the body, c.) failing to call a logger with a warn/error/fatal when catching-not-rethrowing ex, d.) logging an exception, re-throwing it, and logging the same exception with same msg, e.) throwing unchecked exceptions and not documenting they are thrown in javadoc, f.) failing to throw a nested exception and instead just throwing a different exception.
  4. Calling a print/println method in production code when using a logger is needed
  5. Not aborting start up of an application when an error is detected in configuration
  6. Syntax errors in generated/entered HTML code; HTML has been out a decade and a half, people - learn the language and use a validator
  7. Generating/entering XML with syntax errors in it, not validating it, and not turning on validation in the XML parser being used
  8. Testing HTML with a particular browser - and completely overlooking the fact that it has lots of errors in it because it "looks right" in that version of that browser.
  9. Spelling errors in comments (decent IDE's point these out now) or worse, in a method name
  10. Declaring a parameter an Object or something too general to use and then down-casting the argument value received. Ninety-five percent of the time, the need for a downcast could have been avoided by using a different approach: overload the method, use generics, keep track of the type being passed by correctly structuring the control flow and data flow of the program, etc.
  11. Using flags and type codes instead of polymorphism in object-oriented langauges
  12. Checking for null AFTER dereferencing the value passed as an argument
  13. Failing to code defensively by checking arguments for correct values: boundary checks, null checks, size checks, and string length checks (empty or too long)
  14. Processing input from CSV (comma-separated value) data files and not handling the myriad special cases: apostrophe(s) in data, double quote mark(s) in data, commas in data, etc.
  15. Concatenating values directly into SQL statements instead of using prepared statements with placeholders and storing the values into it that way. Concatenation is generally an evil way to build SQL statements because of the reasons cited above for CSV data. Plus, has no one heard of "SQL injection vulnerability"?
  16. Calling System.exit method from deep within the bowels of an application, especially one that does not contain resource closing/releasing code in finally clauses of try statements.
  17. Overlooking the fact that ThreadDeath should never be caught (if you catch it, rethrow it) and usually neither should Interrupted Execution unless you consciously are handling it.
  18. C/C++ code that makes JNI calls but fails to check the JNI status after each such call as is required by the spec - and, boy, do they mean it!
  19. Violating the crap out of the architectural constraints/rules for EJBs.
  20. C++ code that throws something insane (like false) instead of a proper exception-explaining class that documents what when wrong; or on the flip side, using catch (...) to catch exceptions. Doing both in the same program really bugs me, pun intended.
  21. Putting code in a static initializer that can fail and not paying attention to the weird context it executes in that will vex anyone trying to debug what you wrote when exceptions occur. Try it - not so happy times, eh?
  22. Writing code such as listed above and then blaming the language, the GUI classes, the SQL server, the J2EE server, the compiler, the operating system, the JDBC drivers, and/or the third party software libraries for your application's slow and/or unreliable behavior.

Those are a few of my least favorite things.

In a more general vein, I have lost track of how many times I have seen code with bugs in it because someone copied code blindly from somewhere else that supposedly "did something similar" to what they were trying to do.

Copy-paste programming without an understanding any deeper than the name of a function and how many arguments to pass it can get your software product into a world of trouble!

The place I see this happen the most often as I work on Java programs is with concurrency issues.

Sun made it way too easy to create a thread in Java - and way too hard, relatively speaking, to detect/prevent cases where some yokel has violated a constraint.

Fortunately, you can check for this problem using AspectJ. There are plenty of good examples of how to do this in books, online articles/tutorials on the web, etc. Program the aspect in a .aj source file not a .java source file. Then, your application proper will not need to be compiled with the AspectJ compiler in general. Only when you want to have the aspect be in effect do you need to use the AspectJ compiler.

Hmmmm... I guess I have seen a lot of defects occur a lot of times and cause a lot of problems.

JohnnySoftware
Users don't read the manual, for that matter users don't read anything - http://www.joelonsoftware.com/uibook/chapters/fog0000000062.html
Maslow
@Maslow: Some of us read *parts* of the manual. And if you sent it to me on paper, I might read more!
SamB
A: 

Pretentious questions like this :-)

+13  A: 

I don't think any else has posted this - I hate "over inheritance" where the class hierarchy is 8 or 9 classes deep. I've seen code like this written by fairly experienced people and I think it's caused by combination of a naive view of what inheritance is for and an unwillingness to refactor base classes to make better use of encapsulation instead.

Ah, classic. I like to call this "OO-wanking".
Rob
Rob, I am SO stealing that.
JasonFruit
8 or 9 does seem a bit much -- how can you see from one end of the hierarchy to the other?
SamB
+1  A: 

My favorite one is that linked lists are quicker for adding and removing items in the middle than array lists. So many people fail to grasp the subtler concept and give the canned answer that everyone seems to propagate. This is in Java in particular, but the pet peeve applies to the concept in general. Say you have list.remove(2000) in a list of 4000 items, they claim it will be quicker in a linked list than in an array list. What they forget about is how long it will take the above call to find the 2000th item ( O(n) ) and then remove it ( O(1) ). The iteration will be done in Java code many times over. With an array list, it will be a low-level memory copy which, while is o(n) as well, will be quicker in most cases than iterating a linked list.

Well, what about removing every other element between the 1000th and 3000th element? A linked list can be modified in O(1) as many times as required while you iterate over it.
Michael Borgwardt
the basic peeve stands. In some cases a linked list is faster than an array. In other cases the array is faster. It takes a full understanding of what an algorithm is doing to make a statement about its run-time complexity.
TokenMacGuy
+20  A: 

Spelling mistakes.

Brannon
You do realize your code will still compile as long as you misspell consistently, don't you? ;-)
John MacIntyre
Not necessarily - http://www.javaspecialists.eu/archive/Issue046.html
Pete Kirkham
That's not a very good excuse for misspelling. even the simplest of IDE's make fixing bad spelling stupid easy to fix.
TokenMacGuy
+23  A: 

Oh, just remembered another one...

In C# and Java at least, '? :' isn't named "the ternary operator". It's the conditional operator. It happens to be a ternary operator (in that it has three operands) and it happens to be the only ternary operator at the moment, but that's not its name, nor does it describe the purpose of the operator. It's what many people call it, but that doesn't make it the correct name for it. (Many people spell my name "John", but it's still "Jon" however many people do that.)

If either language ever gains a second ternary operator (it's possible) then all articles/answers/books etc which refer to the conditional operator as "the ternary operator" will become ambiguous.

Yes, this is very much a pedantic peeve, but it still irritates me. I blame book and tutorial authors who've been spreading the non-name "ternary" for years :(

Jon Skeet
It's actually ? ::)
Ether
Jon have you ever considered that the more you learn beyond the rest of us, the more we're all going to irritate you with our inaccurate statements? ;-)
John MacIntyre
@Ether: Good catch - I'm so ashamed! @John MacIntyre: You have no idea about the huge *ocean* of my ignorance...
Jon Skeet
@Jon-Maybe so, but the gap between you and the rest of us (I know theres a gap .. I'm reading your book) ... is what I'm talking about.
John MacIntyre
SamB
@Jon, do other ternary operators exist, in any programming language? Just curious.
LarsH
@Jon, conversely to your pet peeve, I just read on Wikipedia that "As of version 5.3, PHP supports a ternary shortcut syntax expr1 ?: expr2 which is equivalent to expr1 ? expr1 : expr2, i.e. the condition is returned unless it evaluates to false when converted to a boolean value." In other words, the ternary operator is no longer always ternary. Another good reason to call it "conditional".
LarsH
PS. By "other ternary operators" I meant ternary operators that are not the equivalent of the conditional operator.
LarsH
Found a different ternary operator: SQL's "a BETWEEN b AND c". Got me thinking about why so few ternary operators. There are several reasons but this comment box is too small to contain...
LarsH
Another example might be C's "for" construct: `for (expr1; expr2; expr3) { statement; }` That's almost quaternary, though we're stretching the definition of an operator. XPath's "for" expression is closer: `for $a in expr1 return expr2`. But the XPath spec calls this a "for expression" rather than an operator.
LarsH
LarsH
Jon Skeet
@Jon: The fact that "the conditional operator" (or conditional expression) is its official name is a good point. But that's a separate issue from the issue of going from unambiguous to ambiguous due to the addition of another operator that fits the literal meaning of that name (which was the reason you gave for disliking "the ternary operator").
LarsH
@LarsH: No, I gave *both* as reasons for disliking "the ternary operator". Only the third paragraph talks about ambiguity. Both the second and the fourth talk about its name.
Jon Skeet
@Jon, yes, you gave other reasons. My comment should be corrected to say "(which was the reason you gave ... that I was responding to)". But you didn't support your assertions about the name, other than citing the operator's purpose, and its potential future ambiguity. So I interpreted the latter two as your reasons for saying that "ternary" was "not its name" / "the non-name". The "ternary operator" is *a* name of the operator (widely used and understood), however inferior it may be. So without such justifications, or others, your point about "not its name" is dubious.
LarsH
@LarsH: Just because it's widely used *as if* it's the name doesn't mean it *is* the name, IMO. I take the language specification as the canonical documentation here - the language designers get to name the operators, not the community.
Jon Skeet
@Jon, I would agree that the language designers get more authority than others to name things. However if the lang spec is your primary reason for disliking "ternary operator", you should mention it in your answer. Just because a name is not canonical doesn't mean it's a non-name. (But I agree it's wrong to say "ternary operator" is *the* name.) It may be just an inferior name, for the reasons given: canon, purpose, and potential ambiguity. I agree mostly about the first two, not so much about ambiguity (because "conditional operator" is potentially ambiguous too).
LarsH
@LarsH: I would still say that's not its name - it may be what many people call it, but that's not its name. However many people call Java's parameter-passing mechanism "pass by reference," that doesn't make it so. If I kept calling you "foobar" would that make it your name - or would it make me incorrect? Is my name "John" as well as "Jon" simply because people mis-spell it all the time? I don't think so.
Jon Skeet
@Jon: If you said foobar w/o context no one would know you meant me. I will agree that the statement "*Its name* is the ternary operator" is misleading or false. Rather, that's *a* name for it. "Syria" was originally a misnomer for Aram, probably confusing it with Assyria, but nevertheless Syria is now widely used and correctly understood as a name for that ancient nation. It is *a* name, however accidental its etymology. A name *can* be an incorrect name, but "the ternary operator" is a semantically correct name for ?:, since there is only one ternary operator in C.
LarsH
@Jon, I think part of our disagreement comes from a difference in the usage of "is called" between British and US English. When you say `'? :' isn't called "the ternary operator"`, my US ears object "yes people do call it that", but I think in British English "A is called B" is more definite: B is *the* name for A.
LarsH
@LarsH: I'll certainly agree that the "isn't called" bit of my answer is misleading. I'll edit :)
Jon Skeet
@Jon, thanks for being a good sport and for all this discussion. No hard feelings I hope. BTW if you had asked me before I read your answer what that operator was called, I would have said "ternary" out of mere ignorance. Now I know better. :-)
LarsH
+125  A: 

Yet another one: the popular language Sun released in the 90s is called Java, not JAVA. It's not an acronym. There's no need to shout. Grrr.

(I'm thinking of changing my middle name to "grumpy old man".)

Jon Skeet
And there I always thought it stood for “Just another vulgar annoyance.”
Konrad Rudolph
I'm a .net developer and for the life of me I can't remember if it's .NET, .Net or .net. MS marketing FTL there.
jcollum
I always use ".NET" which seems to be what MS uses... but I'm sure at least one series of books has it as ".net" which actually looks more visually appealing.
Jon Skeet
Just the same with Ada.
E Dominique
@jcollum - isn't DNS case insensitive? :-P
Jason Baker
Back in the day, using small caps for product names, trademarks, etc. seemed quite the fashion - perhaps this sort of thing is a throwback. "MAC" for (Apple) "Mac" ticks me off. Maybe IT is so full of acronyms people just assume every term is one!
cheduardo
Lol at gumpy old man Jon :-)
DoctaJonez
I write .Net like I would write it in C# - its not a acronym and you only capitalize the first letter of the word.
Callum Rogers
If someone who calls him/herself a Java programmer writes "JAVA", then I seriously doubt how well that person knows about Java.
Jesper
@Jon: Perhaps "Code Curmudgeon"? Frank Deford is fantastic (and witty) in his role as the Sports Curmudgeon, so you'd be in good company. E.g.: http://www.npr.org/templates/story/story.php?storyId=90413254
Argalatyr
@Argalatyr: I think that would involve being witty instead of just grumpy ;)
Jon Skeet
+1 JAVA is Sun's stock symbol, not the programming language
geowa4
Ditto people who say "C-Pound" and "Lin-Q". Sigh.
stusmith
@stusmith:LInQ, you meant?
Behrooz
-1 for pedantry...
advs89
LUA is another example. Do you always scream when you see the moon (lua in Portuguese)? You might be a werewolf.
Tadeusz A. Kadłubowski
@ E Dominique - since Ada is named after a person it would seem appropriate with one cap "Ada".
phkahler
Reminds me of companies looking for PEARL programmers
James Roth
@James: I like the ones looking for Sequel developers.
Steven Sudit
+1 for "grumpy old man"
James B
Same with 'Scrum'!
bacar
+5  A: 

That rebooting is a first line of defense solution.

This applies to DBAs too. I've encountered more than my share of programmers/DBAs that think nothing of rebooting a production system to fix things. In fact, I am cringing right now. =)

While this may fix things, it is tremendously disruptive and only used as a last resort.

Jauder Ho
rebooting is not a last resort. If it were a last resort, then it's sure to fix the problem (if at a terrible cost). Sadly, rebooting fixes very few problems.
TokenMacGuy
Try hitting it.
Gurdas Nijor
+8  A: 

Ignorance of a programming language's order of operations. I've had programmers ask me why something like 10 + 20 * 3 - 5 was resulting in 65 instead of 85. I take one look at it and shake my head. On a related note, I always try to use parentheses liberally.

Joshua Carmody
Isn't that grade 5 math?
John MacIntyre
Yes. But people manage to be ignorant of it anyway. Although I was using a simple example of a problem that is sometimes much more complex.
Joshua Carmody
I had fun writing an expression interpreter that did things all odd ball, like left to write, or every other.my favorite is http://en.wikipedia.org/wiki/Polish_notation
Ape-inago
It works the other way, too. I've seen "if (a and b) or c", which really bugs me.
Shadowfirebird
It probably doesn't help that people use terms like "order of operations", rather than explaining the concept of a syntax tree...
SamB
@SamB - The thing is though, that algebraic "order of operations" is a concept that is taught to everyone in high school, or maybe even earlier. So even somebody who is programming for the first time should understand the problem with the example I gave.
Joshua Carmody
@Joshua, the term "order of operations" is widely used, but it's a bit of a misnomer: it's really about how the evaluation of the expression is structured. Is 3 multiplied by 20 or by (10 + 20)? Even when order of operations (the * happens before the +) uniquely determines structure, the order is not the core issue. The difference can be seen in lazy-evaluation languages, where order of evaluation is independent of the grouping structure ("syntax tree").
LarsH
+3  A: 

Ignorance of the principles of reusable code and parameters. A ColdFusion developer I inherited code from had made several pages with names like getWallProducts.cfm, getFloorProducts.cfm, getCountertopProducts.cfm, getBacksplashProducts.cfm, etc. Each of the pages was absolutely identical except for the WHERE clause in one SQL query.

Joshua Carmody
I see a lot of this. Pulling those out can be one of the first steps in an awesome refactor. My eye actually pulls towards blocks of code that has a similar outline--instant refactoring fun.
Bill K
+31  A: 

Using string concatenation rather than parameters for SQL:

v_sql = "select cust_age from customer where cust_id = " + v_cust_id
RussellH
On a related note, it's possible to do use dynamic SQL with parameters with sp_executesql...
Brian
i'd use parameters for SQL as long as i can see the final `INSERT`, `UPDATE`, or `DELETE` that will be run by the server. Without any sp_executesql.
Ian Boyd
0;drop table customer;--
Behrooz
+11  A: 

Ignoring all performance aspects for the sake of quick and dirty code. We all know the axiom "premature optimization is the root of all evil". However, there's a middle ground between premature optimization and writing code with abysmal performance characteristics.

No, you don't need to spend hours tweaking your SQL queries to wring an extra millisecond out of them if you're running a tiny application with a mostly idle system, but you DO need to avoid things like "SELECT * FROM table" just because it was easier to code it that way. Things like this work great in a test/dev system, but what about in the real world where someone will be running with 100 or 1000x as much data in the db? Same goes for any code you write.

Take performance into account enough to recognize when you're artificially creating a bottleneck. This is an area where an ounce of prevention is definitely worth a pound of cure...

Jay
And the idea that developer time (saving a couple of minutes once) is more important than user time (having a 30 second delay hundreds or even thousands of times a day).
HLGEM
Maybe the problem is that the test db doesn't have enough data?
SamB
Actually, they tell me that the correct translation is "the root of all *kinds* of evil".
SamB
+25  A: 

My code is so clear I don't need comments - that drives me nuts. No matter how good you are or how clean the code, comments are still helpful. Even with great variable names, clear formatting, and avoidance of "clever" hacks, sometimes it can still be unclear why code is written a certain way. Maybe you make use of an API such that's not readily apparent why you need to code something a certain way. Maybe you're testing something with unusual conditional statements that wouldn't be clear to another programmer. Whatever the reason, it's good practice to leave comments whether for yourself or someone else, that explain anything that's not very obvious, standard code.

At an absolute minimum, it's helpful to include things like function/method comments that explain what parameters are passed and what return value is expected as well as potential error conditions. Failing to do this because "my code is clear so I don't need comments" is just being lazy, ignorant, or both.

In a similar vein, deciding documentation isn't important because it's boring - that just results in a high "bus factor" where the loss of a single person can cripple the ability for the team to maintain code. This is great for job retention, not great for smooth development, and especially terrible for an open source project where the sharing of the code is an integral part of the ecosystem. Code access is not a substitute for documentation.

Jay
Interesting how there are answers on this thread complaining about writing unintuitive code that requires a comment to explain it, and answers complaining about the lack of comments in code...
thecoop
In the days when functions were called `strtok` and parameters were called `p` or `n`, I could understand this attitude. Today, if I write a method `IEnumerable<T> WhereNotNull<T>(this IEnumerable<T> source) where T : class` then my colleagues are going to know that it returns a sequence without null references and there's no need to write some clutter about how the `source` parameter is the input sequence. Comments are sometimes needed, but they are for *excuses*. You put a comment wherever you have failed to make something self-explanatory, or where there's an ugly hack.
Daniel Earwicker
comments violate DRY - http://memeagora.blogspot.com/2008/11/comments-code-smell.html
Maslow
Occasionally you need comments. However, I always look for how to make the code clearer before writing a comment.
Loren Pechtel
Sorry Daniel, i'm gonna need comments to explain that one. i don't know what that code's doing. At least if there was the comment `//remove all null entries from source` i would know **what** it's doing; although not **how**.
Ian Boyd
@thecoop: I think the point here is that it's annoying when people *falsely* believe that their code is clear enough to go without comments... and that they shouldn't at least have some high-level comments to help people orient themselves without running the right margin to oblivion (thus decreasing readability considerably)
SamB
+60  A: 

I am a programmer and I do not need to know how to write a gramatically correct email. I also do not need to communicate with a customer on the phone - it is someone else's job. The only skills that matter are related to programming and nothing, nothing else.

Hate this!

petr k.
The email thing really bothers me. I really hate getting email from people and have no idea what they are talking about because their grammar is so bad.
Kibbee
what do you mean about grammar it doesn bother me atall
JasonFruit
-1, why on earth should programmer talk to customer? You don't hire programmers for this and it's usually a bad idea to have them doing this.
Kugel
@Kugel: Provided you hire a lousy programmer, then, well, it really IS a bad idea. Still, my argument stands, these skills are essential, be it being able to communicate your ideas to customers or your team. In the real world every programmer, once in a while, has to get his hands dirty and pick up the phone to know what's really going on on the customer's side.
petr k.
@petr k. Most of the programmers do not have very good people skills. Working in a team is completely different than talking to customer. There should be somebody in between, tech support or project manager. In my experience the programmers really dislike talking to customers directly.
Kugel
Oddly enough, almost every programmer I know uses great grammar in their e-mails. I don't believe this has _anything_ to do with being a programmer.
Wallacoloo
I don't dislike talking with customers. Customers dislike talking with me.
codeelegance
+7  A: 

Using global variables as a mechanism for parameter passing. I have seen this mainly in VB6 projects. When you open a project you are greeted with a page of global variable declarations. And the functions usually dont take parameters.

This sucks big time because:

  • it breaks encapsulation (the function now has external dependencies)
  • it is reinventing the wheel (there already is a mechanism for parameter passing)
  • it is usually undocumented (the caller needs occult knowledge)
+2  A: 

In C++:

Myth: std::getline is a global function.

Reality: std::getline is not a global function, but a function defined in the namespace std.

There is a common believing that things that are defined in namespaces other than the global namespace are all global. But in fact, that can cause confusion as to not knowing where stuff is really defined.

Here is an example where to avoid confusion: Instead of saying such things as

1) global int variables are initialized to zero if an initializer is omitted.

Say the following, which is more correct and probably is what you really want to say

1) namespace scope int variables are initialized to zero if an initializer is omitted.

Note that just because there is no "namespace... { ... }" around the global scope doesn't mean that there isn't a global namespace: This namespace is not user defined. It's implicitly created by the compiler before anything else happens.

Johannes Schaub - litb
If you pass a std::cin as the first argument, then Koenig lookup means getline "looks" global because you don't need to qualify the std:: on it. i.e. "std::string line; getline(std::cin, line)" will compile.
rq
rq, right it looks like it's a global function. but it isn't :) but actually that was just an example. i could have used any other function that's within some namespace and is not global to make my point
Johannes Schaub - litb
rq, in addition the fact that you can call a function without telling its scope does tell nothing about whether it's a global or not. consider struct s { void g() { } void f() { g(); /* g is a global??? */ } };
Johannes Schaub - litb
It just says that the thing "is in scope". It doesn't say from which scope it comes :)
Johannes Schaub - litb
Huh. I'd call that stuff global ... it's still reachable from anywhere!
SamB
@SamB, it's not reachable from outside `std`. Try `int main() { cout << "a"; }` and you get an error. You need to qualify it with `std::` or use a using-declaration/directive. That's what makes it very different from global names.
Johannes Schaub - litb
Johannes: the way I see it, that's just a long global name which it is possible to abbreviate under certain circumstances...
SamB
+14  A: 

In C and C++:

Myth: Arrays are just pointers

Reality: Pointers are very different. Arrays are converted to pointers implicitly and often.

An array is a block of elements, while a pointer points to such a block. As this simple observation shows, they can't be the same. And an array also can't be some special kind of pointer, because as it is a block of elements, it doesn't point to somewhere.

Nevertheless, I often see people write that arrays are just pointers pointing to a block of memory. That yields to the fact that people try to pass arrays like if they were pointers. Two dimensional arrays are tried to pass like

void myarray(int **array) { array[i][j]...; } // wrong!

while believing if they have two dimensions, they have a pointer to a pointer. In reality, an array itself consists of the elements, it does not point to them:

int a[4][3]; sizeof(a) == 4 * sizeof(int[3])

There are many contexts in which one needs to address a certain element of it. This is where it converts to a pointer implicitly (i.e without programmers writing it). When passing the array to a function, the function receives a pointer to the first element that points to the array. That pointer is made up by the compiler as a temporary. The two dimensional array of above, would thus be passed like this:

void myarray(int (*array)[3]);

Which makes the parameter a pointer to the first element of it, namely a pointer to the first 3-elements array.

Arrays in function parameters

The programmer may declare a parameter to be an array, like in the following example.

void f(char s[]) { }

This will confuse the crap out of a programmer, at first. Because as the programmer works with the parameter, he finds out that it is actually a pointer. And he is right - it is a pointer, despite being declared as an array. The compiler doesn't care that you told him it's an array, it will make s a pointer anyway. As a consequence, any size you specify in the brackets is silently ignored, too. In this case and only in this case, s is a pointer and you can say it points to memory, because it itself does not own the data you access through it.

Variable Length Arrays (VLA)

Note that C99 introduced variable length arrays, which your compiler may silently support, too. These arrays have a size that isn't known at compile time. Their type is called a variably modified type, and these arrays can be used only for parameters or non-static, local variables (automatic storage duration). Here is an example

void f(int n) {
    int a[n];
}

In this case, the rule is the same as for non-variable length arrays. The array here will convert implicitly to int* (its element type) when required - just as with the other array above. Also, sizeof behaves correctly, and would yield in this case

sizeof(a) == n * sizeof(int)

They are not declared as pointers just because they have a size determined at runtime!

Related answers

Johannes Schaub - litb
Or more type safe: void myarray(int (*array)[4][3])
Brian R. Bondy
I wish you could favorite answers for questions with this many answers.
Brian R. Bondy
@Brian: Amen to favoriting answers!
SamB
+11  A: 

Many programmers seem to think that their only audience is the compiler, when code is really written for other programmers. Compilers have no taste. It's an odd kind of prose, but it's for people to read. Tell me a story.

Ishmael
+1 for "tell me a story". Amen, brother!
Drew Hall
Yes, yes, yes! I just read through four pages of these (generally very good, but numerous) comments because I was specifically trying to see if anyone had said this.
Joe Carnahan
+18  A: 

"Runs on my box"

TJB
"But we will not ship your box..." ;-)
vobject
In my field, "runs on my box" is used to convince an user to try and see if there couldn't possibly be a user error, when you know pretty much for sure that the user did something wrong). Every once in a while some user will report an error and demand that you fix your stupid software, and 9 times out of 10 he won't even consider that he might have made a mistake.
Sylverdrag
+53  A: 

When a developer has no idea how to set up their own machine.

I've worked for a few companies now where a programmer is hired and the machine they are given is generic so it needs Visual Studio, SQL, etc. set up on it. Even when handed install media and/or a place on the network to get the installers from, many developers cannot figure out how to install the tools they need or have no idea what they need to install.

Worst case scenario this is proof that you have hired the wrong person, best case scenario they're actually a brilliant programmer who just so happens to have never had to install their own tools before. It pretty much cements the idea that they don't code at home.

Some of this though could be because I'm a snot who doesn't trust others to set things up right

IT: "So, what all do you need installed on this thing?"

ME: "Please just let me have the machine already, I'll put what I need on there"

Schnapple
+1000+ I headed an development team way back when (yuck) and one thing I made all my coders do was setup their own machine from scratch. I knew I had a problem if someone couldn't do it or took too long.
Stu Thompson
It depends on where you work. When I first started my job, I sat around for the first day doing virtually nothing because I had to wait for the IT guy to come around and install all my software. I would have been happy if he had just left me the media and let me do it!! But the media is sacred, I guess, not just anyone is allowed to touch it!
Chris Dunaway
Never mind installing the software. The first company I worked at, the IT guy gave me a motherboard, a dirty cream IBM PC/AT case, 8 MB (!) of RAM, a mouse/keyboard with dust on them, and pointed at a shelf with some old hard drives on it... I ordered another 8 MB so I could try out this new "NT" thing. Also I treated myself to an 80 MB (!!!) harddrive. Kids today, you've no idea what it was like.
Daniel Earwicker
First job out of college at one of the bigger digital agencies, they had just acquired one of their local rivals. i had never previously opened a computer case except to look in awe. they put me in a room with all of the acquired hardware, told me to build as many machines as i could, take two of them and install that new "linux" thing on one and that new "NT" thing on the other to be my workstations. I only let the magic smoke escape on one box and ended up with a pretty solid understanding of both the hardware and software.
ken
+1 because 1. I love your avatar and 2. seen a lot of this.Fortunatelly I've been allowed to install my own machine on my desire.
stefita
+3  A: 

The difference between "I need to get this done" and "I need to get this done here" (as in I need to add code in this specific location). By far the biggest issue I have encountered in scaling systems up is where code written by various people puts a lot of logic that should live in separate levels of abstraction in a single place.

MSN
+3  A: 

Copying code from another application they've worked on containing the functionality they want to use, and not changing the variable names (that only make sense in context of the original application) because "the client will never see the code."

Oy. Do I try to explain that the client can and will see the code in any variety of instances, or that this will drive fellow team members crazy/confused, or that the PM will have a conniption when she requests full documentation of the system and sees processes named after other clients' products?

aesdanae
+3  A: 

Always starts by writing concrete classes instead of starting to "program by interface".

kal
I've seen a few variations of this. A good one was never create an abstract class that you will have less than three concrete subclasses. Another follows the same template, Code must be reused at least three times before it can be called generically reusable.
TokenMacGuy
+3  A: 

Cowboys who just want to write code before they have finished understanding and then debugging their business rules & requirements. Once you have finished slashing your business requirements and rules with Occam's' Razor the code, modules, libraries, data structure etc. that you need will be bleedingly obvious.

Horse first, then cart.

CAD bloke
Try it when this is type of development practice is actually *policy*.
David
+18  A: 

Reinventing the wheel.

As in: instead of using 30 minutes to look up a standard, textbook-ish solution (using an actual textbook, Google, or whatever) – first use 25 minutes to design your own solution (because it's somehow less boring; see also NIH), then use another 25 minutes to make your solution compile, then use 1:45 to prevent it from crashing when you just try it, then use 3.5 days for some additional fixes based on integration testing (or whatever it is that you do), and finally spend weeks processing bug reports and log files / stack dumps / whatever that you get from the customers.

Pukku
Worse than that are "technical" managers who discourage use of existing solutions that weren't "written here".
JasonFruit
Some of the best solutions are literally found in my old textbooks. I'll never toss the good ones.
TokenMacGuy
For some reason it's considered normal for Haskell beginners to re-implement half the Prelude and then become delighted when they find the functions they've written were actually already there... maybe because some of those functions are really damn obviously useful and simple to write, but not so obviously named?
SamB
+47  A: 

This is a real, live, production example that I uncovered in code that I needed to maintain in my professional capacity.

I printed it out and kept it on my wall as a trophy for some time.

function isValid(form){
    if(checkUser(form.username))
    {
//        if(checkPass(form.password))
//        {
            if(checkName(form.name))
            {
                if(checkCompany(form.company))
                {
                    if(checkCompany(form.email))
                    {
                        if(isNotEmpty(form.phone))
                        {
                            if(isNotEmpty(form.address))
                            {
                                if(isNotEmpty(form.city))
                                {
                            //        if(isNotEmpty(form.state))
                            //        {
                                        if(isNotEmpty(form.zip))
                                        {
                                            if(isNotEmpty(form.country))
                                            {
                                                if(isNotEmpty(form.url))
                                                {
                                                    if(isNotEmpty(form.payto))
                                                    {
                                                        if(checkForm(form.terms))
                                                        {
                                                            if(checkForm(form.spam))
                                                            {
                                                                //alert("Thank you form is processing");
                                                                return true;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                   // }
                                }
                            }
                        }
                    }
                }
//            }
        }
    }

    //alert("processing failed");
    return false;
}
chaos
the true icing is the carefully commented close braces.
TokenMacGuy
Especially since, despite the obvious care taken, the outer set of commented braces doesn't match.
chaos
But you have the power to refactor this mess.
Walt Gordon Jones
I agree. This would be much cleaner without the braces, and then you don't have the danger of commenting out the wrong closing brace.
James M.
@James M.: careful with humour: remember this is a reference site, and someone unclued might think that the only thing wrong with the abomination above is that it uses redundant braces.
Adriano Varoli Piazza
AAAAAAAAAAAAAHHHHHHHHHHHHHHH!!!!!!!!!!!!!
MusiGenesis
My Eyes!! Didn't this programmer know anything about boolean algebra???
yelinna
Oh my word. This could almost pass for obfuscation.
Kyle Rozendo
You sir, are a prince amongst men for not quitting on the spot.
SnOrfus
Aw, thanks. I was brought on largely to clean house on a codebase that was originally written by a guy whose grasp of Perl was such that, if he needed ten related values, he used variables `$a1`, `$a2` .. `$a10`, though, so really it was all par for the course.
chaos
Oh My God... This one is really scary.
stefita
My God .. Its full of stars!
Tim Post
My God... it's full of *stupid*!
chaos
In Visual Basic 6, this improved performance by about 20% on a function called a lot of time. VB6 has no short circuit so this was the only way to return after the first false is match.
Alex Bagnolini
@Alex. Yes, you can learn a lot of bad habits from VB6.
Jeff Davis
@Alex: One of the many reasons VB6 lies on the trash-heap of history. I said for years they'd have to break it to fix it, thank Jebus they did.
Binary Worrier
Jeeze, never heard of newlines in the conditional?
SamB
@Alex: I suspect that it can be done without several monitors' worth of indentation, however ;-)
SamB
@Alex Bagnolini:in VB6 you can GOTO falsepart if the condition is not met.
Behrooz
+40  A: 

I'm not a perfect programmer and there are a lot of things I don't know. But for all my imperfections; I care, I do my best, and I always try to figure out how to do it better next time.

.. but programmers who just don't care drive me nuts.

John MacIntyre
+26  A: 
  1. The programmer who thinks that I have no clue how memory management works because I've been working in a language with a garbage collector for 8 years.

  2. The n00b who we just hired that hasn't seen a language without a garbage collector telling me I'm too uptight because I worry about how memory is being allocated and freed.

In our case (long running, high load processes), it's critical we pay attention to how much memory we're allocating and when that memory is going to be freed. Just because the actual collection will be done for me doesn't mean I can bury my head in the sand.

Dan
+15  A: 

Anyone who calls "SQL Server" "SQL". One is a product of Microsoft, the other is not.

Jim Blizard
And the perversity of calling the product "SQL Server". I had one dope reboot the machine when I told him to restart SQL Server.
Joshua
That's good. If the product is SQL then the box it's running on must be "the SQL Server". Uggh.
Jim Blizard
"es queue el server" And that's my final answer.
Ian Boyd
@Joshua - if you go there, we'll get into the perversity of naming "Windows", etc. etc.
LarsH
+8  A: 

The most annoying thing I have come across are developers that truly believe that if the code builds then it is working and production quality!

John Hunter
Yeah. I think that only applies in things like Coq... and then only if you have the types right!
SamB
+2  A: 

My Pet Peeve?

Undocumented code. All the rest can be solved or worked around.

Vordreller
Except for *incorrectly* documented code.
David
+2  A: 

Most of my "favorites" are already up here, but here's one I just ran into again last week (from an otherwise decent programmer):
Traversing the ENTIRE XML DOM tree, when searching for a specific node (or nodes), using methods such as Children[], NextSibling(), etc.... instead of a simple call to SelectSingleNode (or SelectNodes) with a simple XPath expression. This of course resulted in many recursive calls, not to mention HORRENDOUS performance...

Of course, this can be generalize as "not using code the way it is meant to be used".

AviD
+2  A: 

Unreadable code. And large, flat LabVIEW block diagrams that take a couple thousand pixels in both directions. And bland and ugly UI's. And noisy workplaces. And knowledge silos. (What? we can only have one?)

PaulG
You can have as man as you like, but you are advised to use a separate answer post for each discrete response.
TokenMacGuy
+1 for noisy workplaces.
Ant
+5  A: 

I find that all too many business application programmers are abysmally ignorant of data meaning, database design and data access. Virtually every business application has a database backend, a programmer who doesn't understand how to efficiently and effectively query it will have a badly performing product that users don't want to use.

A developer who doesn't bother to learn database design principles before actually designing a database will cause problems in the applications for years to come.

Further their ignorance often results in data integrity issues - meaning the data is unreliable or meaningless and thus the application is irrelevant or queries that are so poorly designed they provide the wrong results.

Another problem is the developer who thinks that saving a minute of his precious development time is more important than wasting hours of the users' time every day. Programmers should spend all day every day for a week actually using their applications. They would change how they design them.

HLGEM
+1 for 'eating your own dogfood' advice.
TokenMacGuy
+3  A: 

Bad or incorrect knowledge of data structures.

"I need to find all untranslated strings in our source. I'll just build an array of all the strings, copy it and compare them to eachother."

Congrats on your n-squared solution. Some folks with modern CS degrees don't even know what a hash-map does. Or why you would ever use one as opposed to an array or list etc...

Drives me nuts.

Trey Stout
really? they only briefly touched on it in my school, but they did go over it. what bugs me more is all these CS buggers that have no interest in programming beyond school.
Mark
Why not just build one array, sort it, and check to see if any two consecutive entries match?
Robert L
+10  A: 

Professional programmers who don't understand free software (open source) licenses, and yet either use the code without regard to what the license says, or make blatantly false statements that simply reading the license in question would fix. Now, there are a lot of licenses out there, so it's not necessary to understand the intricacies of every single one, but if you are going to use or discuss one of the most common licenses (GPL, LGPL, BSD, or MIT), you should at least have a decent idea of the basic requirements of that license.

I have found GPL'd software in proprietary code bases with all license notices stripped off. I have seen people assert that because it's free software and they have the source code in front of them they should be able to do whatever they want with it.

On the other hand, there are the people who make blatantly false statements about licenses without having ever actually read the license in question; for instance, asserting that the GPL is viral, or that your code must be under the GPL if you link to GPL'd code.

Just for the record, since I have seen a lot of this confusion recently, the GPL doesn't force you to do anything; it does not infect your code. It is simply a license; that is, it is a set of terms which, if followed, give you permission to copy and distribute that GPL'd code. Those conditions include having no restrictions beyond those of the GPL on code you distribute that is based on (which basically means linked to) the GPL'd code. Your code can be licensed under any GPL compatible license, and if you remove the GPL'd code (including support for linking to it, unless it's the LGPL), then you can go back to using any license you want.

Brian Campbell
If your program links to a GPL library, then your program must use a GPL-compatible license, i.e. you must make your source code available. This is considered a feature of the GPL by those who use it, and a drawback by those who are writing closed source code. There is another license for open source libraries, the LGPL, that permits closed source programs to use these libraries. This is considered a necessary compromise in certain cases.
Kevin Panko
@Kevin: that is AGAIN a case of misrepresenting the GPL. You need to (1) link your program against GPL code and (2) distribute it, otherwise the GPL doesn't apply. Same thing with LGPL. Both cover _distribution_, not _use_.
MSalters
@MSalters: You're splitting hairs here. Who writes a serious program without the intent of distributing it?
Billy ONeal
@BillyONeal: thousands, if not millions of companies. For internal use, you see.
MSalters
Uh, the GPL is an awful long read...
SamB
+2  A: 

In a dynamic language, not using Duck Typing and littering the code with tonnes of switch statements!

ewakened
This pattern is excellent, and should be the way forward, but it still seems kind of like a new-ish concept (the term at least), so I tend to forgive this, so long as the solution isn't too awkard, such as using multiple inheritance or interfaces or adaptor classes or some such in a polite way. Endless switch statements aren't elegant in any case, and annoy me plenty.
TokenMacGuy
+4  A: 

Comparing floating point values from different calculations without using an epsilon.

Example:

if(sin(x) == cos(y)){ /* do something */ }

instead of

/* here epsilon is taken as 0.001 */
if(abs(sin(x) - cos(y)) <= 0.001){ /* do something */ }
Vulcan Eager
Can you give an example of how you'd do this?
p.campbell
Hmm, wouldn't it be better to use a named constant rather than embedding a magic number? (Presumably "epsilon" would be part of the name.)
SamB
@SamB - I agree completely.
Vulcan Eager
Well said! Float point operation is generally misunderstood.
Juliano
+7  A: 

Coders who don't know the advantages of keeping code within 80-columns.

Vulcan Eager
what ARE the advantages?! depends on your development team no? unless you've got some oldschool console whores on your team, I don't get it. sometimes its better for readability NOT to break up long lines
Mark
It allows you to keep two related code windows side by side like .h and .cpp. And it's also easier when you're viewing code on a console or a printout.
Vulcan Eager
Here's another scenario: when I need to view the MouseDown, MouseMove and MouseUp handlers side by side!
Vulcan Eager
It forces you to ask yourself "why am I doing all that on one line?"
bmb
Adding to @bmb: It reduces the number of things that you can possibly do on one line, thereby reducing the number of things that a reader of your code needs to keep in his/her head at once while reading each line of code. It also facilitates debugging. If you just wrote the code, you probably think it's sweet that you just chained those four function calls, but the person who reads/debugs it later will thank you for storing each intermediate result in a well-named local variable.
Joe Carnahan
I like being able to have several emacs panels side by side on my widescreen monitor. Also, legibility guidelines for typesetting often propose a maximum of between 60 and 80 characters per line, because this is a comfortable amount of text to consume in one pass of the eyes.
Jon Purdy
+5  A: 

I have many, but this one makes me want to hurt myself:

"...but it was working before."

karim79
As an extension to this, "You *must* have broken it, because before I merged in your changes, it was working!". But thinking about whether my "correct" changes just unhide bugs he/she made would be out of question ... sigh.
phresnel
A: 

Users of any application - or device - who call you up and say "It doesn't work".

Paul Morrison
-1 Programmers who blame the user.
Tom Leys
Well, that's not nearly as bad as emailing you or filing a bug report saying that. If it's on the phone, that's a perfectly valid way to begin a troubleshooting session!
SamB
+9  A: 

The Tabs vs. Spaces debate. I personally don't care which to use (I'm not picking any sides - they all have their pros and cons, and modern IDEs will do whatever policy is selected for you), I just hate working on a project where it is not consistent between developers, and I'm constantly asking myself "do I need to switch my editor policy for this file?", and toggling my "show whitespace character" setting. If you're ever starting a new project with new developers - pick one, put it in your coding style guidelines, and make sure everyone sticks to it, or watch out when you have to modify someone else's stuff - and don't complain if you join a project and the current policy is different than what you prefer and try to prove that "tabs are better than spaces", or the reverse - it'll just make everyone mad, make you sound arrogant, and you'll be bantering over something that is not productive. You can banter about it when you're deciding which to use at the beginning, but after that - leave it alone!

Oh - if you prefer to use tabs - use it only for indenting, and use spaces for alignment. Those who use tabs for alignment bug me.

paquetp
TABS! :) And nothing for "alignment". It doesn't need to be pretty, just logical.
James M.
Personally, I don't care. If I see tabs in a file, I usually assume I can use tabs. If I don't I assume no tabs are allowed. If I make a mistake, and somebody bitches about it I tell them to change it. It's not like it's a shuttle launch procedure. The only thing I cannot stand is talking about one and the other, and "which are better" discussions. So +1 to you.
ldigas
+5  A: 

Programmers who do not unit test their code and then get upset with QA when bugs are found which obviously demonstrate this fact.

ssakl
+14  A: 

When people don't know what "Unit Testing" means

I've heard the phrase Unit Testing thrown around and since I'm a developer I think of stuff like Nunit and so forth but then it hit me that when I hear QA and Managers say "Unit Testing" they're referring to actually just doing the testing, maybe from a set list ("do A then B then C and the output should be D, if it's not then shit's broke").

So then to avoid confusion I started using the phrase Automated Unit Testing to refer to what I'm calling Unit Testing as a developer - which worked fine right up until the managers thought that I was referring to generating Unit Tests (the lists, I guess) automatically and the QA people thought I was trying to automate them out of a job.

I guess I'll just call it "NUnit Tests" and be done with it. Well, until we get migrated to TFS at least.

Schnapple
+2  A: 

The remark "reinvent the wheel". Look around you, do you see one size of the wheel fitting all?

Marco van de Voort
There's nothing wrong, necessarily with reinventing the wheel. The question is, is that really what you're up to? If you are serious about researching the technology of wheels, and get a good feel of what makes a good wheel and a bad one, then there's nothing wrong with expending engineering effort at improving or rethinking it. On the other hand, if you want a cabinet that rolls, spend your energy on the cabinet, and use an off-the-shelf wheel.
TokenMacGuy
The problem is when *round* wheels of appropriate type are available already, and people go around inventing *square* ones...
SamB
So maybe then the mantra is correct. It is the difference between inventing (wheel is round) and making a specific one. That is hairsplitting though. The point was that the mantra is used wildly inappopriately. The complexity of buying stuff and services (and worse, characterizing it that it furfills the destiny) is very underrated
Marco van de Voort
+5  A: 

When people say "Oh, this is so simple, I know it works, there's no point of writing a test for it".

They are completely missing the point of the test, it isn't just to verify that it works, it's to verify that it still works when people make changes down the road.

TM
+4  A: 

People who think "Real-time" is fast.

Usually it takes more time to make sure that tasks are achieved in time.

call me Steve
but real-time things work better if they are fast.
Behrooz
+5  A: 

Ignoring the latest community libraries/techinques, and continuing to develop software the way people did ten years ago.

pomarc
In my experience with large companies, you can count yourself very lucky if techniques are only 10 years out of date.
Michael Borgwardt
Good point, however, sometimes the difficulty of code maintenance, particularly on legacy systems, can affect how you attack the code. Michael Feather's "Working Effectively with Legacy Code" recognizes that a system that "can't be easily thrown into a test harness" can force the developer to proceed in a less than optimal manner. This does not mean the dev should not attempt refactoring, but time constraints, cruddy massive systems, and clueless leaders being what they are, sometimes driving another mile before getting the oil change is an acceptable approach.
Bernard Dy
Hmm. Not *all* of the latest techniques are necessarily that great... though not-invented-yet is probably not a good attitude unless the technology in question is, in fact, not ported to all your target platforms yet...
SamB
+9  A: 

JavaScript is the same as Java right? They both have Java in the name, so they must be the same.

Tim
I searched all pages to find this before posting it myself. It's so frustrating to repeatedly explain this one to people. This is what I always tell them: http://stackoverflow.com/questions/245062/whats-the-difference-between-javascript-and-java/245068#245068
Michael Haren
I've never met a programmer who didn't know the difference.
JohnFx
Well the script version has a syntax that sorta looks like Java. But then again Java sorta looks like C.
Ian Boyd
Hey, I once thought HTML was called Java, because I had heard on the radio that Java was the language of the web ;-)
SamB
Ha ha! What radio station are you listening too?
Tim
Java is to Javascript as cat is to catastrophe
sum1stolemyname
+13  A: 

People who really believe that Object Oriented Programming is the end all be all of programming, and completely disregard anything else. I'm a Clojure and Haskell programmer. People like that are extremely annoying, and extremely blind.

Rayne
Couldn't agree more!
ldigas
I tihnk it's a bit unfair to call Clojure and Haskell programmers extremely annoying and extremely blind. They merely hit the Post button too quickly :P
MSalters
I think you misunderstood me. I was calling the OOP fanatics extremely annoying and extremely blind. Clojure and Haskell programmers tend to be more enlightened.
Rayne
@Rayne: read again what you wrote, then read again MSalters comment.
Sylverdrag
@Sylverdrag And? I understood his joke the first time.
Rayne
+2  A: 

Revert 'small' refactoring because running the unit tests before committing takes too long.

crauscher
+5  A: 

People who know only one language, that "can do everything". And every problem they face as if they are using their "can do everything" language and never stop to see what else can bee done in the others paradigms.

Chocolim
+3  A: 

My peeve is programmers that don't consider the memory footprint of their software. They develop code using STL or other data structures and they automatically pick a set or map instead of a vector or deque.

Gnome software does this a lot. One of the data structures provided is a GTree that uses GNodes that have five pointers each! Some people use this to store data items smaller than the nodes!

Now imagine what this does when built with 64-bit pointers.

Zan Lynx
Well, it means a 40 byte overhead per node - that's 4MB for 100,000 nodes, or less than 1% of the total phyisical memory (otherwise, why would you have 64 bit pointers?). Worrying about that is purely premature optimization.
Michael Borgwardt
It is the difference between 1 MB notification bar programs and 5-10 MB programs.
Zan Lynx
Also, I used to run 64-bit Linux on a 1GB system because I wanted to use the larger/more registers of the Athlon-64.
Zan Lynx
+1 - Avoiding premature optimization just means waiting until you know how to prioritize optimizations, but too many people use the mantra as an excuse to ignore resource usage/waste altogether. And @Michael Borgwardt, it's a bad idea to make assumptions about "total physical memory" unless your app will own the box. Other poorly-written software might have already eaten up the other 15.999 GB.
James M.
@Michael - The cache in the processor is measured in megabytes. Memory bandwidth is the new bottleneck.
Tom Leys
+3  A: 

When programmers confuse classes and instances when talking about systems. The word object often gets used ambiguously to refer to classes and instances in both casual and formal conversations about architecture and software engineering.

sean riley
+1  A: 

For me the worst thing someone who wants to be a programmer can ignore is the need of commenting. Everything else doesn't matter so much, as in a normal workplace somebody else can fix the error. While those issues may be time consuming, not commenting can make any of the necessary fixes or changes take much longer than necessary since any developer would have to figure out what the code does before they can make any changes. Some would say that this isn't an issue if the same developer who wrote it is making the changes, but even then people won't recognize what the code does. This is why commenting is so important. Sadly, I know of a graduate director who has only ever written one comment in 147,000 lines of code and most of it doesn't work the way it should.

indyK1ng
A: 

Emulating sets with dictionaries, or failing to see when a set would be appropriate.

Setting the value in a dictionary to some random value instead of just using a set data structure.

d[key] = 1 # now `key` is in the set!!

Or general ignorance of set data structures, using lists/arrays instead.

Sets offer O(1) lookup and awesome operations like union, intersection, difference. Sets are applied less often than they are applicable.

FogleBird
I still don't get why .net lacks a Set class in the BCL... I use them almost as much as true maps//dictionaries.
Robert Fraser
@Robert: System.Collections.Generic.HashSet
Dour High Arch
@Dour Only in .Net 3.5 and later, which is fairly recent.
dbkk
A: 

Version control.

+24  A: 

Asking a perfectly legitimate question on Stack Overflow that I and numerious programmers would love to discuss and debate over, only to have it closed within minutes by trigger happy individuals.

Marc
+7  A: 

Myth: End-users can all think like programmers, or else they're incompetent.

Reality: No, they can't. And no, they aren't.

The type of behaviour a programmer expects, versus the type of behaviour an end-user expects, can be vastly different. Trying to explain the rationale so that they understand what's happening and why, rather than fixing the "bug", is not always the ideal method of dealing with this.

If the end-user needs any degree of programming experience to use your program, chances are you're doing it wrong.

goldPseudo
+9  A: 

Developers that go "solve" the customer requirements by creating some reusable framework or system that is completely unnecessary for what the customer asked for.

I find this usually done by very intelligent, but bored people would who much rather work on something interesting to them then actually solve the problem for the customer.

Jon Clegg
-1 it's not their fault that their job is boring. I'd blame management for that.
hasen j
Maybe they should just get to look at more problems at the same time, and pick several to kill with the same stone?
SamB
otherwise known as "The inner-platform effect" (http://en.wikipedia.org/wiki/Inner-platform_effect)
JohnFx
+24  A: 

Programmers who use strings as a universal variable type.

statenjason
I especially dislike seeing people use strings to do what booleans are meant for (`someCond = "true"` or `someCond = "yes"`)
Wallacoloo
Or using integers as booleans
Bart van Heukelom
Using integers as booleans can be a habit brought over from C, which doesn't have actual bools.
statenjason
+10  A: 

Caught, but unhandled exceptions

Nothing bugs me more than coming across a try...catch block that doesn't have any exception handling or propagation.

Example:

Try

'do something here

 Catch ex as Exception

 End Try

Lack of proper exception propagation has cost our dev team countless hours of debugging.

JonnyD
Just be sure that you don't "fix" it, and 3 years later the customer encounters an edge case, that shows up as an exception in their face - lest the clenched fist of a grumpy customer come crashing down on your house.
Ian Boyd
Well ... you at least want to make sure there is a human-comprehensible explanation of the exception in the dialog box...
SamB
+3  A: 

Claiming that things like if/else vs. switch will obviously improve the performance of a program.

Because it's premature optimization, but also because people making such claims don't know what they're talking about, and yet they feel the need to teach other people how everything works.

Other examples:

  • Thinking that you just have to add some mutual exclusion, and voilà you now have a faster program on multiprocessor machine. It's especially funny if the person telling you that synchronizes threads with busy waiting, and is proud of it.
  • Thinking that a garbage collector necessarily slows down a program.
Bastien Léonard
+4  A: 

Ignorance of one's own limitations. I can't stand it when someone thinks they know everything there is to know about a topic and give useless or harmful "advice" to someone else.

Ah... Second Order Incompetence. Nasty one that! It's so difficult to get those that are suffering from it to realise it.
Colin Mackay
A: 
  • comment your code

  • write unit tests

  • be userfriendly

Henning
Huh? Those are peeves of yours?
SamB
I think the question is misleading and was a bit different when I answered.I name the important subjects being ignored too often by developers - and this fact then, in turn becomes a peeve!
Henning
+10  A: 

Drag and drop programming.

My teacher once tried to show off some Ajax in ASP.NET. It started by talking about how the "Ajax would stop the postback of the HTML to the server". He said that Ajax is asynchronous because "The server doesn't have to wait for the client to respond". He also didn't understand that an Ajax request is no different than any other HTTP request. He basically thought it was the XML itself that was sending the request.

Of course I was a bit surprised. I then realized why he did not understand Ajax! He was just drag and dropping UpdatePanels and controls on the page. There is nothing wrong with drag and drop, it can save a lot of time and money. But it's no excuse to not understand the underlying technology, especially when teaching it to others.

MrHus
Just... Wow! That's shockingly bad.
Colin Mackay
Sir, you need to find a new school.
McPherrinM
I actualy hate those GUI builders. Even though it's taking longer to write the GUI code on my own, I have better control over my application and always know what's going on, because I wrote every single bit of it. Once I had to do a project for school using Cocoa Interface Builder. It was a really bad time for me :).
stefita
@pcampbell: What happened to you also happened to me when I was in college, and not only once. Fortunately those (bleep) they pass as teachers don't do any real world development. @stefita: Being myself a happy Mac user, I still don't understand how the Apple guys, the supposed UI geniuses, could come up with something like Interface Builder.
Eduardo León
@Eduardo: perhaps it is merely intended for marketing purposes, not for actual use?
SamB
A: 

Not putting the extra effort to be clean when committing code... Nothing annoys me more than people who commit print statements, extra spaces or end-of-line characters as a result of their debugging.

Matt
I do that.... allllll the time :)
Earlz
+3  A: 

Changing code, but not updating comments

I come across code sometimes that has evolved over time, but the people who worked on it didn't update the comments around the code - so that the comments refer to what was there before, and not the current code.

Misleading comments in the code are worse than no comments at all.

Jesper
+4  A: 

My pet peeve is poor variable naming! Having spent some time as a maintenance programmer, I can tell you that poor variable naming is pure Hell! You should never name things after yourself, after your pets, or after anything that does not relate to what it is and/or what it is doing in your code! I should never see anything like:

if (john == 0){
     return fido;
else
     return fluffy;

5 days from now, no one will know what you were doing, let alone 5 years from now!

Molex
I've seen a lot of this in my previous job- names like (php) $specialCustomerNameBratwurst... and there were much longer names, I can't just remember all of them :)
stefita
There really ought to be a sniglet for this syndrome. I maintain code which uses variable names i, ii, iii etc. That is the mark of a recovering fortran programmer.I try to name the variables and function names in my implementation plans, so as not to grind to a halt, when in coding flow.
EvilTeach
We had a developer that used names like Fizzle Fazzle and Fuzzle. When we were trying to debug a problem in the code, we had to go to him and ask what these variables represented. We also asked why he'd chosen arbitrary names for his variables. His response was "well, it really doesn't matter, does it?". I wanted to shout at him "WELL WE'RE HERE ASKING YOU NOW INSTEAD OF FIXING THIS BUG, AREN'T WE?"
Scott Smith
@Scott: maybe you should have sent him back to FizzBuzz ;-P
SamB
@stefita: wow! that's two different variable name syndromes -- the way-too-long syndrome and the "might as well have called it x" syndrome. (Actually, I *do* call a lot of my variables that -- mostly when they don't mean much in the context of the function I'm writing.)
SamB
+7  A: 

I didn't/You can't because the house rules of development say you can't!

I can't count how many times I've been told I couldn't write something a certain way, or been told by someone that they didn't write something a certain way, because some preexisting "house rule" said it wasn't allowed. I don't think anything irks me more than encountering a "rule" that prevents me from implementing something in the most efficient, concise, effective, clear, maintainable way possible because it is either:

  1. Not a "standard" for the company
  2. Not allowed because of some wiley rule...usually written decades ago
  3. Not proper coding style for Java, despite the fact that its C# code
    1. Starting type members with a capital...?
    2. Using properties...??
    3. Using LINQ or lambda expressions, or anything 'functional'...???
  4. Not kosher because its "too new" .NET technology, despite the fact that its been out FOR YEARS, and has been thoroughly vetted by the monstrous Microsoft developer community of MILLIONS.
    1. .NET 3.0/WCF/WPF
    2. C# 3.0 features: LINQ, anonymous types, lambda expressions, etc.

These kinds of things just REEK of ignorance. People get so attached to their "purist" or "conformist" ways sometimes that they miss the long- and short-term time, effort, and money saving advantages that are just dangling right in front of their noses.

C# sucks because Microsoft destroyed its original intent as an object-oriented purist language.

I get this one from Java OO purists a lot (no offense). No matter how much I stress the point, provide solid resources (i.e. Eric Lippert's Fabulous Adventures In Coding), or actually demonstrate it...some people refuse to accept the simple fact that C# is a language designed for component development. It was never designed as an OO purist language in which functional features such as lambda expressions, the var keyword, LINQ, etc. are bad things that ruin the language.

Wake up, people! C# was never designed as a pure object-oriented language. Use it for what it is, and reap the benefits!

jrista
Hmm ... don't most decent OO languages have something like lambda anyways? Take, oh, Smalltalk for example...
SamB
Some do, but I wouldn't say most do. Smalltalk is a good example of a great language though. ;)
jrista
+5  A: 

In C++:

Myth: NULL is not always zero, but it depends on the null pointer address.

Reality: NULL is always zero, and it's not an address. It's an integer.

Many confuse NULL with an address, and think therefor it's not necessarily zero if the platform has a different null pointer address.

But NULL is always zero and it is not an address. It's an zero constant integer expression that can be converted to pointer types. When converted, the pointer created is called a "null pointer", and its value is not necessarily the lowest address of the system. But this has nothing to do with the value of NULL.

Johannes Schaub - litb
Myth: NULL is always zero, and it's not an address. It's an integer. Reality: NULL is either 0 or (void*) 0, depending on the implementor's choice. (Or any other expression that evaluates to one of these at compile time.)
Windows programmer
@Windows programmer, No in `C++` it is always an *integer*, never a pointer expression. It's got a reason i didn't include `C` into it. So if you think it deserves an entry for `C` about it with that wording - go for it. But this comment section is the wrong place.
Johannes Schaub - litb
I just checked and you're right. I wasn't trying to put my comment in the wrong place, I hadn't noticed that C++ differed from C on this matter, and my comment was wrong for what it says. Maybe we should publish an article in a scholarly publication. "C considered harmful, for C++ programmers" :^)
Windows programmer
Good idea hehe xD
Johannes Schaub - litb
http://c-faq.com/null/index.html
Kevin Panko
@Kevin, That faq is a C FAQ. I'm not sure why you post it to my answer as a comment. Either you think my answer is *wrong* (but then you should have downvoted me), or you think my answer is right and the FAQ is helpful - but it isn't because it's not about C++). My Pet Peeve is about C++, to keep it clear and so that my pet peeve doesn't always need to say ".. except when it's `(void*)0 ... etc".
Johannes Schaub - litb
Your answer is right. The FAQ page explains more about this NULL versus zero business. It's simply the best page I could find on the issue. Memory addresses work the same way in any language -- assembly, C and C++ .
Kevin Panko
To be really anal about it, "NULL" is not a part of the C++ language at all. The file, stdlib.h, #define's NULL to be 0 when __cplusplus is defined. You can cut out the middleman and just write 0 anyplace you would write NULL, and it works exactly the same. It's just conventional not to do it that way.
Kevin Panko
@Kevin, that is right and i agree. It's not part of the core language. But it's still specified as being part of C++. In this way, it's part of the language's library. To be further anal about it, `NULL` can be defined as `0L`, `'\0'` or any other zero value - in this way, `0` and `NULL` are not always completely identical, and it's allowed in C to have `NULL` be `0` too. The matter is more difficult in details, so i omitted the C side of this on purpose, because i wanted my answer to be a rough overview, not a detailed specification :)
Johannes Schaub - litb
Use nullptr.NULL is simply broken...
Andreas
+3  A: 
somefunction(){

try { .... put your whole code here .... }

catch{}; // empty catchy!!

}
yelinna
+2  A: 

Developers who don't understand .NET naming conventions.

Examples (from a real library that I had to use):

public delegate void FooBarVoidVoidDelegate();  //FooBar is the component name.

public enum FieldTypeEnum {
    OBJECT_NAME,
    FIELD_SIZE
}

public delegate void ConnectedDelegate(object sender_, ConnectedEventArgs args_);
SLaks
The temptation really is great, at first, to name delegates with the "Delegate" suffix. As if it was a totally different entity altogether that deserved its own naming convention. I do declare guilty on that one.
MPelletier
I must admit I don't understand this. (Probably related to not having a clue what `delegate` means, and that I have done very little with .NET...)
SamB
+10  A: 

"When I have time at the end of the project" , "Later", and "At the end" refer to a non-mythical point in time.

"This is just a hack, but I'll just put it in as a placeholder and fix it later."
"I know the code isn't commented, I go back and add those in at the end."
"I'll update the database documentation when I have time at the end of the project."

Correllary: "Version 2-The Refactoring" is just as mythical
Myth: "This is just a quick and dirty implementation so we can hit the release date, we'll come back and fix it in the next version"
Fact: The re-factored version of "quick and dirty implementations" never make it to the top of the priority list. Ever.

JohnFx
Joel Spolsky's latest; "Duct Tape Programmers" disagrees with you.
Neil N
Well I guess that just proves he can't be right all the time. =)
JohnFx
+1 (only because I can't +1000)
Scott Smith
Hmm. I think the time referred to actually exists, but is equivalent to **"when nobody cares"**...
SamB
+9  A: 

Any Usability Failure is the User's fault

Wrong! If the user can't figure it out, the developer is doing something wrong.

Corollary: Documenting a non-intuitive UI makes it okay
I know it is uncommon to have to quadruple left click an icon to change make it visible, but it is clearly spelled out in the manual. RTFM!

JohnFx
Hmm, but sometimes the user really *isn't* qualified to use the program! What if it was a theorem prover and the user didn't even know what mathematics is?
SamB
Still, your criticism is valid in many cases, so +1.
SamB
@SamB - I would argue that a person who didn't know what mathematics is, wouldn't be a user of a theorem prover, and if they were it would be the developer's responsibility to make the UI intuitive for that type of user.
JohnFx
+18  A: 

Users Read
"I am a user and I do not read." Said Johnny User McSnead.

I do not read dialogs, whether large or small.
I'd not read a help file if it were forty feet tall.

When they don't heed text littered all over the screens.
"It is all your fault", the developer screams.

Using your app isn't my job
so make it wordless you programmer snob!

The Moral of the story: Your job as a programmer is not to create a better class of users, but to make programs that accommodate the users you have. Writing an app that ignores the fact that users don't read (whatever the reason) is one that fails in terms of usability.

JohnFx
great poem! * required - at least 15 characters
Robert Fraser
Who should I attribute that poem to?
Neil N
I made it up, so I guess me.
JohnFx
+1  A: 

Incomplete/inaccurate/missing documentation

I know this was partially answered before, but mine has two parts:

  1. When I inherit code from another programmer, I'd like to see what the intent was behind the code. When I started my current job, I inherited a number of classes that were heavily dependent upon a knowledge of specialized business math. In order to make corrections, I had to spend a lot of time with senior management learning what the math was supposed to be, why, and how it would look on paper (immediately got documented). With proper documentation, my time spent would have been cut by 75%.

  2. Component documentation. My company spent hundreds of dollars for your company's components a few months ago as they have the most functionality that we can use. Now you have a new release, and the documentation is incomplete and inaccurate because you did an overhaul on your methods and properties. Now I have to spend multiple hours figuring out what's wrong with my code because of your changes. Now I have to hunt through source code and keep playing with different switches because it no longer works properly. Please, is it too hard to document not just the change log, but also the help files? I know it's not. All you have to do is show sales a noose and ask them to back off their artificial deadline before the deadline gets used on them (not really, ignore last part).

As a part of number 2, why don't component developers ever document custom exceptions their code can throw? Why do I have to waste more hours testing every case to find out what exceptions can get thrown? Because I don't have the time to find every obscure exception buried 6 or 7 layers deep in the component code that might hit me, I'm forced to generic handling (and yes, this is based on my reality, no exaggeration or whining intended).

Tom
rolled back as didn't see the need for a period after a sentence fragment according to grammar rules.
Tom
+9  A: 

Ignorance of the runtime model

I was once criticized by my java team lead for putting too many methods in a class - "the objects will take up too much memory!".

Ash Kim
+5  A: 

People who refuse to learn an IDE

It takes effort to get used to, but if "a text editor with syntax highlighting" for you, you're coding at about 40% efficiency and making hard-to-detect mistakes when refactoring. Even if you're using an IDE, if you haven't put in the work to learn its features beyond IntelliSense, you're doing the same, only with higher memory usage.

If you don't know how to set a conditional breakpoint or watch expression, you're doing it wrong. If you rename variables by changing the name and seeing the errors the compiler spits out, you're doing it wrong. If you undo more than 10 steps instead of using syntax-aware history, you're doing it wrong. In fact, if you ever get a compiler error, you need a better IDE that reports them as you type.

Did you know that a conditional breakpoint in Visual Studio can be used to execute arbitrary code at that point (and the breakpoint will never trigger)? Did you know that JDT's auto-correct can fix typos in variable names? Did you know that in two clicks in ReSharper you can change a string built using concatenation into a string.Format call?

For part of this, I blame Visual Studio -- the actual editor is what a lot of people who don't use IDEs complain about -- slow, and not that feature-rich. Learn 50% the features of Eclipse JDT and you'll type 80% less code, or your money back. ReSharper is close, but it's still not as good as JDT and it's expensive. Vanilla VS's editor is a bloated text editor (but its debugging tools and integration with MS stuff is terrific).

Second up are people who don't know regular expressions. I think I may have put a regex into code once or twice, but a quick find-and-replace regex in your editor with a couple capturing groups can save you loads of repetitive typing and prevent bugs.

Robert Fraser
Using and IDE might be useful in some situations, but a lot of times it doesn't increase productivity.
Amuck
Probably worse is when people try to teach/learn an IDE without knowing how to do it the old-fashioned way first...
SamB
vim vim vim ftw!
Arnis L.
+6  A: 

Source files that contain numerous commented out iterations of code with no comments

Recently I came across a project that had files that contained multiple version of similar logic commented out one after the other with no reasons as to why or even when the code was deemed non functional.

Worse the actually running code also didn't meet the project requirements. Worse still they did have source control setup to keep track of different version.

For example:

// Working! (not)
If($something) 
{
    $sql .= "AND (select top 1 x from y where x = $z) = 1";
    $sql .= "OR (select top 1 x from p where x != $z) = 1";
} 
/*
   // Updated by bob
  some alternative code
*/
/* 
   // this code was no good (joe)
   some more alternative code
*/
/*
   // original verion by (paul)
   obviously the original version that also didn't work
*/
Jai
That's called Scar Tissue (http://codewright.blogspot.com/2005/11/scars-we-bear.html)
Kelly French
+5  A: 

Another pet peeve for me is programmers who confuse the meaning of the concept of inheritance in object oriented programming with the biological meaning of the word.

For example, people who call the superclass the "parent class" and who call the subclass the "child class", or who write code examples like this:

class Parent {
    // ...
}

class Child extends Parent {
    // ...
}

Ofcourse, inheritance in OO programming means "specialization", and there is an is a relationship between instances of a subclass and instances of a superclass.

By writing class Child extends Parent you are saying "a Child is a Parent", which is obviously wrong.

Jesper
Uh, what? I don't see the issue. At *all*.
SamB
+3  A: 

Not just programmers (though they are unfortunately very much represented in this group), but I'm annoyed by people who don't understand or appreciate the role of research in driving progress in technology (I say this as an industrial programmer, not a researcher, btw) and don't understand how long it takes for something to go from an idea to mainstream reality, or how long a history each "new hot technology" really has.

Max Strini
+6  A: 

Fanboy-ism

Developers who don't become complacent but actually become fanboys of some arbitrary language. They often refuse to discuss the shortcomings of their chosen favorite langauge or discuss advantages of alternative languages.

Resisting Lower Level Understanding

Developers who work in high level languages, tools, or toolkits that provide capabilities like JIT, gabage collection, database access, file I/O, and dynamic typing and refuse to work in situations that require them to understand such menial tasks. It's like an author that doesn't know how to write in MLA format because their editor/publisher does that for them.

s1n
To be pedantic, "refusing to work in situations" is not the same as "resisting lower level understanding". I may for example be interested in the mechanics of garbage collection, and memory management in general, particularly as it helps in producing good software. I may however prefer to work with "higher level" systems since it makes me more productive and most of the time a garbage collector does a good enough job (particularly if you have some idea how it works).
Phil
Indeed -- I may be happy to know these things, but still not wish to write C for no good reason. (This is, in fact, the case.)
SamB
+1  A: 

They just develop skill in one language and try to do everything with the same, they don't try to understand that there are scenarios when C++ should be preferred over C#. They don't think to go out of the Box.

viky
Hmm. I'm honestly not sure when C++ should be preferred. (I tend towards C for low-level code, myself...)
SamB
+2  A: 

I find myself particularly irritated when a I encounter programmers who act as if documenting bugs is enough to get along instead of fixing them. Those people who even argue against those who discover bugs in their codes. Even defending defective implementation with a "working as designed" attitude.

I hate the "known problems" sections in readme files.

PA
At least they are admitting the problem exists. Be very glad you have not had to work in a ship with developer(s) who refuse to admit bugs exist, even when presented with clear demonstrations of programs freezing, locking up, or just not doing what they are supposed to.
David
Sometimes we do this because they have not figured out how to actually solve the problem, but wish to remember the existance of it so that we can figure it out later (in addition to warning users in the meantime)...
SamB
Fixing non-trivial bugs always opens up possibilities for regression (creating new, unknown issues), and requires more testing. Some bugs are better left documented and unfixed if shipping in a timely fashion is a consideration.
dbkk
+5  A: 
Dave Quick
+3  A: 

The My-app-should-run-in-full-screen-by-default-even-if-you-have-a-30-inch-monitor-attitude.

FeatureCreep
I'm fairly certain that it's not the inches that matter, but the degrees -- that is, the portion of your field of view occupied by the screen.
SamB
+5  A: 

I'm not sure if I'd call this "programmer ignorance" but it's definitely a pet peeve:

Code which passes data around in unsuitable, non-specific types.

This to me is one of those code smells that will tell you fairly quickly that the code you're looking at is really bad.

A prime example that springs to mind is some code I was looking at that passed IP addresses (specifically IP addresses mind - not DNS names) as strings. These IP addresses were passed through multiple layers of the application all as strings.

Result of course is error prone code - with it being entirely unclear where the invariant (that you have a valid IP address) should be checked.

Of course what should have been done is that the user entered IP address should have been converted as soon as possible (usually within the UI 'layer') to an IP address structure/class (probably IPEndPoint on .NET). That way the location for validating the address is self evident, and you don't have to repeatedly worry about a broken invariant since IPEndPoint cannot have an invalid address.

Additionally, by the same reasoning, when there is no preexisting class/structure that can be used to represent the data, the developer should consider creating one rather than 'making do' with an unsuitable type that does not enforce invariants.

Phil
I would pass IP addresses as strings. You see, it's very likely I turn those into hostnames very shortly thereafter.
Joshua
Then that would be a hostname or URI, not an IP address. What I'm referring to was specifically used for IP addressed - it did not allow host names; there was no DNS resolution involved. In any case, the point is (at least with static languages) types should be used to constrain input/output data, avoid broken invariants and make it easy to identify where data validation is required and performed.
Phil
Come to think of it Joshua, what you suggest still end up being an example of what I'm arguing against and what I consider to be bad practice. A string can contain illegal characters and can be a malformed URI. So, instead of passing strings around you should use a class (or write one) which enforces validation of the URI.
Phil
hostname != URI.
Joshua
Joshua, to be blunt.. so what? I don't see what that has to do with the point being made - which is that if you use a class which enforces constraints, you can ensure that the points where validation are required are obvious, and limited. This would apply equally whether you're talking about a 'URI' class or a 'HostName' class.
Phil
+7  A: 

Developers not understanding the Liskov substitution principle.

To me, this is another bad one - and one which leads to misunderstanding and misuse of inheritance.

A lot of developers are taught to choose between inheritance and aggregation via the "Is-a versus Has-a" relationship, but then still end up misusing inheritance.

Recent example - developer inherits from a class that represents a TCP connection in order to create a class that handles communication with a device over a TCP. I initially tried to explain to the developer that his assertion that his 'device connection' 'is a' 'TCP connection' was false. I couldn't get it through to him, so I tried the alternative tack of explaining to him Liskov's substitution principle, and that unless the inheriting class could support the parent class's interface etc. etc., that he was fundamentally misusing inheritance.

Unfortunately, I've seen this kind of misunderstanding way too often, and this was not a junior inexperienced developer.

Phil
It sounds like you're trying to prove the "glass is half full"
Jay
You lost me there Jay!
Phil
Well, I understand the Liskov substitution principle and once ignored it for the sake of efficiency. But I explicitly wrote it in the documentation, of course. (For a while I even had the conceptually "correct" version of the class commented.)
Eduardo León
+20  A: 

I tend to dislike any notion that programming is keyboarding and that if you aren't typing you aren't programming.

It calls to mind a physics student I worked with. He would stare off into space for a bit, then he'd write down the solution. By the time he started writing he had already solved the problem.

A little whiteboarding before keyboarding can save more typing (and debugging, etc) than anything else you might do. Programmers are not data entry monkeys.

brian d foy
+1 for "Programming is keyboarding and if you aren't typing you aren't programming." // I think non-technical management makes this mistake frequently.
Jim G.
+1  A: 

The belief "What I think is good is always best"

I've worked with many programmers who believe they know what's best for everyone because it's what's best for them. The "best" code is the best solution to the code user's problem. It may not be the most elegant, fastest, easiest to maintain, coolest, easiest to read, best documented, most advanced, newest technology, etc.

Unfortunately too many employers don't spell out their requirements for good decision making so I can't really complain too much.

Jay
Why are "coolest", "most advanced" and "newest technology" on this list?
+11  A: 

Ignorance of how to use a debugger

I see so many people waste time trying to figure out what is going wrong in an app by using print statements or blindly changing the code, when the problem could be found by spending 30 seconds in the debugger, stepping through and examining values.

Similarly, a core file is not just the unsightly mess left when your app defecates in fear before dying. There is valuable information inside that will, in most cases, lead you directly to the source of the crash in very little time.

This isn't just a problem with young programmers, either. Many people start doing things one way, never bother to learn the better way, and rise to very senior positions without knowing how to save themselves hours of work by running their app in a debugger. I weep to think of how many millions of dollars have been wasted over the years by these people. (OK, that's a little over the top, I admit. But this is about pet peeves, so pardon me for getting a little worked up.)

I blame the schools: I got my CS degree at a very reputable university, but using a debugger didn't appear in the curriculum for the intro-level courses. At most, it was mentioned as an afterthought. When I later worked as a tutor for the walk-in CS tutoring center on campus, gradually became aware of this problem and started teaching the students who came in about how to solve their problems using the debugger. Later, as a TA, I created a short seminar about debugging practices in an attempt to help the situation. However, now as a practicing Software Engineer, I still find that I have to instruct other very experienced engineers in the use of a debugger.

Adam
Do yo have a favorite reference or tutorial for learning how to use a debugger? I for one would find it very useful. Especially one for GDB.
AndyL
Wow. I haven't had an app leave a core file unbidden in forever...
SamB
+3  A: 

"It doesn't matter that Java doesn't have feature X - because with a little bit of coding around (in all the places where X would be used) achieves the same effect"

Where X can be:

  • closures
  • continuations
  • an OO metamodel
  • anything else

It's another way of saying "I get paid to do Java and it's a general purpose programming language so I don't need to bother to learn anything else"

cartoonfox
Yeah. The paper "On the Expressive Power of Programming Languages" http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.51.4656 deals with the common fallacy that since most languages are Turing complete, it doesn't really matter that much which you use.
SamB
+7  A: 

Claiming something can't be done because they can't do it.

z5h
As a corollary to this, one of my pet peeves is being forced to say, "It can't be done" because if you admit it's possible you'll be asked to do it, no matter how big of a waste of time it is.
kubi
+11  A: 

Failure to use source control, or failure to use it sensibly.

Source control is the memory of your project. If you don't check anything in, you're living in an enforced state of amnesia. You've heard of those people who have head injuries and lose the ability to store things into long-term memory? That's you without source control.

On the flip side, if you keep commented-out code in your current source files because "I might need it someday," you're that guy who doesn't trust himself to remember anything and goes around wearing an upside-down nametag.

And if you're working on a team where each member has different standards about what gets checked into version control at what stage of development, you're a normal person (who can remember your 5th grade teacher's haircut but not where you put your car keys last night).

[Slight tangent: we recently had a developer get very irate with our (competent) sysadmin because the latter had redeployed a script from the source repository. Turns out the developer hadn't checked any of his changes into SVN in the six months (!!!) he'd been working for us. This is what happens when a dev gets hired by the marketing team.]

Arkaaito
If a source control product could show me me the "removed" code exactly the way i want it, i would remove it. i'll also keep commented out lines in place when i've added to the end of it `No! You *don't* want to do this.` and i explain why. Too often someone comes along and thinks they're fixing something, but they don't realize that their fix is wrong for very good reasons. Seeing the exact line they were about to add is an indication that the author knew what they were doing.
Ian Boyd
Related: a CVS workflow with everything being commited straight to the HEAD, with no tags of what goes to live production servers.
Tadeusz A. Kadłubowski
+3  A: 

This is really anal, but I abhor the use of NULL to describe the character that is used to mark the end of a string in c.

NULL is associated with pointers.

NUL is the name of the ASCII character that represents '\0'

EvilTeach
In C, the term "null character" is used to refer to `'\0'`. The ASCII character may be called _NUL_, but in C the terminator is called the _null character_.
James McNellis
+3  A: 

My pet peeve is programmers who don't try to understanding something, they have the attitude that the "compiler" will figure it out for them.

Chris
+4  A: 

Humility. Eric Evans said it in his forward to Jimmy Nilsson's book Apply Domain Driven Design and Patterns, the best coders have the rare combination of self-confidence and humility.

I find many developers have plenty of self-confidence however do not take well to good criticism. Dunno whether this can be blamed on ignorance of human nature.

Wix
+2  A: 

There are a lot of good answers here already. Here are my top four:

Continuous Learning: It's one of my most important interview areas. If you aren't learning anymore, you shouldn't be in this business.

Arrogance: I have no patience for a developer that say something should be done that way "because it's the only way".

Over-commenting: If your code is written so that it can be maintained by others, it doesn't need comments describing each line.

Consuming Errors: Putting a try/catch around each section or just returning from each function when an error condition occurs isn't HANDLING an error. It takes a lot more time to track down a bug if an error condition is consumed.

Hank
+11  A: 

Ignoring the knowledge created and work developed before they could type.

Very often, programmers think that anything older than them is old fashioned or outright invalid. This is a big mistake. Although software development moves extremely quickly, many great steps were taken decades ago and have not been superseded at all. Ignoring that is stupid.

I can see this sometimes when programmers (usually young ones) are asked about books or other reference material. They seem oblivious to what was written before 2004 or something like that. There are great books today, but there is a lot of crap too. Ten or fifteen years ago publishers were much more selective, and fashion was not that important a factor to sell computer-related books.

Now you'll think I am a melancholic pensioner. Ha! :-)

CesarGon
Huh. I always thought it was kind of neat that TeX predates me ;-P.
SamB
TeX? TeX is *trendy*!
CesarGon
+3  A: 

The belief that the ease of writing code in a language is a more important quality of the language than the ease of reading code in that language.

Joe Carnahan
+2  A: 

Using ".Net is the future" as the primary justification for rewriting existing working software. The same developer once described it as "God's will".

Bruce McGee
+3  A: 

I read 4 pages of that and I really need to post... (hope no reposts;))

I hate when developers forget that they write soft to BE usable by people who are not programmers, and not taking into account that for a non-programmer smth may be difficult to grasp..

Also 'index base programming' - a fantastic paradigm I have kept on rediscovering in many lines of code eg.

List<int> linesChecked
List<Rectangle> drawnRectangles
List<whatever> something

and then orchestrating all the lists using one index because the things are ESSENTIALLY a single object. duh

A third.... not leaving the default: in switch statement... it's there because something CAN really happen, one can recompile the enum, whatever.... duh (an infinite source of bugs for me:)

luckyluke
Yeah, what is this, BASIC? Come on people, use records!
SamB
+1 Good point about the possibility of an __enum__ being redefined.
+6  A: 
if (someValue == true){
    return true;
} else {
    return false;
}

Instead of

return someValue;
Erin Stanfill
A: 

Test by try/catch

This must be bad for my heart.

Example is in J. Suppose two vectors. The dyad ,. means stitch, a.k.a. align these two vectors side-by-side in a matrix. Now suppose that for some reason, you have vectorA and vectorB, and you know that vectorB can be one off. I've seen this in a function trying to alter colours between two rows, vectorA has the odd rows, vectorB the even rows, so either vectorB will be the same length or one off.

    try.
        vectorA ,. vectorB
    catch.
        vectorA ,. (vectorB, a:) NB. append an empty item
    end.
MPelletier
This is considered normal in some languages, notably Python, where it's called "ask forgiveness rather than permission", and more often than not has a notable negative impact on speed. My least favorite use is list.index raising an exception if it can't find the object, rather than returning None.
Joe
I would not consider the above valid in J. There is a totally acceptable way to test for this. And since J cannot catch by exception type (I think. although one could fetch the exception type and perform a switch in the catch), my example could occur on a length error or a domain error, where types aren't compatible, or a syntax error, if a variable isn't declared). Plus, `,.` is a bit of a resource monster. Using it, watching it fail, then using it again? That's a crime!
MPelletier
A: 
bool finished = false;
for (i = 0; i < size; i++) {
    if (something(i))
        finished = true;
    ...
    if (finished) break;
}

Rather than

bool finished = false;
for (i = 0; i < size && !finished; i++) {
    if (something(i))
        finished = true;
    ...
}

Languages support a full conditional in loop clauses for a reason.

Joe
True to a point.... you may want to exit BEFORE the end of the loop. In that case the second solution won't work.
nico
what aboutfor (i = 0; i < size; i++) { ... if (something(i)) break;}
Johann Philipp Strathausen
+3  A: 

Some prefixing of variables is just aggravating:

  • temp- In the end, all variables are temporary
  • scr- (for scratch, meaning temp)
  • my- (OK in example code, but not in implementation)
MPelletier
Add on there `<short_product_name>` for instance, if your product is ABC Accounting, having all sorts of variables like `abcWindow` and `abcSqlConnection`
Earlz
I can see your point about "my", but I think "temp" communicates something helpful: such variables are typically much shorter-lived than others. E.g. a variable used for swapping two values. It gives a hint that the variable does not directly affect anything beyond the immediate context. Taking "all variables are temporary" to its logical conclusion, all hardware, people, and stars are also temporary. Yet the differing degrees of longevity matter.
LarsH
@LarsH: very good point. "Temporality" is indeed the key. For such operations as swapping, I'll name/prefix it temp myself. But when you see that "temp" live on for the remainder of the function (sometimes a very long one), it gets irksome. Working with array based language J, I can tell you that very often you take a matrix and transform it a few times. If you want to lay down your code and not just have a string of ascii characters, you'll create several steps, each of which is temporary, but there temp- just denotes lazy naming.
MPelletier
+4  A: 

Any form of cargo culting (programming, general computer usage, etc.).

  • “Hmm, the result still has “&gt;” thingies in it. I guess I have to add yet another decoding pass.”

    Take the time to understand the involved specifications and standards to find out whether this is a bug in the content the program is consuming, a bug in the standard, a bug in the specification, or a bug in some other part of the system. If the data is supposed to be free of character entity references at this point, then there is a bug somewhere (unless the bug is in the specification and it really is OK to have character entity references at this point!). Find the bug to understand the problem.

  • “Hmm, that did not work. sudo worked on this other thing I was doing, I guess I will try it here, too.”

    The solution to every permission problem is not “do it as root”.

Do not “paper over” the immediate problem with the first thing that comes to mind. Solutions from one problem should not be automatically applied to any other problems unless the solution will solve the problem in all applicable situations.

Getting a solution from “the Internet” is fine, but do not blindly apply it. Read the documentation, read the code, do some research, experiment in temporary environments. Learn from the given solution. Do not parrot it. Only with a proper understanding of a particular solution can one determine whether it is a proper solution for a specific problem.

Chris Johnsen
+1  A: 

This could would be so much better if I could just re-build it from the ground up.

No, it wouldn't.

JohnFx
I disagree, many times from the ground up is better. But it depends on scope and risk of changing the existing software.
Chris Marisic
+1  A: 
  • BY FAR my biggest annoyance is: Leaving Code Commented out everywhere!

  • Not improving code that was fixed, just leaving it alone

  • Not using the framework, for instance, writing their own code to log something instead of using the common logging framework the rest of the team uses.
  • Printing to the Console, and not removing it..cluttering it up for other developers...
emalamisura
+5  A: 

Jumbo Methods

I can't stand "jumbo methods," often characterized by:

  1. no extracted helper methods (but you might get block comments if you're lucky)
  2. dozens of variables in scope (rather than limiting their scope by extracting methods)
  3. no clear separation of tiers (e.g. intermixed validation, persistence, and presentation logic)
  4. control-flow hell

e.g.

void DoIt() {
   // if the view is valid
   if (TextBox1.Text != string.Empty && ...) {
       var sum = 0;
       // process each element
       for (var i = 0; ... ) {
           // make sure it's a good element
           if ( ... ) {
               Status.Text = "Bad Element";
               break;
           }

           // process each subelement
           for (var j = 0; ... ) {
                // add to the sum
                sum += ...
           }
       }
       // remember the sum
       ViewState["sum"] = sum;
   }
   // if the view is not valid
   else Status.Text = "Required field missing";
}
Jon Nadal
I don't understand why this got -1 because it's a very valid and commonplace situation.This is how code becomes unmaintainable, one method or variable at a time."Getting the job done" is not the whole story, and leads to spaghetti code.
smci
It is good to remember that usually when you get down to more than 3 nested conditionals or loops, it is time to refactor and break down the function into helpers. I once did this with a more than 100 line method and made it so that I never went further than 1 nested level.
Earlz
@Earlz: I couldn't agree more.
Jon Nadal
+4  A: 

jQuery != javascript

I see a lot of questions around here saying, How do I do X in jQuery, even when the OP has no idea whether jQuery is relevant.

This has elements of other answers: fanboyism, and using frameworks that you don't understand.

There are some great answers at the top! This really is just a personal pet peeve.

harpo
Well, maybe they were just *hoping* that jQuery would make it easier. A reasonable thing to hope in many cases, I think -- I certainly find it handy for screwing around with the DOM in my day-to-day browsing ;-)
SamB
@SamB, don't get me wrong, I love jQuery, and I hope some of its features are built into future versions of javascript. I just see a wave of folks who apparently don't know the difference and who (already) seem to think that jQuery *is* javascript.
harpo
More than that I hate when someone asks "How do I do xyz" and the reply is "Well, if you used JQuery it would be easy". As if you couldn't do anything without it... http://meta.stackoverflow.com/questions/45176/when-is-use-jquery-not-a-valid-answer-to-a-javascript-question
nico
+2  A: 

Indifference towards retarded compilation/build/project-organization methods that create unbelievable amount of mundane work.

I kid you not, I've seen a dev environment where checking out the latest revision requires 10 (gui) steps, and so does building. Running the full test suite might well require 100+ (gui) steps.

hasen j
A: 

My pet peeve is my ISP. Especially when the support says: "Turn off your modem, wait 15 seconds and turn in again. Is it okay now?"

neduddki
Yeah. It's a pain when technical support is not actually technical ...
SamB
In atleast 50% of the cases where my modem isn't working, this solves the problem. As long as they know what to suggest after you tell them that didn't work, I see no problem with this.
Wallacoloo
I called them because my server's IPv6 settings...
neduddki
I usually try restarting my modem and such things before I ever call :P
Earlz
Rules for trouble shooting most network stuff:1. Locate the most complex least expensive hunk of consumer electronics in the system (like a cable modem).2. Disconnect power from the device (power switches and reset buttons cannot be trusted, unplug it).3. Wait 30+ seconds (modern capacitors are very efficient and electronics designers love to scatter them all over).4. Reconnect power. WAIT at least 2 minutes.5. Test.If this does not work: Find the least complex MOST expensive hunk of electronics (like a Cisco Ethernet switch) and perform steps 2-5.:)
Rusty
You're forgetting that 99.99% of the population is not a programmer, and a good part of them will NOT reboot before asking for help. Some of them probably also did not notice that little switch labeled "power" that is turned off.
nico
@nico: unless, of course, they're still on 9x, in which case they're nearly always aware that it might help...
SamB
+1  A: 

Programmers writing "helper" code (eg: buggy date validation that doesn't use regex to parse and breaks on certain dates since they were unable to understand testing works by not merely running it once on their machine) that can easily be found in the default language API or some commonly used library such as Apache Commons.

Zombies
I'm unsure how using regex would be an improvement...
SamB
Why wouldn't you understand that a regex can parse a valid date format? As opposed to writing date.length == 10, date.countChars('/') == 2?
Zombies
@Zombies What's a valid date format? Me, I see dates like 12 มิ.ย. 2552 quite often...
dbkk
+1  A: 

Programmers who decide to deviate from a standard just to make it work. This lack of concern also means they won't share this information until after they have commited their several revisions.

Zombies
A: 

Programmers are people and as such are expected to function as a socially responsible member of society or company.

MSN
are you saying we are not people ? :)
David Brunelle
It's a direct answer to "things that everyone who aspires to be a professional should know and take seriously, but doesn't?" :) It's confusing, I admit.
MSN
+4  A: 

It continues to amaze me how many people believe that:

All programming languages are fundamentally the same; they just use different syntax.

Wallacoloo
Well, all computer languages certainly are the same—in the same way that all human languages are the same. The things that make them so have precious little to do with syntax, or even paradigm.
Jon Purdy
DV, If they are turing complete languages they are the same! The only differences are the tools the languages have available.
Chris Marisic
@Chris The statement above is annoying since it is only true in a narrow theoretical sense, but is used in a broad range of discussions where it doesn't apply (e.g. choice of language for a project). By the same token, all computers are the same, but you won't host a website on a TI-83.
dbkk
@dbkk: you don't want to... but you could :)
nico
@dbkk: Agreed. It is not true even in a theoretical sense. Only heavy qualification could make it true. This is the heavy-handed reductionist paradigm: Let f(x) = what I think is important about x. If f(x) = f(y), then x and y must be the same! @Chris - All people are the same if they have 4 limbs! The only difference is their faces, their voices, their actions, their goals, ... etc. etc.
LarsH
A: 

Datastructures..... people don't know what it is first... but go on with programming.

Vinothbabu
+1  A: 

Thinking that their code is the reason the business exists, not the other way around.

Hooray Im Helping
Except with many businesses they wouldn't exist without our code!
Chris Marisic
+3  A: 

Pointless Tables and ASP.Net controls

Example: clean, functional code

<div>
  I is in your browser
</div>
<div>
  Showing your static text
</div>

Horrible beyond belief code

<asp:Table ID="table1" runat="server">
  <asp:TableRow ID="row1" runat="server">
    <asp:TableData ID="data1" runat="server" Width=191px>
      <asp:Panel runat="server" ID="pnl1">
        <asp:Label runat="server" ID=lbl1" Text="I is in your browser" />
      </asp:Panel>
    </asp:TableData>
  </asp:TableRow>
  <asp:TableRow ID="row2" runat="server">
    <asp:TableData ID="data2" runat="server" Width=191px>
      <asp:Panel runat="server" ID="pnl2">
        <asp:Label runat="server" ID=lbl2" Text="Showing your static text" />
      </asp:Panel>
    </asp:TableData>
  </asp:TableRow>
</asp:Table>
Earlz
A: 

Using Java.

You can't imagine how much I hate software written in Java. Clumsy looking GUIs with tons of display bugs, the resource hogging "java automatic updater"...

Second worst pet peeve:

Using anything else than C# / F#. There is no justification, except in extreme cases (OS development or when you need to talk to the CPU directly to use SIMD). And then - only write as little as possible in unmanaged horrorlanguages from hell (C++, etc... choke) or, even worse, "dynamically typed languages" which are nothing but toys for masochists who hate understanding code and helpful tools like Intellisense.

Third worst pet peeve:

Unneccessary P/Invoke...

stormianrootsolver
That's *Java on the Desktop* to be precise, and is more of an issue with Swing (the GUI toolkit). Nothing wrong with Java programming language itself (e.g. when used on a web server, or for Android apps).
dbkk
+1 for *Using anything else than C# / F#. There is no justification, except in extreme cases (OS development or when you need to talk to the CPU directly to use SIMD).*: Looks like you and I would get along.
Jim G.
+1 for dynamically typed languages. I've developed web applications in PHP and I know what I'm talking about when I agree with your statement ... Swing does indeed look clumsy and ugly, that's right.
Marius Schulz
I think you're confusing poor *use* with poor *technology* - there are some Java Desktop apps with absolutely brilliant user interfaces, so good that you'd never know they weren't totally native unless you went looking. Similarly with dynamic languages, there's been a lot of developers using the lack of static typing as an excuse to be cowboys. Good dynamic language code requires *greater* discipline, not less.
Bevan
I also hate Java, but there is one justification for using it - the JVM is much better than the CLR. That's why I have high hopes for Scala.
Craig P. Motlin
Are there any solid arguments for this? Without them this post looks to me like a typical case of evangelism. I do also like C#. ... **and** Java **and** Python **and** PHP **and** Prolog, **and** ...No matter how you look at it, a developer who dabbles in only one corner is not looking at the Big Picture IMHO. Oh, and I am *sure* that you can easily write abysmal code (with an eyesore of UI to go with that) in C#. You are actually demonstrating one of my fav. cases of "programmer ignorance".
exhuma
Python is a horrible dynamically typed language, PHP is... well... LOL... Prolog? Seriously?And Java... if I can get the more complete, more high quality .NET - framework and a language WITHOUT the ugly egypt dancer style parentheses, why would I use Java?No, thanks. Microsoft has provided us with the last necessary answer, it is C# / F#. Case closed.
stormianrootsolver
You know javac can compile code with different styles of curly braces, right?Have you tried Scala?
Craig P. Motlin
@exhuma: you could not have said it better
nico
On Java: agree.
FerretallicA
+9  A: 

Mine is technical and is about text encoding. There are a LOT of programmers out there that just ignore this thing or don't even know what it is. And in an era where isolated apps are disappearing in favor of APIs, integration, messaging etc, every developer should have knowledge of text encoding, how it works and what are the libraries/functions their favorite programming language offers to deal with it.

redben
Its all about EBCDIC
bobobobo
Even its name is scary ! lol
redben
+8  A: 

"Programmers" that don't RTFM, those that want you to chew their food for them. They just come to forums or SO and ask questions that even google can answer!

redben
"Programmers" who post answers with obvious typos and spelling errors `;)`
e.James
e.James...Sorry ! English not being my mother language + google effect and code assist effect. :)
redben
No need to apologize! It was meant as a cheerful joke. What's the point of expressing our pet peeves if we can't have a little fun while we're at it? `;)`
e.James
That's what lmgtfy dot com is for. ;-)
peSHIr
what is RTFM? I'm not familiar with that acronym.
David Brunelle
@David Brunelle: I see what you did there :)
nico
@nico : I'm not getting it...
David Brunelle
@David Brunelle: http://en.wikipedia.org/wiki/RTFMMy comment was about the fact that you just asked that after the one about lmgtfy dot com ...
nico
@nico lmgtfy, nice one, didn't know about this acronym. American people (or anglophones?) love acronyms http://www.computergear.com/aaaaatshirt.html
redben
@redben: oh, I can tell you, French are as bad as Americans :)
nico
+3  A: 

The belief that other coders are incompetent.

mR_fr0g
"The belief that other coders are **incompetent**." Fixed.
Jim Schubert
ha ha. Without auto-complete i am incompetent.
mR_fr0g
haha, me too. I just couldn't pass up an easy fix ;)
Jim Schubert
+8  A: 

Unnecessary comments! It drives me crazy when I see comments like:

if
{

}//end of if

or

x + y // add x to y

or

Catch (Exception e) { 
 //exception logic
} 
Florian
Man I feel for you. I saw a program from someone I had to take over which contains only this kind of comments and a lot of it. Every lines have the explination of what it did, like : "add 1 to i" or "Call the GetLine function". it has about 2000 lines of code, so it had about 2000 useless comments.
David Brunelle
+1. I've been modifying the twentyten WordPress theme, and it's lousy with these kinds of useless comments.
Hooray Im Helping
+4  A: 

Fonts that don't distinguish between zero (0) and the letter 'oh' (o/O) or between lowercase 'el' (l) and the number one (1). When done right it makes it drop dead easy to tell the difference. When done wrong, just hope guessing wrong doesn't have bad consequences. CAPTCHA's anyone?

Kelly French
+8  A: 

What I call the "King Nebuchadnezzar attitude":

Programmers posting on web site asking for help, saying "This is what I did and it didn't work" without saying in what way it didn't work. Compiler error? Runtime error? Wrong output? Electric shock? Somehow they determined that it didn't work, but they're not going to share that critical information with the people they're asking to help them.

You are supposed to figure out what they mean by "it didn't work", as well as why it didn't work.

Non-programmers are even worse... but that's off-topic.

LarsH
Even worse is when you try figuring out in what way it didn't work with non programmers. "My TV isn't working" "ok, in what way does it not work" "I don't know, it just isn't working" "what the *$#(@!!!!..."
Earlz
A good asking-for-help question has to provide 3 crucial pieces of info: 1) What exactly you did. 2) What you expected to happen. 3) What exactly happened instead.
Michael Borgwardt
+3  A: 

Listening to ASP.Net (VB) developers with several years experience comment that they cannot work with a particular application because it is written in ASP.Net with C# and they "don't know how it works".

BradB
And vice-versa ^_^
Pondidum
I’ve actually never encountered this in the reverse context!
BradB
+5  A: 

Redundant naming.

For instance:

class bookType
{
public:
  void setBookTitle(string booktitle);
private:
  string bookTitle;
}

Let's play a game of how many times you will commonly repeat the word book now. Believe it or not this is a snipplet of example code from my college C++ book. It annoys me to no end.

Common usage:

bookType myBook;
myBook.setBookTitle("My book title");

I would have done:

class bookType
{
public:
  void setTitle(string title);
private:
  string Title;
}

Especially because it makes the structure a bit brittle. For instance if you decided to have a mapType inherit from this bookType. It'd look very odd having

myMap.setBookTitle("Map of Asia");
Earlz
"Programmers who use 'snipplet' to mean 'snippet'" :) But in your particular last example, I'd say the possible error is in extending a mapType from a Book. Although I do agree that repeating the class name in the methods is redundant and overspecific, yes, and leads to the problems you point out when you extend the class.
Adriano Varoli Piazza
I think your biggest problem would be driving a map from a book type. You should only derive from a type if it IS that type.
Brian R. Bondy
Well it'd be the same name with `Person` and `Student`... `myStudent.setPersonName` @Brian. My example is a bit poor. I was thinking of like one of those map books, like an atlus.
Earlz
+3  A: 

Needlessly Nested If statements

if(something == true)
{
    if(somethingElse == true)
    {
            if(somethingElseOther == true)
            {
             // Logic 
            }
            else
            {
                return false;
            }
    }
    else
    {
       return false;
    }
}
else
{
   return false;
}

Instead of doing something like:

if(!something) return false;
if(!somethingElse) return false;
if(!somethingElseOther) return false;

// Logic

Or like this

return something && somethingElse && somethingElseOther;
Kaius
I once found if(someVar == true) during a code review. I suggested them to refactor, to if((someVar==true) == true) :)
Pavel Radzivilovsky
+3  A: 

Programmers that think they don't need to consistently indent code and make it as readable as possible for the next developer.

Dustin Martin
Yeah, especially when you just *know* there must be a tab-width that will make things actually line up, but can't figure out what that is.
SamB
+4  A: 

The most recent answer made me think of:

  • Programmers who don't realize that a Tab does not necessarily equal four spaces (or eight, or two)

(Or, to remove the double-negation: programmers who assume that a tab equals four spaces)

palswim
Personally I consider that more of an IDE consistency peeve, but yes, a peeve none the less.
FerretallicA
+2  A: 

What bothers me the most is people who code to just accomplish a task without putting even a minimal amount of thought into planning what they should do.

John
It's like speaking without taking time to form a coherent sentence.
palswim