Hacker News new | past | comments | ask | show | jobs | submit login

why should I use Zig coming from Python/Go ?



Zig is much lower level than Python or Go. This means that you can write programs that use very little memory and run really fast. If minimizing memory use and maximizing speed are your primary objectives, Zig could be a better fit than Go or Python.

If you're coming from Python and Go, then producing the fastest possible program that uses the least amount of memory probably isn't your top objective. Zig is fast, but you're going to have to think about memory management and other things you take for granted in garbage collected language. Zig also has nowhere near the number of libraries that exist in Python or Go, so you'll be building a lot more stuff yourself.

Also, the simplicity of a language like Zig may be a hindrance if you're working with really big code bases. If you need something that will scale to really large projects, like say a web browser, you're probably better off in Rust.

If performance is not an issue and you want something that will let you focus on the program's logic rather than the implementation, Python is probably what you want.

If you're writing a microservice to run in a datacenter, you'll be up and running in Go much more quickly and the performance is probably good enough.

But if you're writing a program for an embedded or limited environment, or you need something that's simple and fast, then Zig is worth a look. And of course, Zig is worth a look because it's very simple and easy to learn so you can be up and running very quickly.


Realistically, you probably shouldn't. Zig seems to be positioning itself as a systems-level language—more of an alternative to C/C++/Rust than to Python/Go. If you're building low-level, high-performance software, it might be interesting to you; otherwise, I don't see a practical benefit.


> Python/Go

I wouldn't put those two languages in the same class. Go has about the performance of Java/C# with about the memory usage of C++. It's much closer in performance and resource efficiency to those languages than it is from a scripting language like Python.


They both emphasize productivity over other factors like performance and correctness, so I think they're very much in the same boat in terms of use cases.


Go was created for correctness. It is strongly, statically typed, it won't compile if there are unused imports or variables, and it won't compile either if you don't free up resources after usage. C/C++ don't do that and have UBs.

Go is in the same ballpark than C#: a modernized C with GC, good productivity although not as good as a scripting language, and good performance although not as good as ANSI C. They're popular because they stand in that sweet spot.

Python is easier than Go or C# to pick up, but it's also 20x slower than C rather than 2-3x.


Correctness may have been a goal of the Go language authors but they don't seem to have achieved it.

I could find countless other comments about this on HN, but here's the top hit in a quick search. https://news.ycombinator.com/item?id=26632821


Thanks, this is the take I was looking for. It would be great if Unreal Engine could be ported to Zig and then I would be happy to get into it again.


I think that a Zig API for Unreal is very likely to appear at some point.


As I understand it, Zig is not targeted at GC language users. Their main focus is C, C++ and Rust(?) users.


You could use it to build python extensions.

https://pypi.org/project/setuptools-zig/


Another use case aside from the typical "high perf" ones: if you're building a cross-platform library with bindings in various language (eg. Swift bindings, Kotlin, C#, etc.), I'd imagine you'd benefit in the long run from having manual memory management and a thin runtime that doesn't clash with the host runtime. But personally I'd choose C/C++ for this, for the sake of existing support in writing bindings and C interoperability.


It may be interesting for replacing C to write high performance Python extensions (in my experience, C and Python go very well together, and Zig should be able to replace C pretty well in such scenarios).


Have you read the article? Half its examples are not well suited to Python/Go (maybe if you use micropython/tinygo instead).


You shouldn't, unless the speed of your Python/Go programs is an issue. Zig is a C-like language.


Fast code and fast compile time.


hmmm but how much of a performance gain is there from say CPython or even Go?

The syntax of Zig appears to be quite user friendly but not sure if there are hidden pitfalls.

I am excited for Zig but careful in adopting new languages but if this takes off, what sort of changes might we see? Cheaper C/C++ programmers?


> hmmm but how much of a performance gain is there from say CPython or even Go?

It depends on what you are doing.

If your python code is mainly calling out to highly optimized math routines, well, not much.

If you are doing lots of computationally intensive work, quite a bit.

If your Python code does a lot of allocating of memory, throws around lots of large objects, or has to parse a lot of inputs, then moving to a native language can be very beneficial.

> I am excited for Zig but careful in adopting new languages but if this takes off, what sort of changes might we see? Cheaper C/C++ programmers?

Newer more powerful languages tend to result in more complex software being written. Ignoring CPU and memory limits, no one would have been capable of writing a modern AAA game with the tools available back in 1992.


I'd say at least 2x-5x with Go and 10x or more with CPython, depending on the type of work.


It sounds like from your point of view, Zig, C, C++ and Rust are all pretty much interchangeable. I like Zig a lot, but don't expect that it will turn the world upside down. None of the new programming languages will make C, C++ or Rust more or less popular (not by a huge amount at least), they are just additional options to choose from. For instance C is alive and well at age 50, it will probably survive the next 50 years just fine (unless we switch to a completely different computing paradigm - but this would kill all other existing programming too).


>if this takes off, what sort of changes might we see? Cheaper C/C++ programmers?

Zig is very likely to appeal to people who loves C, or newcomers who are looking for performance.

The quality-of-life gains might lead to marginal changes in productivity/cost, but I would not bet on it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: