News for hackers. Stuff that matters.
Re:Sshole by f33d5173 on Friday November 06, 2026 @12:21PM (#50395327)
.unwrap()

Now what?

Re:Sshole by shakow on Friday November 06, 2026 @12:44PM (#50395636)
First you shouldn't have unwraps in prod code, and you can verify that in your CI/build process/whatever. Second, now you have a crash of the SSH server, which is arguably much better than some random logging in as root.
Re:Sshole by f33d5173 on Friday November 06, 2026 @04:38PM (#50398870)
This isn't about "you", it's about whether any consumer of your code is using unwrap on the result, which currently is perfectly safe to do. The equivalent in C is returning NULL, which would also have caused a crash. They decided not crashing was preferable, which is how we ended up here.
Re:Sshole by kazinator on Friday November 06, 2026 @06:15PM (#50399812)
[delayed]
Re:Sshole by shakow on Friday November 06, 2026 @09:01PM (#50400932)
I don't really care about the form of the argument when the concrete results are that (i) “no unwrap in prod” is trivial to ensure through the toolchain, (ii) even though, its consequences are “damn it crashed” instead of “welp I guess this guy is root now”.
Re:Sshole by kazinator on Sunday November 08, 2026 @01:57AM (#50411035)
[delayed]
Re:Sshole by shakow on Sunday November 08, 2026 @05:31AM (#50412000)
> And that analogous situation can happen in the safer language where crypt returns an Optional(String) which some bad programs assume is always present.

Once again, no, because these unknown programs would just crash on the `.unwrap()`; not get in a silently corrupted state. Same causes, different effects.

Re:Sshole by kazinator on Sunday November 08, 2026 @11:38AM (#50414753)
[delayed]
Re:Sshole by dadoum on Saturday November 07, 2026 @06:46AM (#50403712)
Absolutely not. Unwrap is a language rule, so everyone knows unwrap is not a safe thing to do and writing it even once is an explicit dismissal (and you should document it). On the other side, knowing that crypt does not necessarily return a hash is easily overlooked and forgotten, there is no code smell that can hint you that you are doing things wrong.
Re:Sshole by kazinator on Saturday November 07, 2026 @10:34AM (#50405412)
[delayed]
Re:Sshole by ahepp on Friday November 06, 2026 @06:00PM (#50399658)
I think the argument would be that in C people will look at a char* and think "string" rather than "string or null". Thus consumers of the library not checking the result and the maintainer trying to be helpful by putting a "safe" value in there for the error case.

Whereas if the library returns something that is unambiguously an option type, consumers unambiguously call unwrap at their own risk.

Of course you do have a point (assuming I'm picking up what you're suggesting correctly) that all pointers in C are option types. But I think there's a cognitive ergonomics aspect to this where an option type more clearly relays the library authors' intent.

Re:Sshole by eviks on Saturday November 07, 2026 @12:26PM (#50406288)
Now you have an easy way to discover the bug