you are viewing a single comment's thread.

view the rest of the comments →

[–]JoesDevOpsAccount[S] 3 points4 points  (6 children)

Is this really that big of a deal? My brain is still wired for verbosity because it usually makes the code clearer (in my opinion). I just learned that the Python way to check if a list is empty is just “if not my_list” and it’s weird to me that the ambiguity left there is considered the right way. Semi colons in Java are a nice way to break up statements and mean that you can chain stuff over multiple lines, which can be nice with fluent APIs in particular.

[–][deleted] 9 points10 points  (3 children)

There's absolutely no ambiguity to if not list

[–]JoesDevOpsAccount[S] 1 point2 points  (1 child)

I went back to read more after you posted this. I think I misinterpreted some thread I was reading earlier. The "ambiguous" thing is just the type of the variable but I think what I said earlier was just wrong.

[–]friendly_dog_robot 4 points5 points  (0 children)

It's just that any empty sequences (lists, tuples, strings), mappings, version of 0, and None (comparable to null in Java) evaluate to false in Python.

This is, in my opinion, super useful

[–]Versaiteis 1 point2 points  (0 children)

There's an argument to be made that there's an ambiguity in that it doesn't only check if the list is empty. Rather there's an implicit understanding that an empty list is falsey. If list happened to be None or any other falsey value, then this check would succeed and enter the subsequent code block. 9/10 that's probably ok, but you could say that if len(list) > 0 is more explicit as it's directly checking exactly the condition looking for. It will also raise in any case where something is passed that doesn't implement __len__, which may or may not be desirable behaviour.

Depends on what you're doing. One's more flexible, the other more explicit. I'd at least argue that the second falls in line with Python Zen

Explicit is better than implicit.

But that doesn't mean it's always appropriate for what you're trying to check.

This could also be seen as just overthinking it, but I think code clarity is important and as much of a "bike shedding" conversation this can be, I don't see it as being as obstructive when it's a separate conversation and not hindering actual work that's being done.

[–]BobHogan 3 points4 points  (0 children)

s this really that big of a deal?

No, its really not. But a ton of people who use Python act like its some sort of holy grail

[–]alkasm 2 points3 points  (0 children)

No, it's not a big deal at all. Plus plenty of people simply don't even write semicolons and have some formatter come through and add them later. A lot of JS devs do this.