今日精选
HOTEngland set to be one of the first countries to eliminate hepatitis C
France to ban unsolicited telemarketing calls
Illinois Just Passed a Law That Puts Linux on the Hook for Age Verification
Study links GLP-1 drugs to bigger jump in women's employment than a degree
Magnitude 7.4 Earthquake – 5 km S of San José del Palmar, Colombia
最新资讯
共 30515 篇Wooting 60HE v2: Peak Keyboard Perfection
Wooting’s 60HE v2 isn’t just a terrific Hall Effect keyboard. It’s a fantastic keyboard period.
Sony’s Xperia 1 VIII is still a phone for the fans
The Xperia 1 VIII marks an attempt at a step change for Sony's flagship phone line. Not only has it had an aesthetic overhaul, but Sony has also revamped the camera system, dropping the continuous optical zoom telephoto that's defined the last four generations of Xperia phone. It's not all different. Sony staples like a […]
The Best NAS Devices for Your Home After Months of Testing
Network-attached storage (NAS) provides accessible shared space on your home network. After testing, these are my favorite NAS devices.
28 Tips to Take Your ChatGPT Prompts to the Next Level
Sure, anyone can use OpenAI’s chatbot. But with smart engineering, you can get way more interesting results.
If You’re Searching for a New Skillet, Consider Stainless Steel
Stainless-steel pans may lack nonstick coatings, but they’re unfussy, they sear well, and they’re built for a lifetime of hard work.
How Apps Know What You Want Next?
Hello, I'm Maneshwar. I'm building git-lrc, a Micro AI code reviewer that runs on every commit. It is...
Review: Widow's Bay is a boldly original take on comedic horror
An eminently binge-able series that honors classic horror tropes while reinventing them in surprising ways
Buying a Used iPhone Makes More Sense Than Ever
With Apple raising prices soon, you can save a lot of money by buying a used handset or upgrading an older device—safe in the knowledge that it'll last longer than ever.
Error Handling — Learning to Love `if err != nil`
Error Handling — Learning to Love if err != nil In part 3 I covered goroutines and channels, and how Go's concurrency model sidesteps a lot of the ceremony I was used to from the JVM. This time I'm tackling the thing I complained about in part 1 of this series before I'd even really tried it: error handling. I called if err != nil repetitive back then. A few weeks and a lot of real code later, I owe Go a partial apology. No Exceptions, On Purpose Coming from Java, the absence of try / catch is the first thing that feels like a missing feature. It isn't — it's a deliberate design choice. In Go, errors are just values. A function that can fail returns an error as its last return value, and the caller decides what to do with it, right there, inline: func divide ( a , b float64 ) ( float64 , error ) { if b == 0 { return 0 , errors . New ( "division by zero" ) } return a / b , nil } func main () { result , err := divide ( 10 , 0 ) if err != nil { fmt . Println ( "error:" , err ) return } fmt . Println ( "result:" , result ) } That's the pattern you'll write hundreds of times in Go: call a function, check err , handle it or bail out, move on. No hidden control flow jumping up the call stack to whichever catch block happens to match. No checked-exception signatures cluttering method declarations. No RuntimeException quietly skipping past five layers of code that had no idea it could happen. Whatever can fail is sitting right there in the function signature, and you're forced to look at it. Why the Repetition Is the Point My part 1 complaint was that if err != nil everywhere feels manual. It is manual — and that's exactly the trade Go is making. In Java, an exception thrown deep in a call stack can silently propagate through layers of code that never declared they might fail, and you only find out where things actually break by reading a stack trace after the fact. In Go, every single point where something can go wrong is visible in the source, in order, as you read top to