You are viewing a single thread.
View all comments
0 points
*

Ruby:

a || b

(no return as last line is returned implicitly, no semicolon)

EDIT: As pointed out in the comments, this is not strictly equivalent, as it will return b if a is false as well as if it’s nil (these are the only two falsy values in Ruby).

permalink
report
reply
0 points

Python:

return a or b

i like it because it reads like a sentence so it somewhat makes sense

and you can make it more comprehensive if you want to:

return a if a is not None else b

permalink
report
parent
reply
0 points
*

This diverges from the OP code snippets if a has the value False.

permalink
report
parent
reply

Programmer Humor

!programmerhumor@lemmy.ml

Create post

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

  • Posts must be relevant to programming, programmers, or computer science.
  • No NSFW content.
  • Jokes must be in good taste. No hate speech, bigotry, etc.

Community stats

  • 6.7K

    Monthly active users

  • 796

    Posts

  • 7.3K

    Comments

Community moderators