this post was submitted on 28 Mar 2024
246 points (94.2% liked)

Rust

5999 readers
5 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 1 year ago
MODERATORS
 

Slide with text: “Rust teams at Google are as productive as ones using Go, and more than twice as productive as teams using C++.”

In small print it says the data is collected over 2022 and 2023.

you are viewing a single comment's thread
view the rest of the comments
[–] orclev@lemmy.world 2 points 7 months ago* (last edited 7 months ago) (1 children)

Yeah as far as I'm concerned null is public enemy number one. I refuse to work in any language that doesn't allow me to indicate in some fashion that a variable is non-nullable. I just about had an aneurysm when I found out that JavaScript not only has null, but also nil and undefined and they all mean something subtly different. To be fair though, JavaScript is like a greatest hits of bad language design.

[–] sugar_in_your_tea@sh.itjust.works 2 points 7 months ago (1 children)

JavaScript doesn't have nil, but it has null, NaN and undefined.

But yeah, wrapping null in an Option is a really nice.

[–] orclev@lemmy.world 2 points 7 months ago (1 children)

It sort of has nil. While a type can be null or undefined when evaluated, nil is used in many of the JS libraries and frameworks to mean something that is either null or undefined. So you'll see functions like function isNil(value) { return value == null || value == undefined } and they'll sometimes often confuse things even more be actually defining a nil value that's just an alias for null which is just pointlessly confusing.

As an aside, basically every language under the sun has NaN as it's part of the IEEE floating point standard. JavaScript just confuses the situation more than most because it's weakly typed so it doesn't differentiate between integers, floats, or some other type like an array, string, or object. Hence anything in JS can be a NaN even though it really only has meaning for a floating point value.

[–] sugar_in_your_tea@sh.itjust.works 3 points 7 months ago (1 children)

function isNil(value)

We instead have function isNullOrUndefined(value) ... instead, but it does the same thing.

It's especially lame since you can't just do if (!value) ... since that includes 0 (but not [] or {}, which Python considers falsey). It's remarkably inconsistent...

basically every language under the sun has NaN

Yup, but you can use NotNan in Rust, just like your NonNull example.

And yeah, it's weird that JavaScript doesn't have an integer type, everything is just floating point all the way down. I actually did some bitwise logic with JavaScript (wrote a tar implementation for the web), and you get into weird situations where you need to >>> 0 in order to get an unsigned 32-bit integer (e.g. (1 << 31) >>> 0). Those hacks really shouldn't be necessary...

[–] orclev@lemmy.world 3 points 7 months ago

Because it's floating point it also causes some REALLY strange bounds on integers. The maximum sized int you can safely store in JS is a 53 bit integer. That caused us all kinds of headaches when we tried to serialize a 64 bit integer and it started producing garbage results for very large values.