www.ziglang.org
www.ziglang.org copied to clipboard
Add hello world to samples page
What
Add a hello world example to the samples page.
Why
The learn samples showcase some advanced features and concerns like memory leaks, but as a someone who is new to Zig the first thing I need to see is hello world. i.e. The minimal application that runs and gives me some sense of where the entry point is and how to log so I can debug using some basic principles.
I think it would be helpful to new folks to add a hello world example to the samples page.
Close https://github.com/ziglang/www.ziglang.org/issues/117
For the other language pages, is it best to leave this off those pages until someone translates it? Or should I add it to the other pages without text? How does the translation process work with this repo?
Previously, the index page displayed a "Hello World". Personally, I like the current example better. And for a 'Hello World', we might consider whether the debug version or a release version would be more appropriate:
const std = @import("std");
const stdout = std.io.getStdOut();
pub fn main() !void {
try stdout.writeAll("Hello, World!\n");
}
I see that you renamed all sample files to keep the order, if maintainers are ok with it I would remove that prefix since these files are not order-sensitive,. Having to keep the order of the filesin sync with the order in the page feels like an unnecessary complication.
I see that you renamed all sample files to keep the order, if maintainers are ok with it I would remove that prefix since these files are not order-sensitive,. Having to keep the order of the filesin sync with the order in the page feels like an unnecessary complication.
+1. Initially I just added hello world as number 6 and put it at the beginning so they were out of order, but I wasn't sure if the numbering was important. I'll remove the numbers, sounds good to me.
I've updated the example to use stdout, but chose to use print, since it allows printing values in the text.
You could do that, but why if you don't have a variable to print?
try stdout.print("Hello World!\n", .{});
I think using the print fn is more similar to the hello world programs I see in other languages, which also means increased familiarity for folks coming from other ecosystems. Often a function is used that supports plain text and substitution variables like the zig print function.
For e.g. in Go hello worlds you'll often see fmt.Println(...) be used which supports variables, even though you'll often see no variables in those examples. It's rare to see folks use os.Stdout.Write(...).
For e.g. in Rust hello worlds you'll often see println!(...) be used which supports variables. It's rare to see folks use std::io::stdout().write_all(...).
I completely understand what you mean. While the old "Hello World" example is well-known, it often results in new visitors just taking a quick look and thinking, 'Wow, that looks complicated,' without really grasping the philosophy behind it. However, it’s crucial to understand Zig’s philosophy in order to appreciate the example fully — especially when it comes to the print case, where it’s essential to include even empty parameters. That's why I personally find the current example much better. It really showcases Zig's elegance and encourages curious visitors to explore a bit deeper.
That's why I personally find the current example much better. It really showcases Zig's elegance and encourages curious visitors to explore a bit deeper.
👍🏻. If folks are happy with the current example, can we merge this PR, or anything that should be tweaked, etc?
👋🏻