Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which one are we doing?
For (2) I could see it being a call to
std.debug.printorstd.log. But it looks like what you're trying to do is move this closer to (1), in which case this would be the way to do it:I think that's not actually helpful though, because it would lead to people using this pattern instead of
std.debug.printorstd.log.I think status quo is actually better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was doing
3. Hello world as defined to be the most correct (in terms of code style) program that prints a string to stdout.
The reasoning for this is, clearly what we're doing here is printing a message, no matter what mechanism we use; therefore what we do here will be taken as the correct way to print a message in Zig. We need to set a good example.
Here's why I say that status quo is not a good example:
We're not playing code golf here; we're demonstrating, maybe for one of the first times to some people, an example of how to write Zig. We can be a bit more verbose for the sake of clarity, and I say we should.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most correct hello world is using
writeAll, as suggested above. Your (3) is my (1). We are talking about the same thing.zig init-exeis not intended to be "hello world" - it is intended to be a template to get you going. That's why it also includes unit tests. I think teaching people how to use std.log is more appropriate than teaching how to write to stdout, which is actually a rare use case.I think it should be improved even further and set someone up a GeneralPurposeAllocator as well as an arena with the lifetime of the process, with comments explaining when someone might use one or the other.
Also argument parsing, and maybe even a buffered writer to write something to a file. Basically a "getting started" kit.
This PR is not the direction I see this going.