4 ms·
> but the larger purpose of the code is obscured in all the "if err != nil" weeds. That's the difference between script and system programming. When writing sc
by randomdata 3y ago
> but the larger purpose of the code is obscured in all the "if err != nil" weeds.
That's the difference between script and system programming. When writing scripts, one is only concerned about carrying out a certain task and if anything goes wrong the whole thing can bail. Systems are more robust. When things go wrong they cannot just fail. They need to recover gracefully and do something meaningful in the failed state.
Handing failure conditions is the primary purpose of system code. Irrespective of Go, there is something to be said about some kind of identifier that says "take note: this is the most important code in the application!" If that comes across as being 'weedy', you know that you really needed a scripting language, not a systems language.
Different tools for different jobs.
- gaganyaan 3y agoGo still picked a terrible option. The `?` operator in Rust is way better, proving that systems languages don't have to suffer Go's choice.
- randomdata 3y agoThat is quite different. ? in Rust signifies "this code is not important" Which even in systems is unavoidable, to be fair. Sometimes failure just isn't important. The division between systems and scripts is not perfect. But, that will be the uncommon case in systems. It is not certain that really needs a symbol in which to draw attention. (An implementation may need a symbol, but that's beyond this discussion)
- gaganyaan 3y agoI'm not sure why you think it's unimportant. You seem to be confusing its purpose, and making distinction between systems and scripts that doesn't apply here. Rust's whole error handling, including the ? operator work great for embedded systems where Go isn't enough of a systems language to even run. EDIT: I think you're confused. The ? operator says "I'm not handling this specially here". That doesn't mean the error is just propagated to the top like an uncaught exception in a Python script. It allows you any level of granular handling you'd like.
- deleted 3y ago[deleted]
- sgarland 3y agoPython has excellent exception handling, and its corollary to if err != nil would be try/except blocks everywhere. That said, I hate Go for unrelated reasons, and love Python.
- randomdata 3y agoGo's exception handling (panic/recover) is very much like most other languages with exception handling, including Python. It is there to use when you have exceptions. But we're talking about expected failure (network failure, hardware failure, etc.), not exceptional cases (programmer error). You would not want to carry 'expecteds' on exception handlers. Different tools for different jobs. That said, systems transcend Go. The discussion isn't about Go, or Python, specifically.
- guappa 3y agoWrite an exception handler so you handle the errors. Plenty of go code doesn't handle errors, just pretends to but doesn't do anything meaningful when they happen.