frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Flow Control: a progammer's text editor

https://flow-control.dev/
1•createaccount99•1m ago•0 comments

Explaining, at some length, Techmeme's 20 years of consistency

https://news.techmeme.com/250912/20-years
1•vinhnx•4m ago•0 comments

How CISOs Can Build an Effective 90-Day AI Security Strategy

https://medium.com/@abdelghani.alhijawi/the-cisos-90-day-ai-security-plan-c23372ee1adc
1•aalhijawi•4m ago•0 comments

Show HN: A better Hacker News front end

https://hakkernieuws.vercel.app/top
1•AntonioEritas•5m ago•0 comments

Ask HN: How do I get a job in OS and networks as a new grad?

1•kaladin-jasnah•6m ago•0 comments

Orcas Sink Sailing Yacht with Family of Five Off Portugal

https://maritime-executive.com/article/orcas-sink-sailing-yacht-with-family-of-five-off-portugal
1•TMWNN•6m ago•1 comments

How to Watch the Olympics of the Piano World

https://www.nytimes.com/2025/10/18/arts/music/chopin-piano-competition-final.html
1•mykowebhn•10m ago•0 comments

Astroimmunology: The effects of spaceflight and its stressors on the immunity

https://www.nature.com/articles/s41577-025-01226-6
2•XzetaU8•12m ago•0 comments

I built an AI that replaces spreadsheets

https://wealth-ai.in/
1•asaws•14m ago•1 comments

New benchmarks (i.e. Nvidia canary) in HuggingFace ASR leaderboard

https://huggingface.co/spaces/hf-audio/open_asr_leaderboard
1•pinter69•17m ago•0 comments

Brussels opens the door to reviewing the ban on ICE vehicles from 2035

https://www.coface.com/news-economy-and-insights/brussels-opens-the-door-to-reviewing-the-ban-on-...
1•teleforce•19m ago•0 comments

Show HN: Nova: Open-source solution for CAD file conflicts

https://github.com/agg111/nova
1•aishwaryagune•20m ago•0 comments

The Risk That Built America

https://www.nytimes.com/2025/10/18/business/dealbook/the-risk-that-built-america.html
1•JumpCrisscross•29m ago•0 comments

TooLoo – Extract thinking patterns from any conversation using AI

https://tooloo-ai.loca.lt
1•oripridan•30m ago•1 comments

Test1

1•oripridan•34m ago•0 comments

VisiCalc on the Apple II

https://stonetools.ghost.io/visicalc-apple2/
1•hggh•42m ago•0 comments

The Travel App I Couldn't Find, So I Built It

https://www.indiehackers.com/post/the-travel-app-i-couldnt-find-so-i-built-it-YMaLtfORnlJmAUS2ej92
2•jollytango•47m ago•0 comments

All You Wanted to Know About Stdio

https://memorici.de/posts/make-or-break-stdio/
2•Bogdanp•54m ago•0 comments

Happy birthday to the NES, companion to Nintendo childhoods

https://www.theguardian.com/games/2025/oct/18/happy-birthday-to-the-nes-nintendo-entertainment-sy...
1•mindracer•1h ago•0 comments

The mind's best trick: how experience (the illusion?) of conscious will (2003)

https://www.sciencedirect.com/science/article/abs/pii/S1364661303000020
2•marshfram•1h ago•0 comments

The AI Bubble and the US Economy

https://mronline.org/2025/10/17/the-ai-bubble-and-the-u-s-economy/
1•pongogogo•1h ago•2 comments

AI – 2025 Stack Overflow Developer Survey

https://survey.stackoverflow.co/2025/ai
1•kamaraju•1h ago•0 comments

Avis Crocombe

https://en.wikipedia.org/wiki/Avis_Crocombe
1•zeristor•1h ago•0 comments

A laser pointer at 2B FPS [video]

https://www.youtube.com/watch?v=o4TdHrMi6do
2•thunderbong•1h ago•0 comments

What chefs and doctors eat when they're sick or hungover

https://www.theguardian.com/food/2025/oct/18/what-chefs-doctors-eat-when-sick-hungover
1•rippeltippel•1h ago•0 comments

Best

