gigachad

joined 1 year ago
[–] gigachad@sh.itjust.works 1 points 9 hours ago

To be fair - this was a non-aggression pact, nothing about an alliance.

[–] gigachad@sh.itjust.works 1 points 1 week ago (1 children)

Sir, I will make sure to never bother you with a PR and my terrible, terrible code ;)

[–] gigachad@sh.itjust.works 3 points 1 week ago* (last edited 1 week ago) (3 children)

This is what I would come up with:

try:
    if len(foo) == 0:
    ...
except TypeError:
    ...

There is no need to add a None check, as foo being None should be considered as a faulty input. Avoiding the possibility of foo being None from the beginning using static checks or testing is of course the preferred solution. But in reality we do not work in such optimal environments, at least I can say that from the perspective of data science, where often procedural, untested code is produced that runs only a few times. But I get your point and I think both paths are viable, but I am also okay with being in the wrong here,

[–] gigachad@sh.itjust.works 1 points 1 week ago (2 children)

I am not saying it's better, just that I don't like the proposed way :) I would argue that being "pythonic" has even less value than the Zen, which I quoted because it's true, not because it is some strict rule (which it isn't anyway).

You could argue I also need to write that extra code for the if not case, as I explicitly have to check if it is None if my program somewhere further down expects only lists.

Hunting for those sweet milliseconds is a popular game in the Python community ;) if this mechanism is that important for your program, you should definitely use it, I would do as well!

[–] gigachad@sh.itjust.works 6 points 1 week ago* (last edited 1 week ago) (10 children)

But None has no len

if not foo:  

-> foo could be an empty list or None, it is ambiguous.

len(foo) will lead to an exception TypeError if foo is None, I can cleanly catch that.

It suggests I deal with a boolean when that is not the case. Explicit is better than implicit, and if not foo to check for an empty list may be pythonic, but it's still implicit af

[–] gigachad@sh.itjust.works 6 points 1 week ago (12 children)

I don't like it very much, my variable could also be None here

[–] gigachad@sh.itjust.works 12 points 1 week ago* (last edited 1 week ago) (3 children)

Absolutely agree. I just use it for some simple stuff like "every nth row in a pandas dataframe slice a string from x to y if column z is True" or something like that. These logics take time to write, and GPT usually comes up with a right solution or one that doesn't need a lot of modification.

But debugging or analyzing an error? No thanks

[–] gigachad@sh.itjust.works 24 points 2 weeks ago* (last edited 2 weeks ago) (1 children)

Why is the European Space Agency speaking up to this topic

[–] gigachad@sh.itjust.works 46 points 1 month ago (7 children)

...as reported by the South China Morning Post lol

[–] gigachad@sh.itjust.works 25 points 1 month ago (5 children)

Maybe or maybe not. Being long-term invested (>15 years) will solve this issue for you. Studies suggest you probably realized a loss and will also miss the entry point when stocks are going up again. Remember folks, time in the market beats timing the market.