General statistics
List of Youtube channels
Youtube commenter search
Distinguished comments
About
Dr Gamma D
ArjanCodes
comments
Comments by "Dr Gamma D" (@DrDeuteron) on "ArjanCodes" channel.
Previous
1
Next
...
All
@ArjanCodes the first step to becoming a Pystro is forgetting all other languages.
19
I find list[int] typing unpythonic. It's nice to know what a function expects, but if you want many ints, use an array of int, where trying is both obvious and enforced. The point of a list is 2-fold: it's mutable, its elements are "any". The point of array.array(int, ) is that it's an ordered container of ints. I know it's not practical to implement, and no one uses the array from the standard library, so: j/s.
3
WET: Write Everything Twice. can get WETTT: Write Everything Ten Thousand Times. Rule of Three notwithstanding.
2
well at this point, make a Cart class and put it in methods with a default _discounted=False class attribute.
2
Around 9:20 I don't like it. If dunder init takes 1 attribute, then the instance should have one attribute. info='worker' should be a class attribute, since it's the same for all instances of the Worker class. A video on the horrors of bad instantiation practices (setting would-be class attributes, nullary instantiation followed by, barf.. setters...a major problem with Java ppl, and the greatest sin: doing work!) would be helpful to a lot of pythoneers.
2
because the choices are unordered and unique, so a set is a better match than a list. If there is no order, don't use a list.
1
only 5:40 in, never used an enum. I'd make a Role a class and attribute payment to it, and let the Employee class call a pay method.
1
at 6:11, I would return type(self)(...). not Vector(...)...b/c you never know. I would also, to avoid writing more code do subtraction via: def __neg__(self): return type(self)(-self.x, -self.y) def __sub__(self, other): return self + (-other)
1
@IronicHavoc it is. But moved beyond that years ago, and you can address me as: Pystro.
1
I so agree with the error handling. Builtin errors are for straight screwups breaking python. Custom errors are for things that break your abstractions.
1
and _rmul_ for dilation.
1
@lazerbro omg. what? my version doesn't have it tho. We got security lags.
1
The class attribute behavior is great. An instance look up starts at "self", and then checks type(self). It makes class attributes the place to set instance defaults. When I see: self.foo = foo and "foo" is NOT a dunder init argument, I lose it. Example: a car class: class Car: crashes = 0 def crash(self): self.crashes += 1 then: >>>car = Car() >>>car.crashes 0 is the class variable. But after: >>>car.crash() >>>car.crashes 1 is the instance attribute. Python is a language where, as with timer.counter, and the main() at 21:40 , you should never modify instance attributes outside of instance methods, Major code smell.
1
smell -> stench -> sin
1
timestamp?
1
If all a function does is return errors, why call it?
1
cyclomatic_complexity -= 1 ftw.
1
Yeah, raising a value error for a country code? That’s a custom exception.
1
But I already extended datetime.datetime to include leap-seconds, with operator overloads and 60 seconds in the init….on actual leap-seconds. So no pendulum for me
1
btw: if you want to do coordinate independent scalar products on your vectors, define a norm: def __abs__(self): return pow(self.x**2 + self.y**2, 1/2) and then: def __mul__(self, other): return (abs(self + other)**2 - abs(self - other)**2) / 4 works on any vector with a norm, without regards to internals.
1
Regarding Employee, Manager, etc. I would have them all inherit from a base class and return a class attribute that describes roll.
1
wait, isn't the >>>a.some_attr is X.some_attr rendered pointless by the weirdness No 1: integer caching?
1
Previous
1
Next
...
All