mathstodon.xyz is one of the many independent Mastodon servers you can use to participate in the fediverse.
A Mastodon instance for maths people. We have LaTeX rendering in the web interface!

Server stats:

2.8K
active users

I can't believe how much of my pre #rust life I spent with only numbers that could be negative, instead of "this will absolutely not go below 0".

I should really consider starting to use the NonZero* types, too, but I've never really had an obvious opportunity to...

Anyway, here's to staying positive.

Cassandra Granade

@zkat It honestly drives me nuts how, even in languages like C and C# that have unsigned types, no one bloody uses them. Like .NET is filled with things that are Int32 but should be UInt64 (even well after 32 → 64). I think it's partly the culture of Rust to be precise, not just the language?

@cgranade these days I get very very confused when I see an api that uses signed ints, because it makes me wonder if they’re using -1 as a sentinel, which I hate

@zkat I'm honestly not sure what's worse, using it as a sentinel or just using signed ints for lolz and hoping people guard against < 0 correctly.

@cgranade @zkat I don't know what it's worth to you, but Google's C++ style guide google.github.io/styleguide/cp goes into why they're opposed to the use of unsigned integers, and that explicitly checking for > 0 is preferred.

google.github.ioGoogle C++ Style Guide

@ilyvion @zkat That seems like such a weird argument to me. If you have a value where it is always a bug for it to be less than zero, why include negative numbers in the domain of that value's type? If there's something else like wraparound, solving it by using the wrong type feels very suboptimal by comparison to using checked arithmetic. Seems like they're effectively using negative numbers as a hack to get checked arithmetic in, but that's a disaster and a half waiting to happen...

@ilyvion @cgranade their justification is about integer overflow/underflow, which is just not the case in Rust.

@zkat @cgranade I was mainly trying to show why it could be the case that "even in languages like C and C# that have unsigned types, no one bloody uses them." Though I don't know how the rules are in C# and C vs C++, I just happened to know that Google specifically had rules against them for C++.

@ilyvion @cgranade @zkat I admit that on a language that can't or won't statically enforce valid values it might make sense to allow and explicitly check for invalid states rather than accepting and running with wrong but technically valid states.

@clacke @zkat @ilyvion I mean, if a type in a language can't meaningfully express constraints on the valid values of that type because of other crap in the language, then what's the point of types in the first place? All the more reason I'm glad I don't have any cause to work in C or C++...

@cgranade @zkat I have spent many a code review flagging inappropriate uses of signed types. They learn eventually, with enough repetition

@cgranade @zkat the precision in Rust comes from the lack of automatic type coercion. Container sizes are usize, so you either need to cast (ugly) or get the type right in the first place

@cgranade @zkat incidentally, I once thought that Rust requiring explicit type conversation was insane. Then I was trying to reason out what the code of one of my junior coworkers would do based on the C++ language specification, and quickly came to the opposite conclusion