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 to close connections. (HTTP, database, whatever.) Closing the connections prematurely. |
|||||
|
|
Writing
instead of
|
|||||||||||||||||||||
|
|
In C#, using |
||||
|
|
|
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. |
|||||||||||||
|
|
Test using assignment
Mhh I wonder we never execute the else part |
|||||||||||||||||
|
|
Forgetting the |
|||||||||||||
|
|
Doing this in C/C++ :
It will cause compilation error elsewhere in your code. |
|||||
|
|
Directly using variables without defining it in Javascript. Hence variables will have global scope. And programmer spends whole time debugging the scripts!! |
|||||
|
|
I saw quite a few errors with missing break in switch statements (C++, Java). Fortunately C# forbid this practice.
|
|||||||||||||
|
|
I love the a =+ 1; believing that a will be incremented. |
||||
|
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. |
||||
|
|
Character encodingWorking with Unicode: converting to/from/between Very closely related: string escaping and unescaping, the bane of too many websites. |
||||
|
|
|
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. |
||||
|
|
|
Forgetting to terminate a worker thread when a GUI app exits, so the process continues to run, out of sight. |
||||
|
|
|
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 |
||||
|
|
|
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. |
|||||||||
|
|
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. |
||||
|
|
|
||||
|
|
|
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♯
|
|||||||||
|
|
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. |
||||
|
|
|
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. |
|||||||||
|
|
Forgetting if string functions are 0-based or 1-based with whatever language I'm using I'm always getting the wrong index when trying to parse a string using string functions because it's different for different languages. It almost always takes me more then one try to get it right. For example...... I want a substring of a string starting at the index of X and ending at the index of Y... That's |
||||
|
|
|
I always write "pubic" instead of "public" in Java method signatures. Not really a functionality changing mistake, but a funny one all the same |
|||||
|
|
A misplaced semicolon beside a while loop.
|
|||||
|
|
Assuming that default arguments in Python are not shared between function calls. |
||||
|
|
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. |
||||
|
|
|
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. |
||||
|
|
|
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... |
|||||||||||||
|
