Reading is not as bad as I thought it'd be

While I wait for project idea for Zig, I've been reading the Zig language spec from top to bottom. More like continuing on from where I left of. There are few things thats really cool about the documentation.

It's quite concise without being too hard to follow. I like that there are code snippets for every concept you read, right where you read them. Which makes the understanding a lot easier. As you can see how to use something,right as you read about it.

There are a few cool things I read about today and I think I'm liking the language even more than I did before.

Error handling

At first I was not too sure of the Zig error handling, at first I thought it was unnecessary. Not only have my opinion on it turned, after reading a few more things about errors today, I think they are actually quite fantastic. Why? Mainly as I was reading the examples I realized it's very easy to code the happy path of your program without completely neglecting the errors. You still have to handle the errors but you could defer it to when you are ready to use your methods.

I also read about errdefer today, at first I thought it was unnecessary but after a few examples I do think it might have it's use cases.

I'm starting to like the syntax

Initially I was not a big fan of the try and catch style of error handling for example. Not to be mistaken for exceptions. The error handling is still really good. But I wondered if these were necessary. After reading through a few examples, I realized that you can capture both errors and successes between the pillars | |. This means after you have finished writing the programming logic you can capture the err and then work on that. Something like this:

if (thisMightError()) |success| {
  // handle success
} else |err| {
  // handle failure
}

This is a simplistic example but, the code is easy to read and write. You can even use a switch if you want to handle the errors. Which is also neat.

Finally

Overall I'm glad I decided to continue reading the spec. At first I wasn't sure, it felt like I wasn't really learning anything. I still have to write code for these to stick, but knowing that they exist is a crucial part. I enjoyed reading the errors section today quite a lot. I think I will continue the reading for a few more days.