Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

For example, a common error in C/C++ is to use the assignment operator = instead of the comparison operator ==.

share|improve this question
13  
By looking at the answers so far, it would appear that the most common mistake in coding is using languages from the C family in the first place. ;) – Mason Wheeler Sep 10 '10 at 22:30
1  
See also stackoverflow.com/questions/345737/… – pramodc84 Oct 4 '10 at 12:05
show 3 more comments

closed as not constructive by Aaronaught, Walter, user281377, Dori Jul 3 '11 at 3:05

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or specific expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, see the FAQ for guidance.

36 Answers

1 2

In .NET languages adding of event handlers multiple times.

This usually comes down to putting the code that adds them somewhere that gets called multiple times.

There are two solutions:

  1. Move the code to the constructor (or somewhere where it only gets called once).

  2. Remove the event handler when it's completed, as has to be done if handling the event is dynamic (e.g. it only gets added in certain circumstances).

(I am guilty of this one myself).

share|improve this answer

Typos How come no one said anything about typos Are all of them that much confiednt oops did it again

share|improve this answer

In VB, forget that AND / OR in an expression do not evaluate as a short-circuit by compiler.

VB.NET introduced AndAlso and OrElse to resolve this misunderstanding and work with short-circuit.

share|improve this answer

If you don't implement all your abstract functions, you get an abstract error!

I'd imagine most compiler's will toss you a warning or not let you compile, but I've gotten this once or twice when I thought I was safe.

share|improve this answer

Expecting C's int strcmp(char *p1, char*p2) to work the same as Java/.Net/PHPs and every other programming languages' string compare function.

C's returns the result it has as soon as it finds the first null character (denoting the end of the string) so:

//test password matches:
strcmp("my_password", "m")

actually returns success. You need to remember it's equivelent to "starts with" in other languages and you need to do:

strcmp("my_password", "m") == 0 && (strlen("my_password") == strlen("m"))

(essentially check the length of the strings match as well.

(obviously you wouldn't check passwords unencrytped. Those would be md5 strings you compare or something else)

share|improve this answer

Omitting the curly brackets in C#'s switch statement got me once when I first started programming:

Excerpt from Eric Lippert's blog:

Switch blocks also define their own declaration spaces, but switch sections do not:

switch(x)
{
  case OneWay:
    int y = 123;
    FindYou(ref y);
    break;
  case TheOther:
    double y = 456.7; // illegal!
    GetchaGetcha(ref y);
    break;
}

You can solve this problem in a number of ways; the easiest is probably to wrap the body of the switch section in curly braces:

switch(x)
{
  case OneWay:
  {
    int y = 123;
    FindYou(ref y);
    break;
  }
  case TheOther:
  {
    double y = 456.7; // legal!
    GetchaGetcha(ref y);
    break;
  }
}

which tells the compiler "no, really, I want these to be different declaration spaces".

share|improve this answer
1  
1  
And the way VS deals with this... You must either always use the curlies and turn off indenting after case, or the IDE keeps indenting those curly braces :( – deltreme Oct 7 '10 at 13:04
1 2

Not the answer you're looking for? Browse other questions tagged or ask your own question.