1•sreekesh•1h ago•0 comments

Show HN: Nova: open-source solution for CAD file conflicts

1•aishwaryagune•1h ago•0 comments

Packaging: Sound Removals

https://blog.jak-linux.org/2025/10/18/sound-removals/
1•JNRowe•1h ago•0 comments

Nexperia's Long History, Tangled Present, and Uncertain Future

https://thechipletter.substack.com/p/the-tangled-past-present-and-future
1•chmaynard•1h ago•0 comments

Big week for unions at Blizzard as Hearthstone team also votes to unionize

https://aftermath.site/hearthstone-union-blizzard
3•riffraff•1h ago•0 comments
Open in hackernews

Don't unwrap options: There are better ways (2024)

https://corrode.dev/blog/rust-option-handling-best-practices/
100•mu0n•5mo ago

Comments

ChadNauseam•5mo ago
let-else is awesome. definitely my favorite rust syntax. The compiler checks that the else branch will “diverge” (return, panic, break, or continue), so it’s impossible to mess it up.

the article says “It’s part of the standard library,” which gets the point across that it doesn’t require any external dependencies but it may be slightly misleading to those who interpret it literally - let-else a language feature, not part of the standard library, the relevant difference being that it still works in contexts that don’t have access to the standard library.

I tend to use Option::ok_or more often because it works well in long call chains. let-else is a statement, so you can’t easily insert it in the middle of my_value().do_stuff().my_field.etc(). However, Option::ok_or has the annoying issue of being slightly less efficient than let-else if you do a function call in the “or” (e.g. if you call format! to format the error message). I believe there’s a clippy lint for this, although I could be mixing it up with the lint for Option::expect (which iirc tells you to do unwrap_or_else in some cases)

I appreciate the author for writing a post explaining the “basics” of rust. I’ll include it in any training materials I give to new rust developers where I work. Too often, there’s a gap in introductory material because the vast majority of users of a programming language are not at an introductory level. e.g. in haskell, there might literally be more explanations of GADTs on the internet than there are of typeclasses

progbits•5mo ago
> I believe there’s a clippy lint for this, although I could be mixing it up with the lint for Option::expect (which iirc tells you to do unwrap_or_else in some cases)

It's one lint rule which covers bunch of these _or_else functions: https://rust-lang.github.io/rust-clippy/master/#or_fun_call

frizlab•5mo ago
Swift has guard. Equally awesome.
ziml77•5mo ago
I only just learned of that let-else syntax here. I haven't kept a close eye on all the changes to the language over the years, but this is exactly what I've wanted if-let to allow.
spott•5mo ago
> Too often, there’s a gap in introductory material because the vast majority of users of a programming language are not at an introductory level.

Not for Python! There is way more “intro” to Python stuff out there than anything else…

cibyr•5mo ago
Anyhow warrants more than an honorable mention, IMO. anyhow::Context is great, and basically always an improvement over unwrap() - whatever complaints you might have about anyhow::Error, it's infinitely easier to handle than a panic.
Ar-Curunir•5mo ago
Really useful article to learn about idiomatic Rust :)

In general I think there is a lack of intermediate Rust material that teaches you common design patterns, idiomatic Rust, and so on.

