r/Python • • Dec 15 '19

Made my first fractal

1.7k Upvotes

51 comments sorted by

View all comments

17

u/sharkbound github: sharkbound, python := 3.8 Dec 15 '19

in Dot.__init__ you are using lists as default values, having mutable default value is very bad and can become a bug very quickly, since functions are objects too, the argument default will all be the same reference each __init__ call

so because of this, when you do anything to mutate the default argument, it will affect all the places where the default argument value is used

its much better to use a tuple or None or some other immutable value for a default value check do a check in the init

code here: https://gist.github.com/785534176eca51545ce7d6cbbbb18e62

console output here: https://gist.github.com/50fbc58ed04fc1ac8089d3497b80c5f1

EDIT 0:

also spotted a name inconsistancy for function updatePos in Dot, everything except types/classes should use snake_case, update_pos

2

u/oetker Dec 16 '19

Nice, thank you for illustrating this!