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

There’s a nice list of this feature by language on the Wikipedia page for anyone interested: https://en.wikipedia.org/wiki/Null_coalescing_operator#Examples_by_languages

permalink
report
reply
0 points

This was my first time actually seeing a Rust example, and I hate it.

permalink
report
parent
reply
0 points

Other languages: if a is null return b.

Rust: here is an array of strings, we are going to parse the array to numbers. If that conversion fails we handle the exception and return the minimum integer value. We then save the result in a new vector. We also print it.

I like rust, but I hate the example too. It’s needlessly complex. Should have just been a.unwrap_or(b).

permalink
report
parent
reply
0 points

You’ll be happy to hear I’ve updated the example to be not bad

permalink
report
parent
reply
0 points
*

I wanted to ask why it’s bad, what did you change?

Btw. the example function get_default is badly chosen, because unwrap_or_default exists.

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