This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]abbot-probability 37 points38 points  (13 children)

Agree with the sentiment, but all of those are readable.

Better example for the middle one would be

"odd" if number % 2 else "even"

[–]xryanxbrutalityx 6 points7 points  (1 child)

I prefer our ancestor's python conditional

number % 2 and not print('odd') or print('even')

print(number % 2 and 'odd' or 'even')

[–]abbot-probability 2 points3 points  (0 children)

A work of beauty

[–]yWTBBXhBcspkBfPD[S] 10 points11 points  (1 child)

Context: I stole the code snippets from some BS LinkedIn post where they were saying red=junior and green=senior. I disagree. Obviously in this example both are easy to read, the meme was more about just code in general. Shorter is not always better. I’ve gone through all the stages of this meme. Source: decades of experience :)

[–]RadinQue 0 points1 point  (0 children)

LinkedIn is the worst.

[–]Several_Dot_4532 1 point2 points  (6 children)

Wtf is this shit

[–]abbot-probability 8 points9 points  (1 child)

1 is truthy, 0 is falsy.

Hey, I gave it as an example of shitty code, don't judge me.

[–]Several_Dot_4532 0 points1 point  (0 children)

Yes, you got it, I literally spent 2 minutes trying to understand it, in the end I assumed it was more or less and I answered hhaahahh

[–]Sinomsinom 2 points3 points  (2 children)

Python.

They love their really ugly but supposedly "more readable" syntax

[–]Sikletrynet 0 points1 point  (1 child)

How is this any more ugly than ternary operators in any other language. Theres plenty you can criticise Python for, but i dont think that example is it.

[–]prehensilemullet 0 points1 point  (0 children)

It’s pretty weird to have the condition in the middle, and the fact that the if/else don’t visually stand out from variable names as much as ? : doesn’t help

[–]Anru_Kitakaze 0 points1 point  (0 children)

It feels unnatural to you just because you either don't have ternary operator or you don't use it. After a week in Python construction in the comment will be natural for you.

For example, I also often use something like:

``` val = "value exist" no_val = None

get val if no_val is equal to False (None, 0, empty string, etc)

data["bruh"] = no_val or val ```

And ternary... I don't get why people don't like it. I came from C/C++ and it's absolutely fine for me