#Learning Zig by making a toy Base64 encoder

1 messages · Page 1 of 1 (latest)

summer violet
languid wyvern
#

This looks good. I also only started to learn zig, so you're repository is very interesting. Although, i think switch is overused, i mean, switch on true/false is just regular old if.

Also, does zig support any kind of buffered reading? If yes, you can process files of arbitrary length, since you can just read from the stream.

quasi carbon
#

Also, does zig support any kind of buffered reading?
It absolutely does:

var buffered_in = std.io.bufferedReader(std.io.getStdIn().reader());

Then use buffered_in.reader()

summer violet
# languid wyvern This looks good. I also only started to learn zig, so you're repository is very ...

It's funny you'd say that. I rarely use switch statements in other languages, but I really like the way Zig utilizes it, so I've been intentionally trying to use it more often. I didn't realize how much it showed up in the code.

The true/false one was specially because of switch acting as an expression. So output = switch..., I could have done a standard if, or an if/then ternary expression I guess. The switch just seemed right lol.

Good point about buffering. If I make more improvements to this I'll definitely add that. I'm actually considering expanding it to include other encoding/decoding algorithms. I'm interested to write a few myself.