Live data from Hacker News

How I Built Zig-SQLite

rischmann.fr

61–70 of 104 posts

Re: How I Built Zig-SQLite

#61

Earlier quoted context omitted.

Does a really short summary of this read kind of like, "zig is a modern c, but I like using rust as a modern c++"? Agree, Tokio is a little tricky for people new to rust no doubt, but it's tricky for a reason. It's saving lives in production.

Yes, but Rust offers something more than just modernizing C++. The borrow checker provides something entirely new that has the potential to make a huge impact.

Just semantics, but I think the borrow checker is part of modernizing C++.

(The way to manage memory in C++ and C is to opt in to a memory management pattern... hopefully you've chosen a good pattern and hopefully you follow it consistently. Patterns are generally backed by utilities and primitives that are hopefully correct, complete, and hopefully make it relatively easy to follow the pattern consistently. Hopefully you can get a linter to help you too. In a sense Rust takes the same approach, but was implemented from the ground up to eliminate all the gaps so you essentially don't have to hope to successfully bridge the gaps yourself.)

Re: How I Built Zig-SQLite

#62

Earlier quoted context omitted.

As someone who uses both for different personal projects: - I use zig as my build system for both rust, zig, C libraries and linking since the build system works really well for this purpose - When I need to write applications or libraries that can benefit from compile-time code, I always try and use zigs since it's much easier to use comptime then a combination of rust macros and generics - I like the zig async stor…

Does a really short summary of this read kind of like, "zig is a modern c, but I like using rust as a modern c++"? Agree, Tokio is a little tricky for people new to rust no doubt, but it's tricky for a reason. It's saving lives in production.

Can you elaborate on the savings lives part? I sense a good story, would love to hear.

Re: How I Built Zig-SQLite

#63

Earlier quoted context omitted.

All of this is already done in Lisp. Greenspun's 10th rule.

...is there any lisp that can be used for systems programming and that does NOT produce huge binaries, does not use GC, generates fast n small binaries and is still interactive? everyone claims lisp can be used for anything, same goes for forths, but i cant see a lisp like that, and about forths...none of the free ones are fast, and the fast ones are still slow on the same note, lets say if someone is creating someth…

I mean there was a "lisp machine" in the distant past that actually ran lisp on metal. Does that count?

Re: How I Built Zig-SQLite

#64
post #58

Cool article. I can't figure out why i am supposed to care about zig beyond it's fun? I get that it's interesting and more safe than C (honestly though what the hell isn 't). Say you write rust pretty regularly for new product development, what does zig offer to make my life better, my products more stable, etc?

If zig catches on then the question may change from "why zig" to "do I really need rust?". Rust has a higher entry barrier and is harder to use daily. Is the safety guarantee worth it? In my experience, it is easier to fix a bug than to prove to the rust compiler that there is no bug. I just need a language that finds and reports the bugs (before production). Zig's error handling is interesting in this regard and it…

I think a static borrow checker tool is very likely going to be in the future of zig ecosystem (unlikely to be in the mainline, but that's okay), especially after the intermediate representations stabilize.

Re: How I Built Zig-SQLite

#65
post #45

Cool article. I can't figure out why i am supposed to care about zig beyond it's fun? I get that it's interesting and more safe than C (honestly though what the hell isn 't). Say you write rust pretty regularly for new product development, what does zig offer to make my life better, my products more stable, etc?

I write Rust for $day_job and Zig for fun. Rust is great, but if I had to rip on a few places where it's lacking for some applications: Zig maintains a small language footprint, is easier to interop with C, and makes it readily apparent when your code is doing anything non-trivial. To make that concrete: - The small footprint in Zig enables fast compilation (and getting faster) and fast feedback cycles. - Arbitrary n…

Rust probably had a fairly small "language footprint" when it was only a few years old with no production use cases as well. I've used both in some small hobby projects. I like writing zig significantly more than rust, but we'll see how long the language remains small and compact.

Re: How I Built Zig-SQLite

#66
post #19

