For example, a common error in C/C++ is to use the assignment operator = instead of the comparison operator ==.
|
|
|||||||||
|
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.
|
Off-by-one errors Iterating through a loop either once too often or one time less than intended, e.g.
will go through a loop once less than intended. Changing the Another type of this error is the Fencepost error, so-called due to the following illustrative example: Given a 100m stretch of land, how many fence posts do you need to dividie it in to 10 equal sections? Typical answer is 10 (100/10), forgetting the extra post needed for the outer boundary.
|
||||
|
|
|
Forgetting the |
|||||||||||||
|
|
In C#, using |
||||
|
|
|
I saw quite a few errors with missing break in switch statements (C++, Java). Fortunately C# forbid this practice.
|
|||||||||||||
|
|
In languages like C#, changing the value of a parameter passed in to a method and then wondering why it's not updated in the calling code. |
||||
|
|
|
||||
|
|
|
Misplaced semicolon C/C++ and/or alignment:
doSomething() is always called even when x is not 5. Obviously you know not to put a semicolon at the end of the if but sometimes it can be an overlooked typo. |
|||||||||||||
|
|
Doing this in C/C++ :
It will cause compilation error elsewhere in your code. |
|||||
|
|
Writing
instead of
|
|||||||||||||||||||||
|
|
Forgetting to close connections. (HTTP, database, whatever.) Closing the connections prematurely. |
|||||
|
|
Null References. In OOP an object has control ( or should have control ) over the attributes/data of himself. By setting them to an usable state and controlling how those attributes are modified, the source code prevents using null references ( Initialize with valid values ). The common mistake is to allow the modification of these attributes with a potentially null reference. Ej. in Java:
A possible workaround is: 1.- Remove the setter 2.- Validate the setter
That is, reject the invalid value, the let know the caller, they are using the object wrong. If the program is to fail, it is much better to fail fast. One, mistake to try to mitigate this problem is to validate before each call:
But, its too late, because at that point the object no longer trust its internal data, and that pattern |
||||
|
|
|
When switching between PHP and C♯/Java, I often forgot and write ' instead of " for string constants and end up having compiling errors. Like: PHP
C♯
|
|||||||||
|
|
I love the a =+ 1; believing that a will be incremented. |
||||
|
Forgetting to terminate a worker thread when a GUI app exits, so the process continues to run, out of sight. |
||||
|
|
And in OCaml language I'm currently using, it's common to use "physical equality operator" "Physical equality" means "these two identifiers refer to the same object", contrary to "refer to (possibly different) equal objects". It has synnonyms in other languages as well. |
||||
|
|
|
Assuming that default arguments in Python are not shared between function calls. |
||||
|
|
|
Catching exception that you don't know how to recover from, or catching a large family of exceptions (or even all exceptions) and not re-throwing when you encounter one that you don't know how to handle. In .NET, not bothering to look up what exceptions can be thrown in the documentation (or even the intellisense tooltip) and allowing exceptions that you should have caught (and either recovered from or wrapped and thrown) be bubbled up and to a caller who neither expects them nor understands them. |
|||||||||
|
|
Over reliance on refactoring tools, and code assistance tools (CodeRush / Resharper, etc). Don't get me wrong, I love CodeRush, but they shouldn't be used solely to write the code. In my mind a coder should be able to write code, and use them to assist where necessary. |
||||
|
|
|
One programming error I've seen a ridiculous number of times: Bad list management.
If you ever see this problem, you'll have to review the whole codebase. You're going to see flavours of this problem in multiple places. |
||||
|
|
|
Worst thing I ever saw was a fellow student who wrote something like this:
and was getting some weird weird errors. See if you can spot the error... |
|||||||||||||
|
|
In managed memory platforms: keeping a reference to an object for more time than it is needed causing memory to grow constantly and thinking that "the garbage collector doesn't work". I have seen it many times while troubleshooting applications made by programmers new to .NET or Java. |
||||
|
|
|
Directly using variables without defining it in Javascript. Hence variables will have global scope. And programmer spends whole time debugging the scripts!! |
|||||
|
|
A misplaced semicolon beside a while loop.
|
|||||
|
|
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:
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:
which tells the compiler "no, really, I want these to be different declaration spaces". |
|||||||||
|
|
Test using assignment
Mhh I wonder we never execute the else part |
|||||||||||||||||
|
|
While taking 101, my teacher and I were combing through a student's program because it wouldn't compile. As it turns out, he used
instead of
everywhere in his program. Three hours of my life that I will never get back. |
|||||||||
|
|
Recursive properties in C#:
Doesn't happen so often now we have auto-properties, but it's still something I wish the compiler would pick up on. |
||||
|
|
|
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:
(I am guilty of this one myself). |
||||
|
|
Character encodingWorking with Unicode: converting to/from/between Very closely related: string escaping and unescaping, the bane of too many websites. |
||||
|
|
|
Typos How come no one said anything about typos Are all of them that much confiednt oops did it again |
||||
|
|
