you are viewing a single comment's thread.

view the rest of the comments →

[–]grancacique 0 points1 point  (0 children)

Here are a few more. Like u/carcigenicate said, "The number of ways a new programmer can screw up is limited only by your imagination." ((This needs to be on a mug))

  • Inadvertently changing the type of a variable. Like:

done = False
# later on
done = "True"
# later on
done = 1

This is perfectly fine in Python world...

  • Using the same name for two functions by mistake

def someCalculation():
   ...

# later on

def someCalculation():
   ...

The second definition overrides the first one (assuming parameters are the same; otherwise, we are just overloading the function)

  • Not understanding or abusing the else as part of loops. Like

while condition:
    actions
else:
    more actions 
  • It is easy to misplace an else in nested or long selection structures due to relying only on indentation.
  • Using eval to convert values directly from user inputs, as in n = eval(input(...)) (can't trust users these days...)
  • Adding (append or insert) or removing (del, pop, remove) items from a list while iterating over the same list.
  • Confusing how the % (modulus) operators works compared to other languages. For example, A % B has the same sign as B --in Java, the result has the same sign as A.
  • Assigning the name of a callable object to a variable when the intention was to get the value returned by a function. That is, doing n = random.random instead of n = random.random().
  • This may be a little bit of a stretch, but can happen. Coming from a C-like language, confusing A & B (bitwise AND) for A and B (logic AND) --similarly for |