By using comptime, the statement couldn't be runtime composed, right? That's currently the major holdback for me to spend more time on zig: if using comptime become more common in zig community, the libs could be less flexible to use. It feels sort of like function coloring to me, that the whole call chain also need to pass down the value as comptime variable. I've only spend 2 days with zig, so I would love to learn…

Generally I wouldn't call zig comptime function coloring. (I have written a prime sieve algorithm that uses the runtime code to precalculate some primes at comptime. Yes, I had to be very careful about what was in the prime number algorithm, but comptime supports that level of complexity and it was certainly possible to call runtime-intended code at comptime.

Can you call comptime-intended code at runtime? No? (Yes? B/c the call site is "in" the runtime code?) But just make it runtime code instead of comptime code?

Re: How I Built Zig-SQLite

#67
post #57

In case anyone else is unfamiliar with Zig syntax and wondering: in Zig the .{ "somevalue"} represents an anonymous list literal [1], and .{.somename = "somevalue"} is an anonymous struct literal [2]. (A bit off topic rant, but Zig documentation is quite bad, it took me a lot more effort that it should to discover the facts above.) [1] https://ziglang.org/documentation/master/#Anonymous-List-Lit... [2] https://ziglan…

I thought the docs were quite good. I used "ziglearn" to understand ("chapter 1" and "chapter 2" have tons of foundational stuff): https://ziglearn.org/chapter-1/ I used the language reference for the details: https://ziglang.org/documentation/master/#Introduction I agree the standard library docs aren't useful (unless something changed a lot in the last six months)... it seemed always better to just search and read…

> I agree the standard library docs aren't useful (unless something changed a lot in the last six months)... it seemed always better to just search and read the standard library source directly.

They're automatically generated. As I understand it they've been holding off on improving them until they have the self hosted compiler working, as it will be easier at that point.

Re: How I Built Zig-SQLite

#68
post #57

In case anyone else is unfamiliar with Zig syntax and wondering: in Zig the .{ "somevalue"} represents an anonymous list literal [1], and .{.somename = "somevalue"} is an anonymous struct literal [2]. (A bit off topic rant, but Zig documentation is quite bad, it took me a lot more effort that it should to discover the facts above.) [1] https://ziglang.org/documentation/master/#Anonymous-List-Lit... [2] https://ziglan…

I thought the docs were quite good. I used "ziglearn" to understand ("chapter 1" and "chapter 2" have tons of foundational stuff): https://ziglearn.org/chapter-1/ I used the language reference for the details: https://ziglang.org/documentation/master/#Introduction I agree the standard library docs aren't useful (unless something changed a lot in the last six months)... it seemed always better to just search and read…

To be fair it's really hard to "search" for tuples and anyonymous structs and get an understanding from "reading the stdlib". It's also enough of a departure from C (but not obviously readable like types on the left) to warrant some sort of big red flag in the lang docs... Understanding this tripped me up a bit

Re: How I Built Zig-SQLite

#69
post #56

Earlier quoted context omitted.

You lose at "reimplementation of SQLite".

Possibly, but then again, if one's aim is to replace C with Zig in the future perhaps completely, because SQLite became de-facto standard file format for many applications (see OGC GeoPackage for example), you might need some implementation of SQLite for that. If a file format is going to stick for decades, you'll definitely get other implementations of that file format sooner or later in environments that can't or d…

What environment cannot run C?

Re: How I Built Zig-SQLite

#70
post #58

Cool article. I can't figure out why i am supposed to care about zig beyond it's fun? I get that it's interesting and more safe than C (honestly though what the hell isn 't). Say you write rust pretty regularly for new product development, what does zig offer to make my life better, my products more stable, etc?

If zig catches on then the question may change from "why zig" to "do I really need rust?". Rust has a higher entry barrier and is harder to use daily. Is the safety guarantee worth it? In my experience, it is easier to fix a bug than to prove to the rust compiler that there is no bug. I just need a language that finds and reports the bugs (before production). Zig's error handling is interesting in this regard and it…

It's really not that hard to use once you invest some time into it. I know where you are coming from, but appeasing the compiler actually means "I am writing safe code". Rather then "it compiled let's see what happens in production"
Post reply on HN