Y
Hacker News
new
|
ask
|
show
|
jobs
by
sayrer
205 days ago
Yes, can't have .unwrap() in production code (it's ok in tests)
2 comments
orphea
205 days ago
Like goto, unwrap is just a tool that has its use cases. No need to make a boogeyman out of it.
link
gishh
205 days ago
To be fair, if you’re not “this tall” you really shouldn’t consider using goto in a c program. Most people aren’t that tall.
link
tucnak
205 days ago
Nonsense. Linux kernel for one example, uses goto everywhere for error handling.
link
gishh
201 days ago
How many codebases besides the Linux kernel had you seen an intentional amount of use of goto?
link
orphea
199 days ago
The answer is one search away on GitHub.
I will give you one example though: various .NET repositories (runtime, aspnetcore, orleans).
link
metaltyphoon
205 days ago
Yes it's meant to be used in test code. If you're sure it can't fail do then use .expect() that way it shows you made a choice and it wasn't just a dev oversight.
link
fwjafwasd
205 days ago
panicans should be using .expect() in production
link
keyle
205 days ago
unwrap itself isn't the problem...
link