5 ms·
I sum my booleans all the time in python, but other than that I agree. This whole mutating or not mutating thing was a huge headache when starting python and s
by wodenokoto 7y ago
I sum my booleans all the time in python, but other than that I agree.
This whole mutating or not mutating thing was a huge headache when starting python and still causes gotchas.
R is supposedly the “poorly designed” programming language that data scientists may use instead of python, but I’ve never had such problems in R.
- tempguy9999 7y ago> This whole mutating or not mutating thing was a huge headache when starting python and still causes gotchas. Well, I'd say 1) immutability is expensive[0] and 2) mutability is sometimes simpler and clearer than immutability for some algorithms IMO. So I'd want python to have both. Today's passion for 'immutable everything' is going to burn out pretty quick as it's great but being used too much and without recognising its cost. IMO again. [0] if naively implemented, and it so often is.
- brianberns 7y agoI think mutability is fine, but there should be some syntactic difference in the usage to alert the user.
- wodenokoto 7y agoR doesn’t have strict immutability. I’m not sure which data structures in R are mutable, but I’m sure it’s most, as a common operation is to change the values of a subset of a list/vector/dataframe. So my point is not “python is hard because of mutability” it’s that pythons mutability really gets in the way of the beginner and causes lots of gotchas for even well experienced developers.
- tempguy9999 7y ago> So my point is not “python is hard because of mutability”... ok > ...it’s that pythons mutability really gets in the way of the beginner and causes lots of gotchas for even well experienced developers So python is hard because of mutability? (well, harder anyway). The fact is, if python had immutability it'd be semantically simpler. Unquestionably (I'd claim). But that comes at a performance cost, so mutability is allowed. That's when we get these confusions of what an operation does (because the semantics get non-simple). My point is either way we pay a price. Anyway I have a feeling I may be misconstruing your point, sorry if that's so.
- tempguy9999 7y ago> I sum my booleans all the time in python, but other than that I agree. Use any/all instead? <https://stackoverflow.com/questions/31099561/test-if-all-elements-of-a-python-list-are-false> https://stackoverflow.com/questions/31099561/test-if-all-ele.... More general (see my other post), shorter and clearer?
- dagw 7y agoOften I want to know how many items are True, not just if all/some/none are True.
- wodenokoto 7y agoI get my averages from sum(list_of_bools) / len(list_of_bools) and np_array_of_bools.mean() There is probably a more correct way, but I enjoy it.