Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I think you've skipped over all the cases where knowing the filename is actually helpful? It's true that sometimes it isn't.

Also, a line number is often helpful, which is why compilers include it. Some JSON parsers omit that, which is annoying.



> Also, a line number is often helpful

That's not error data, that's (one level of) a stack trace. And you can do that in zig, but not by putting call stack data into error return codes.

The conflation between exception handling and error flagging (something that C++ did largely as a mistake, and that has been embraced by managed runtimes like Python or Java) is actually precisely what this feature is designed to untangle. Exception support actually turns out to have very non-trivial impact on the generated code, and there's a reason why languages like Rust and Zig don't include them.


> That's not error data, that's (one level of) a stack trace.

They're not talking about the stack trace, but about the common case where the error is not helpful without additional information, for example a JSON parsing library that wants to report the position (line number) in the string where the error appears.

There's no way of doing that in Zig, the best you can do is return a "ParseError" and build you own, non-standard diagnostic facilities to report detailed information though output arguments.


Another way to look at this example is that, for the parser, this is not an error. The parser is doing its job correctly, providing an accurate interpretation of its input, and for the parser, this is qualitatively different from something that prevents it doing its job (say, running out of memory).


At the next level up, though, there might be code that expects to be able to read a JSON config file at a certain location, and if it fails, it’s reasonable to report which file it tried to read, the line number, and what the error was.


Sure, but that's a different level with different considerations. The JSON parser shouldn't care about things like ‘files’ with ‘locations’; maybe it's running on some little esp8266 device that doesn't have such things.




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

Search: