In general, typo questions aren't useful for other readers, can be resolved in comments, then closed as typos & deleted.
But there are cases where pointing them typos out in answers is useful for future readers, because they'll make a mental note that this is an easy trap to fall into (and that is, if the question is concise enough, that doesn't apply to "wall of code" questions / no MCVE, so OP already figured out approximatively where the problem lies)
Some classical examples I've seen a lot:
in C/C++/Java/JavaScript (semicolon after the test (if
, while
), making the following statement execute no matter what):
if (a==0); {
printf("a is 0\n"); // or System.out.writeln :)
}
in C/C++/Java (assigning instead of testing, so condition is never true)
if (a=0) {
printf("a is 0\n"); // or System.out.writeln :)
}
In C, mistakingly activating complex numbers gcc
extension (printing same float value always):
t=(100/(1+2i)); // instead of t=(100/(1+2*i));
In C/C++, swapping !
and =
in a test, resulting in the left operand taking a boolean value instead of comparison (yes it's possible (10K+)):
if (i =! j ) {
In C/C++/Java (trying to increment/decrement but assign to +/-1
instead):
a=+1;
a=-1;
In C/C++ testing a condition within quotes:
if("delta>0")
In C/C++ incrementing 1
instead of i
(yes, it's possible to do such a mistake, 10k+ only link)
for(int i = 1; i < 13; 1++)
in Python (testing instead of assigning, does nothing):
if a:
b==True
In Python (trying to increment/decrement but assign to +/-1
instead):
a=+1
a=-1
In Python, copying/pasting C/C++ code with pre-increment operator gives infinite loop/doesn't loop but is syntaxically correct:
while (a[++i]<0) or (a[--j]>0):
In Python assigning to class/function but not calling it:
handle.close
(see also an original Python strange-result typo here, OPs are very creative :))
In Python bad luck typo when defining a dictionary that triggers string concatenation:
>>> {"a":"b","composers:componisten" "two":"twee"}
{'a': 'b', 'composers:componistentwo': 'twee'} # second key is bogus but syntax is OK
In Python, trying to open a Windows file without the raw prefix, resuting in python interpreting the escape sequences:
with open("C:\tools\a.txt") as f:
python wrong way of protecting conditions, leading to an always truthy result:
if [condition1 and condition2]:
(seen in Simple IF statement in Python 2.7)
Trying to catch several exceptions with and
(resulting in only the last exception type being catched):
except KeyError and IndexError:
Python Ored regex with or operator outside the string (TypeError from use of "|" in re.search("RE"|"RE"|"RE", string))
re.search("UP"|"DOWN"|"LEFT"|"RIGHT", moves)
Python using __neq__
instead of __ne__
: Why does the != operator not call my '__neq__' method?
The consequences of those typos is not a clear error message, the code runs, but with very bizarre behaviour.
It's interesting to have canonical Q&As to link to those (specifically) when it happens, maybe create a canonical-duplicate
tag for quick search.
Those canonical answers should point out the problem, but also have to explain how to prevent such errors in the future (Python: use PyCharm
for early error detection, C/C++: use CppCheck or some verification too, enable all warnings...) so the user doesn't get caught next time.
preserveaspectratio
instead ofpreserveAspectRatio
, should they post a new question about that? We might end up with many questions that refer to the same root cause.viewBox
, but for all SVG markup. So except if you really had this problem caused by the same exact attribute, you would never have found this Q/A (or OP would probably have found one of these other ones before asking his question.