Live data from Hacker News

Zig by Example

github.com

61–70 of 109 posts

Re: Zig by Example

#61

Earlier quoted context omitted.

I see it this way, the full signature for defining a variable is: var foo: Foo = Foo{}; There's two ways to shorten it: var foo = Foo{}; var foo: Foo = .{}; It can infer the type of the var from the right hand side; or the type of the right side from the type of the var. So when you see .{} as an argument, it is inferring the type from the function signature. It happens to be empty only because it's using default val…

that's not quite right. 1) It's var foo = Foo{...}; (no intervening dot) 2) I think parent commenter is referring to function call use case call_my_func(.{...})

1) Ah yes, just typing from memory. Point still stands.

2) Adressed in the last paragraph.

Re: Zig by Example

#62
post #21

Is Zig just a trend, or will it become a solidly established language? After all, learning something is an investment of time. With Zig, it doesn't seem to have the same kind of industry pressure as Rust. There's talk in open source circles about AI-related issues, and on Hacker News people say good things about Zig. The allocator concept looks great. But there's also a possibility that it won't become mainstream, li…

Lindy effect is very strong in the programming languages world. Zig is a very interesting and well built language, but it is also niche, unstable and not offering radical improvements over C. C, as the foundation of all modern kernels and system tools, among many other things, is extremely unlikely to go away soon. Everything you do in Zig can be done almost in the same way in C or C++. I would say the real value of…

> Everything you do in Zig can be done almost in the same way in C or C++.

Can you do this in C?

https://github.com/ityonemo/clr

Re: Zig by Example

#63
post #21

Is Zig just a trend, or will it become a solidly established language? After all, learning something is an investment of time. With Zig, it doesn't seem to have the same kind of industry pressure as Rust. There's talk in open source circles about AI-related issues, and on Hacker News people say good things about Zig. The allocator concept looks great. But there's also a possibility that it won't become mainstream, li…

Rust didn't have nearly the industry adoption it does now back in 2020, but it was gaining traction in various parts of the community. If you learned it back then it was either because you love it, or you thought it had staying power.

I think Zig does, specifically because of its build system and it's C interopt story. Plus Zig has the added advantage that learning it teaches you about how the computer works, how memory gets laid out, etc. So even if it never gets wide adoption the skills are highly transferable.

Re: Zig by Example

#64

Earlier quoted context omitted.

that's not quite right. 1) It's var foo = Foo{...}; (no intervening dot) 2) I think parent commenter is referring to function call use case call_my_func(.{...})

1) Ah yes, just typing from memory. Point still stands. 2) Adressed in the last paragraph.

Point being, these two things aren't different (variable assignment and function calls); IIUC they go through the same analysis pathway, result location semantics.

https://ziglang.org/documentation/master/#Result-Location-Se...

It's a little bit weird, since the types flow in the reverse direction than you would expect.

Re: Zig by Example

#65

Earlier quoted context omitted.

Lindy effect is very strong in the programming languages world. Zig is a very interesting and well built language, but it is also niche, unstable and not offering radical improvements over C. C, as the foundation of all modern kernels and system tools, among many other things, is extremely unlikely to go away soon. Everything you do in Zig can be done almost in the same way in C or C++. I would say the real value of…

> Everything you do in Zig can be done almost in the same way in C or C++. Can you do this in C? https://github.com/ityonemo/clr

Linters are not exactly a new idea, and they can be pushed quite far.

I am generally against the idea of language support for meta-programming, even using C macros or C++ templates.

I do a lot of meta-programming/codegen with external tooling.

Re: Zig by Example

#66
post #21

Is Zig just a trend, or will it become a solidly established language? After all, learning something is an investment of time. With Zig, it doesn't seem to have the same kind of industry pressure as Rust. There's talk in open source circles about AI-related issues, and on Hacker News people say good things about Zig. The allocator concept looks great. But there's also a possibility that it won't become mainstream, li…

Here is where I think Zig shines. When you are a high level programmer that needs to drop down to a low level programming language for performance reasons. The issue with doing that as a high level programmer is that you don't do a lot of low level work frequently.

So unless you work in another domain where you do a lot of low level programming, then every time you drop down you will be out of practice. This favors using a simpler low level language, with low friction for integration. Rust and C++ don't handle being used infrequently, but C with it's simpler standard library and syntax fits this nicely. But it doesn't have things you expect for a modern programming language, and it is also has a lot of dangerous footguns that are easy to forget if you are out of practice

In comes Zig. It's low level, comes with it's own toolchain that makes it pleasant to work with, easy to cross compile, has more safety features built in that C, but is not overly complicated. The code tends to be more verbose, but also more straightforward. So it's a perfect language to pair, when you know you won't be able to do everything in a high level language.

For me that's what seals the deal. I'd argue that Odin has a nicer syntax, but there is a reason that tools like cargo-zigbuild^1 exists. The fact projects not related to Zig are willing to ship Zig toolchains to make lives easier is a testament to how seriously Zig takes this.

1. https://crates.io/crates/cargo-zigbuild

Re: Zig by Example

#67
post #50

This is outdated and AI generated. If you want a good source of zig learning material interactive and by examples please check out ziglings: https://codeberg.org/ziglings It's writen and tested by humans, which is essential for learning purposes. It's listed in the official zig website, by the way. This project is always up to date to the latest zig release.

well, it also made by the same guy behind the boring go book which probably means that boring go is also most likely AI generated

nowadays before reading or buying any book, we need to extensively investigate the author, the author name is now more important than ever, i think whenever a book is shared, the author need to me highlighted

Re: Zig by Example

#68

Earlier quoted context omitted.

> Everything you do in Zig can be done almost in the same way in C or C++. Can you do this in C? https://github.com/ityonemo/clr

Linters are not exactly a new idea, and they can be pushed quite far. I am generally against the idea of language support for meta-programming, even using C macros or C++ templates. I do a lot of meta-programming/codegen with external tooling.

> Linters are not exactly a new idea, and they can be pushed quite far.

That's not an answer. There's a reason why you can't do it in C, and the reason is "the stdlib is poorly designed". No amount of linting can get you around that.

Re: Zig by Example

#69
Do not use this, I recommend ziglings if anything besides what Loris would say: you have to read code.

The builtins don’t even compile in these examples. This is 2 years out of date at least.

Post reply on HN