Hacker News new | ask | show | jobs
by AndyKelley 3368 days ago
I wouldn't advocate for the curl project to experiment with rewriting some code in [Zig](http://ziglang.org/) yet, due to lack of maturity, but it is exactly in the target niche of the project. That is, near-seamless integration with a large pre-existing C codebase.

So you could, for example, take a 400 line C file, convert it to Zig, and have it import the .h files that the previous C file was including, and export an .h file for the rest of the codebase to look at. The compiler can turn this Zig file a .o file that integrates with the rest of the build. The part of the codebase written in Zig could benefit from the safety features, generics, and error handling features of the language while presenting the same interface to the rest of the codebase.

Now of course, if you already have a codebase written in 1 language, it's more complicated to introduce another. This is where the Zig build system comes into play. I'm working on this now, and it's a competitor to autotools, scons, cmake, make, and all those players. It's the Zig programming language with a declarative build system API built into the standard library with some basic tooling around it, and it ships with the compiler.

So if the Zig build system gets to the point where it is high quality enough to attract users and ubiquity in package managers, then a project which already uses Zig for its build system can start using it for its actual code without the penalty of adding a dependency.

In conclusion, once Zig has reached a stable enough state, I would challenge the libcurl devs to consider, perhaps it could make sense to slowly, carefully, methodically transition to a newer language, if that language was friendly enough to the process.

2 comments

I don't know anything about Zig, but I believe that a good reason for cURL to be written in ANSI C is that even your toaster ships with a C compiler able to build the source code.
If that is in fact the reason for sticking with ANSI C then I would like to advocate for a language that compiles to C. In which case I would like to suggest Nim[1].

Of course, I don't think that curl should be rewritten in Nim. But since we are advocating for other languages I thought I would pitch in. If anything, writing new curl functionality in Nim would be the way to go. That is assuming that curl's author is unhappy with C, which does not seem to be the case.

1: https://nim-lang.org

If you depend on Zig then you only depend on Zig to produce a binary or library for any system.

If you depend on Nim then you depend on Nim, a C compiler, and a linker. And I hope your C compiler supports cross compiling out of the box. It probably doesn't.

> you depend on Nim, a C compiler, and a linker

It's a small number of build dependencies.

> I hope your C compiler supports cross compiling out of the box.

It does.

Does the LLVM not count as a dependency?
What does Zig have to offer over Rust's FFI[1]?

Also, it might be useful to know that HN's comment syntax isn't Markdown, though it shares a few features like indenting for code blocks and asterisks for italics. Markdown-style links are not supported.

[1] https://doc.rust-lang.org/book/ffi.html

Of course, not only are markdown style links unsupported, nothing but raw urls are supported as links. For whatever reason, the majority of people here choose to relate links to locations in text using a particular footnote style. Since this format is no more blessed than the common markdown style, they could have easily chosen that instead. Presumably, they didn't because it breaks flow when using long links. For short links, like the one in the GP, inline links work just as well as footnote based ones, and provide the extra benefit of not requiring scrolling to follow them.
If there's no need to tell a parser where the link text begins and ends, then putting the URL in parentheses after the relevant text (without square brackets) would be less fussy.

The "HN style" of citation/linking is basically the IEEE citation style. You could call it "blessed".

http://www.ijssst.info/info/IEEE-Citation-StyleGuide.pdf

https://www.ieee.org/documents/ieeecitationref.pdf

As an addendum, using a Rust library in C is quite easy: https://doc.rust-lang.org/1.2.0/book/rust-inside-other-langu...