Even I (someone who's written hundreds of thousands of fairly complex Rust code) learnt about the let-else style solution from this article =).

mre•5mo ago
Author here; thanks! I had the same impression, which is why I started writing these short-form articles about idiomatic Rust. The blog post overview is here: https://corrode.dev/blog/
Zambyte•5mo ago
I have been using Zig a lot lately, and I just want to share the equivalent of the let-else solution in Zig:

   const user = getUser() orelse return error.NoUser;
If you only need user for a narrow scope like you would get from match, you can also use if to unwrap the optional.

    if (getUser()) |user| {
        // use user
    } else {
        return error.NoUser;
    }
robertlagrant•5mo ago
And the same in Python:

  if user := get_user() is not None:
    # use user
  else:
    # return error
Although given the happy path code can mean you don't see the error condition for ages, I much prefer this:

  if (user := get_user()) is None:
    # return error

  # use user
aatd86•5mo ago
hehehe. reminds me of if err != nil in Go which is really not an issue in my opinion. But it seems to have become somewhat infamous in some circles.
jimbokun•5mo ago
The problem is the compiler doesn’t help you if you forget to check err.

Although it will flag unused variable. So you will have to make an effort to deliberately ignore the error value.

Still not quite as nice as the compiler forcing you to handle the error case.

int_19h•5mo ago
The problem is that idiomatic Go reuses err for multiple calls. So if you already have one call and check err after, it counts as used, and forgetting to check it on subsequent calls is not flagged.
aatd86•5mo ago
True. Not a big issue in practice and there are linters and whatnot. Variable shadowing can happen.

But it's a bit orthogonal of a concern. I do have things to say about errors but my complaints are a bit more nuanced and made with hindsight.

LtWorf•5mo ago
It is a massive problem. It's basically the worse thing about C and they decided to copy it.

Easily 60-70% of all go code is about propagating errors to the caller directly.

aatd86•5mo ago
Not C. C errors are different since they are simply numbers.

And spoiler alert, every language propagates errors. Sometimes automatically via exception handling, somewhat simply by returning error values. rust does this too.

Matter fact, even javascript might be creeping toward this model of explicit error propagation soon.

Good, because it is easier to understand.

LtWorf•5mo ago
Easier to understand and even easier to get it wrong!
fjasdfas•5mo ago
`:=` was new to me: https://peps.python.org/pep-0572/

It actually looks really natural in python, glad they added.

38•5mo ago
Python doesn't have option, so this is not the same thing at all
robertlagrant•5mo ago
What if get_user() returns something of type Optional[User]? Does that get it close enough?
fjasdfas•5mo ago
gleam:

    fn get_user_name() -> Result(String, String) {
        use user <- result.map(option.to_result(get_user(), "No user"))
        user
    }
evrimoztamur•5mo ago
Talking about unwrapping: I’ve been using a rather aggressive list of clippy lints to prevent myself from getting panics, which are particularly deadly in real-time applications (like video games). unwrap/expect_used already got me 90% of the way out, but looking at the number of as conversions in my codebase, I think I have around 300+ numerical conversions (which can and do fail!)

    [lints.clippy]
    all = "deny"
    unwrap_used = "deny"
    expect_used = "deny"
    panic = "deny"
    indexing_slicing = "deny"
    unhandled_errors = "deny"
    unreachable = "deny"
    undocumented_unsafe_blocks = "deny"
    unwrap_in_result = "deny"
    ok_expect = "deny"
an_ko•5mo ago
Does that mean your code is annotated with 300+ instances of `#[allow(clippy::unwrap_used)]` et al?
evrimoztamur•5mo ago
It was the first time I set it up, then I went through every single instance and refactored with the appropriate choice. It wasn't as tedious as you might imagine, and again, I really don't have the option of letting my game crash.

I think the only legitimate uses are for direct indexing for tile maps etc. where I do bounds checking on two axes and know that it will map correctly. to the underlying memory (but that's `clippy::indexing_slicing`, I have 0 `clippy::unwrap_used` in my codebase now).

If you begin a new project with these lints, you'll quickly train to write idiomatic Option/Result handling code by default.

p1necone•5mo ago
yoink (although I will probably allow expect - having to provide a specific message means I'm only going to use it in cases where there's some reasonable justification)
mplanchard•5mo ago
This is nice, but fairly miserable to deal with in in-module unit tests, IMO.

We get around it by using conditional compilation and putting the lints in our entrypoints (`main.rs` or `lib.rs`), which is done automatically for any new entrypoint in the codebase via a Make target and some awk magic.

As an example, the following forbids print and dbg statements in release builds (all output should go through logging), allows it with a warning in debug builds, and allows it unconditionally in tests:

    #![cfg_attr(not(debug_assertions), deny(clippy::dbg_macro))]
    #![cfg_attr(not(debug_assertions), deny(clippy::print_stdout))]
    #![cfg_attr(not(debug_assertions), deny(clippy::print_stderr))]
    #![cfg_attr(debug_assertions, warn(clippy::dbg_macro))]
    #![cfg_attr(debug_assertions, warn(clippy::print_stdout))]
    #![cfg_attr(debug_assertions, warn(clippy::print_stderr))]
    #![cfg_attr(test, allow(clippy::dbg_macro))]
    #![cfg_attr(test, allow(clippy::print_stdout))]
    #![cfg_attr(test, allow(clippy::print_stderr))]
AFAIK there isn't currently a way to configure per-profile lints in the top-level Cargo configs. I wish there were.
indiv0•5mo ago
We just set all the lints to `warn` by default then `RUSTFLAGS="--deny warnings"` when building for release (or in CI).
mplanchard•5mo ago
Yeah that is nice too, and that should also skip all the test code. I think all the clippy warnings on tests for unwrapping and such when working locally would bug me though. And at least the eglot LSP client tends to get bogged down when there are more than a thousand or so clippy warnings/errors, I have found.
quadhome•5mo ago
All but one of these come from the restriction[1][2] lint group.

I try to remember to look at new restriction lints with every Rust release. For example, here's what new with 1.86.0[3]; the `return_and_then` lint looks pretty nice.

n.b. no one should enable all restrictions lints— some are mutually exclusive, some are appropriate for specialised circumstances like `#[no_std]`. But I find them helpful to keep a project away from the wild parts of Rust.

P.S. `unhandled_errors` doesn't exist[4].

[1]: https://rust-lang.github.io/rust-clippy/stable/?groups=restr... [2]: https://doc.rust-lang.org/stable/clippy/lints.html#restricti... [3]: https://rust-lang.github.io/rust-clippy/stable/?groups=restr... [4]: https://rust-lang.github.io/rust-clippy/stable/index.html#/u...

sophacles•5mo ago
> My main gripe with this error message is that it doesn’t explain why the ? operator doesn’t work with Option in that case… just that it doesn’t.

The error in question:

> the `?` operator can only be used on `Result`s, not `Option`s, in a function that returns `Result`

It literally tells you why it doesn't work, wtf do you want?

eviks•5mo ago
Indeed, and it even suggests the 2nd solution. All you have to do is read from the top, not the bottom, of the error message
mre•5mo ago
Fair point. Your wording was a bit strong, but I assume you meant well. I will update the article.
the__alchemist•5mo ago
Something I use for situations where nesting is getting out of hand. Probably not idiomatic but, I find it practical in these cases.

  if param.is_none() {
    // Handle, and continue, return an error etc
  }
  let value = param.as_ref().unwrap(); // or as_mut
  // Use `value` as normal.
acjohnson55•5mo ago
Any advantages of this over let-else?
the__alchemist•5mo ago
I wasn't familiar with let-else...
acjohnson55•5mo ago
I just learned about it through this article, myself!
the__alchemist•5mo ago
Update: No, I don't think so. Just tried Let Else... I like it more than the ex I posted.

That said, much like it took me a while to Grok if let syntax... this will be a struggle. See the other example in this thread where the one suggesting it reversed the syntax. That will take a bit to get right...

rav•5mo ago
You can rewrite it using let-or-else to get rid of the unwrap, which some would find to be more idiomatic.

    let value = Some(param.as_ref()) else {
      // Handle, and continue, return an error etc
    }
    // Use `value` as normal.
the__alchemist•5mo ago
That part intrigued me about the article: I hadn't heard of that syntax! Will try.
epidemian•5mo ago
Small nit: the Some() pattern should go on the left side of the assignment:

    let Some(value) = param.as_ref() else {
      // Handle, and continue, return an error etc
    }
    // Use `value` as normal.
vmg12•5mo ago
Also, sometimes just unwrap it. There is some software where it's perfectly fine to panic. If there is no sane default value and there is nothing you can do to recover from the error, just unwrap.

Also, sometimes you just write software where you know the invariant is enforced so a type is never None, you can unwrap there too.

I find it interesting how a lot of people find Rust annoying because idiomatic Rust is a very strict language. You still get a ton of the benefits of Rust when writing non-idiomatic Rust. Just use the Rc<RefCell<>> and Arc<Mutex> and feel free to unwrap everything, nobody will punish you.

0cf8612b2e1e•5mo ago
Plus it gives others the opportunity to post that xkcd velociraptor strip.
iyn•5mo ago
https://xkcd.com/87/ this one?
Hackbraten•5mo ago
Do you mean this one? https://xkcd.com/292/
0cf8612b2e1e•5mo ago
Yes, exactly. It is the Rust equivalent of goto.
vmg12•5mo ago
Goto is bad because it results in very difficult to reason about code. Using unwrap and expect is as bad as using any other language without null safety.
int_19h•5mo ago
goto is bad when it's used in a way that makes it difficult to reason about code, but not all uses of goto are like that. The usual C pattern of `if (err) goto cleanup_resources_and_return_err;` is a good example of the use of goto that is not difficult to reason about.

Using unwrap/expect is still much better than using a language without null safety because unwrap/expect make it immediately obvious at which point a panic can occur, and creates some friction for the dev writing the code that makes them less likely to use it literally everywhere.

p1necone•5mo ago
Imo always expect rather than unwrap in those cases. If it's justifiable, you should justify it in the message.

("This should never happen because: ..., if you see this message there's a bug.")

Arnavion•5mo ago
Or let-else with a panic!() in the else {} if you want to use a format string.
xigoi•5mo ago
If you’re doing something like Project Euler, writing error messages is a waste of time.
tengbretson•5mo ago
I'm not very familiar with Rust. Do the built in Option and Result types not implement map and flatMap?
trealira•5mo ago
They do implement both of those, except instead of flat_map, it's called and_then for Option and Result.
theon144•5mo ago
They do, `map` and `and_then`.

As for the article, I'm also a bit confused because I'm really not sure whether people write that sort of code at the beginning "very commonly" - match and `ok_or` to handle None by turning them into proper Errors is one of the first things you learn in Rust.

Sharlin•5mo ago
As others have said, you can `and_then` chain `Options`, but often it’s better to convert each `Option` into a `Result`s before chaining, to get more fine-grained error messages as shown in the fine article. But usually it’s cleaner and more convenient (and friendlier to people used to exceptions) to use the `?` operator which is basically Rust’s `do` notation except that currently you can only early-return from the entire function with it, not escape a specific block. Which in turn requires the types to match, though Rust does at least insert an `.into()` conversion for the error value.
rienbdj•5mo ago
How long till the Rust community starts to push do notation and monad transformers?
keybored•5mo ago
Eight years ago?
Sharlin•5mo ago
> I find the name ok_or unintuitive and needed to look it up many times. That’s because Ok is commonly associated with the Result type, not Option.

Hmm, I kind of disagree. The method literally returns “OK or an error”. It converts an Option into a Result and the name reflects that.

There is something of an inconsistency though, although IMHO it’s worth it. The `Result::ok()` method returns a Some if it’s Ok, and None otherwise, which is concise and intuitive but indeed different from `Option::ok_or`.

tekacs•5mo ago
I use a setup like this:

https://gist.github.com/tekacs/60b10000d314f9923d6b6a5af8c35...

where... in my code, I have:

  some_block({ ... }).infallible()
for cases where we believe that the Result truly should never fail (for example a transaction block that passes through the inner Result value and there is no Result value in the block) and if it does then we've drastically misunderstood things.

Then, there's an enum (at the bottom of the file) of different reasons that we believe that this should never fail, like:

  // e.g. we're in a service that writes to disk... and we can't write to disk
  some_operation.invariant(Reason::ExternalIssue)
  // we're not broken, the system wasn't set up correctly, e.g. a missing env var
  some_operation.invariant(Reason::DevOps)
  // this lock was poisoned... there's nothing useful that we can do _here_
  some_operation.invariant(Reason::Lock)
  // something in this function already checked this
  some_operation.invariant(Reason::ControlFlow)
  // u64 overflow of something that we increment once a second... which millennium are we in?
  some_operation.invariant(Reason::SuperRare)
... etc. (there are more Reason values in the gist)

This is all made available on both Result and Option.

mcflubbins•5mo ago
I with there was a clippy check for unwrap(), I have very very rarely needed it in practice.
ChadNauseam•5mo ago
You can add this to your clippy.toml

    [lints.clippy]
    unwrap_used = "warn"
mcflubbins•5mo ago
Nice! Thanks