Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
A Sneaky Golang Bug (dustri.org)
2 points by pabs3 on Aug 5, 2023 | hide | past | favorite | 2 comments


In C++ there’s an attribute called nodiscard which solves this problem assuming the API you’re consuming is written well. When you apply this attribute to a function, the compiler emits a warning when that function’s return value isn’t used by the developer [1].

Lots of other languages take the same approach. Rust’s must_use attribute is basically the same as nodiscard.

It’s a nice way of solving the problem imo.

[1] https://en.cppreference.com/w/cpp/language/attributes/nodisc...


A unit test would have caught this.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: