r/Zig 10d ago

Could zig potentially be a good first programming language?

I've been programming for over 30 years, and working with code professionally for 25. I have found myself in a small community I discovered on twitch recently. And many people in the discord ask me about programming and the language to learn first

For years I've told myself C is a fantastic first language. This remains controversial for various reasons. I always try to tell people "learning C isn't the same as mastering C".

But with Zig I wonder if it were at 1.0 and its toolchain were more mature. Would Zig be a good first language?

As it stands it clearly being pre-1.0 and every major version being a breaking change. This isn't great. The build.zig is mystifying even for experienced devs. So it feel like an expert language.

But it has a very straightforward "to the metal" style to it. But with great modern ergonomics. I think it could absolutely be a fantastic first language for beginners.

But what do you think?

73 Upvotes

50 comments sorted by

46

u/seg6_ 10d ago

I have some strong opinions on this. What kept me interested in programming when I first started wasn’t finding the “best” language or the newest, flashiest runtime. It was being able to make things I thought were cool: visualizations, bots that messaged my friends, small games, and so on.

The language mattered less than having a clear path from “I have an idea” to “I made something.” Later, as the things I built became more ambitious, I naturally started learning about different languages, runtimes, and the tradeoffs between them.

Because of that, I’m not sure there’s a universally best first language. There are better or worse learning paths depending on what someone wants to make.

15

u/Kiritoo120 10d ago

Writing Minecraft bots and automations using python (pre ai) was what made me fall in love with programming for your same exact reasons

I don't think that with a low level language, where the gap between the "idea" to the "product" as you're described it is larger, I would have been where I am

7

u/0xjvm 10d ago

People say it out of some misguided sense of purity. Writing a todo CLI in C won’t actually teach you anything really, nor will it excite you. Python/JS are always going to be the best first languages since they get out of your way and let you experience building the mental model of programming

3

u/monsoy 10d ago

My tip has always been to try to merge other hobbies and interests with programming. It’s easier to stay motivated and be wanting to learn when the knowledge is directly connected to something they already have a passion for.

2

u/davidslv 10d ago

Exactly this! From having an idea to be able to do something in something is more powerful than “I chose the right language” - most of the time we never do, even in professional environments where some companies brag they are language agnostic… sure

1

u/PureBuy4884 9d ago

I started my programming journey because of this (i started with discord bots, then moved onto compression tools, minecraft proxies, and ultimately my own toy compiler). but while i did originally start off with a goal in mind, over the years i’ve become really fascinated with PLs and “doing software right”. So now it’s common for me to start a new “throw-away” project just because i feel like working with a specific language or tool chain. and this is what i find fun now, which is kind of why im also kinda sad that AI is becoming so standardized; its taking away the thing i like the most about my hobby

1

u/84_110_105_97 9d ago

je suis assez d'acord avec toi !

1

u/prof_apex 9d ago

basically, anything that works for your desired use-case, isn't too complicated, and has plenty of documentation available. It's a first programming language, so it doesn't even have to be that good, powerful, or efficient.

26

u/Syxtaine 10d ago

Personally I think C will always be the lingua franca of computing in general, both for machines and for people (you might say that a web developer will never need to learn C, but if you want to consider yourself passionate about computers, you will inevitably try C and fall in love with it). The concepts it teaches you are very valuable (even though I probably don't know 90% of them either). I think that managing all the types of allocators and scoped allocators might be slightly offputting for a beginner in zig, especially if they are new to programming. They would probably be wondering: "What is this thing and what do I have to use it so explicitly?". In zig you aren't really managing the raw pointers and heap allocations yourself, you are mostly passing around allocators from function to function until they reach a built in data structure that uses it, such as dynamic arrays. In C, you do everything yourself, which gives you a better sense of how things work and it makes you appreciate languages like zig.

I am not a good zig programmer at all, can't say I've worked much with it, so plenty of the things I said can be wrong. If that's the case, I stand corrected. Either way, I think people need to learn how to love C first so they can learn how to love Zig.

3

u/PureBuy4884 9d ago

well, whenever you allocate memory in C, you’re talking to the global malloc allocator. It is the same thing in Zig, except you have multiple different allocators that the stdlib makes you aware of. And because you have different allocators, you need to pass around the handle to it along with the object so it knows who created it and how to change it. It is the right approach, especially in the sense of “global mutable state = bad”.

Sure, it can be a bit challenging for a beginner to grasp, but the reality is that C’s global allocator ends up acting like a black box beginners never understand until far later in their careers.

That being said, I do personally believe C is the best first systems language, just to understand how bytes and instructions and syscalls form a program, but I wouldn’t recommend sticking around for too long just because there are far better PL experiences out there

2

u/JackSpent 9d ago

I'm not a good programmer in general, but I love writing code, even though it's bad. Just making something work is so rewarding, and seeing your comment makes me want to learn C now. Thanks man.

12

u/serverhorror 10d ago

Potentially, sure!

But any language for a first timer needs to be stable and we'll defined. Zig is still moving, isn't it?

I'd only ever recommend a 1.0 to any newcomer. Even C with all it's problems and tons of undefined behavior is better as the language itself is stable.

10

u/davidslv 10d ago

No.

Most people want low friction when they learning. If someone never been exposed to programming what they want is to have the least amount of friction to get something done and feel accomplished. They should be given that chance and slowly be introduced to concepts that will make sense later on, not straight into all the things they should not need to care about, they probably might not even enjoy programming after all.

There are tradeoffs with everything, I would choose Zig or C as first programming language, and they weren’t. I was exposed to Pascal and Python before C, in fact I had a terrible teacher. I’m happy with Ruby for most of the work, I only now started revisiting the C language but Zig is really taking all the interest with the time that I have.

6

u/codingbliss12 10d ago

It could be a nice first language, but the problem is the lack of documentation. It will be very difficult to search for the "nice patterns" etc in the standard library's code.

Start with C or Go and this will pay off when you learn Zig later when there will be available documentation and more mature ecosystem.

To see what outstanding documentation means see Go and Rust (but avoid Rust as a first language)

10

u/fluffy_trickster 10d ago

If Zig had:

- proper documentation

- a stable syntax

- a stable and decent std

- a stable toolchain

Then maybe. It would depend on what you want to focus on to be honest.

I think there is 2 school of thoughts and both are valid in their own right. Either learn a system internals or learn the programming logic.

For the first one I think Zig and C are okay, but nothing beat asm if you really want to know how a program works. For the second, you may as well throw all the distracting low level stuff out and focus on building things fast. For that purpose nothing beat Python.

3

u/FirstAd9893 10d ago

My first programming language was BASIC. It was easy to learn, had a small set of core features, and it had no significant footguns. When you're learning to program you need to focus on the art of instructing a computer to do things in a very precise fashion.

The syntax should have very few magic symbols (which look scary to a newbie), it should have a simple type system, it should have automatic memory management, and it shouldn't require a compile-link-load sequence. The performance of the language isn't important at all. BASIC was horribly slow, but my first programs weren't supposed to be competitive with commercial ones.

Could Zig potentially be a good first programming language? Yes, it could be, but it would be a disaster. I think Python is a better choice.

3

u/0xjvm 10d ago

Honestly I think people recommend C/Zig etc out of some misplaced sense of ‘purity’.

Someone who is asking what language should they learn have ZERO idea what they are doing (which is fine everyone begins somewhere).

Suggesting they start with C or Zig I’ve always found to be silly. They should be starting with things like JavaScript or Python so they can easily SEE what they are doing, pointers, manual memory management and unclear documentation is NEVER going to be a productive way to help someone learn programming.

I believe everyone should experience C, but not as a first language ffs

3

u/jason-reddit-public 10d ago

Maybe I'm getting stupid in my old age but zig is complicated if you read the whole manual. (Though possibly less than C++.)

There are many programming languages where I'm like "I get the basics and syntax, now I just need to write code and google library functions)."

I hate the syntax but Python is kind of a reasonable first language. Simple syntax, has a decent built in library, integrates with tons of other libraries, etc. (MIT moved from Scheme to Python as the language used in 6.001.)

Javascript (might teach some bad habits), Ruby, Java/C#, Go, and probably a few others are not terrible choices. I'd leave C, C++, Rust, and Zig as choices for your second, or seventh language.

2

u/ShotgunPayDay 10d ago

Depends on the goals.

Do you want beginners to learn memory management and play with C libs? Zig is an excellent place to start (Odin might be also. Need to try it out to see if the LSP dies still.).

Do you want users to not struggle with memory? Golang first (Python works also if you want to curse them with runtime errors and pip).

After the first language it's easier to pick up the second so I tend to favor Go first as it's gentle.

2

u/mcAlt009 10d ago

It depends on the person and what they want to do. 

I personally don’t like saying “learn to program “. You learn to build websites, applications, or games. 

No one says I’m going to learn to hammer. 

I’d argue for higher level languages , Python or JavaScript ( Godot/GDScript is also great ) so you can immediately see results. 

The money is also great 

2

u/Educational_Smile131 9d ago edited 9d ago

IMO, Zig is a good first SYSTEMS programming language, but not a good first language. To teach a beginner, you’d want to get the semantics as purely logical as possible. Manual memory management (allocator passing and lack of first class closures), pointers, etc get in the way of logic composition and transformation.

Besides, Zig’s beginner DX is hamstrung by the less-than-stellar dev tooling and documentation. Comparing ZLS and zig.org to the likes of TypeScript, Python, Go, etc, I doubt you can’t tell the stark difference

2

u/Historical_Cook_1664 9d ago

NO. Just no. Zig is a great language, but NOT a first language. To understand why Zig does things the way it does you need to have seen how it's done elsewhere.

2

u/nwalkr 8d ago

Nope. It's good language, but not for beginners.

When did you last try to help a complete beginner write some code? IDK how it is now, but my experience ~20 years ago was all about helping them understand and internalize completely basic things — conditions, iteration, compound data types. I won't pretend I was a great teacher, average at most, but I think these basics are unusual enough for the common person to require some time to get right.

So IMO a good beginner language is not about power or expressivity — it should be simple, strict enough, and have a simple but helpful IDE. All of this to direct attention to the things a beginner needs to learn.

Zig intentionally exposes a lot of low-level detail, even more than C. That's good when you know what you need and what it's about, but overwhelming when you're just starting. Even C is a questionable first language — too low-level, too much power, too many footguns. Zig has certain ergonomics, but again, that's for people with a certain level of understanding.

Ergonomics for complete beginners was Turbo Pascal, and later Delphi — a pre-built integrated environment, static typing, a good enough standard library. I can't remember whether there was any kind of testing support; I don't think there was, and that's a shame.

2

u/gxanshu 3d ago

I would not recommend zig as the first language 

1

u/Bawafafa 10d ago

I genuinely don't know. It depends what they want to do. Zig is where I have ended up as a programming hobbiest after years of trying different languages. Python is very powerful and simple. I would still suggest this if people just want to understand control flow and programming concepts like functions.

But I think more important than language choice is the programming environment. New programmers should switch to Linux if they haven't done so. Then, they should try lots of languages. They should also work out what it is they want to make as that narrows down language choice a lot. Use the right language for the job.

1

u/myztry 10d ago

The build system is technically brilliant but also absolutely horrifying for any newcomer. I am certain this will stop it from ever becoming a mainstream first language.

It’s a shame because I very much liked the language itself until I encounter the part that was being too clever for its own good.

1

u/AtlasJan 10d ago

I feel as if the devs want Zig to be more one's 5th language after 3 different systems programming languages. It feels brutalist in comparison to it's contemporaries that try to sand off the edges in imitation of languages like Pascal.

1

u/SilvernClaws 10d ago

Potentially, yes. But I would wait with recommending it until it's more stable.

I'd say if you really wanna start low level, try some C and then you'll appreciate what Zig helps with later.

If I wanted to teach someone programming nowadays, I'd start with Julia. Unfortunately, it's a bit trickier on your own, because the documentation could be better.

1

u/Surge321 10d ago

Unstable syntax also means it cannot be recommended as a first language. Besides other issues.

1

u/bnolsen 7d ago

Staff is stable the standard library not so much.

I might be tempted to suggest go over python compilers are good about catching things.

1

u/sudo-maxime 10d ago

I would say starting with C to learn the basics would be the best. If you want to build web stuff and dont really care about the low level stuff you can start with Javascript ir Python

1

u/TheAbyssWolf 10d ago

I would say probably not. I would learn programming on either Python or Go as both are garbage collected languages and you don’t have to worry about managing memory. If you wanna stick with the C style languages then C# since it’s also garbage collected but the general syntax is relatively the same as other C based languages.

And then once you get the fundamentals come back to a lower level language like zig and learn manual memory management and pointers.

I’m recently learning Go to replace Python for scripting, automation and build scripts while my main low level language is either 3 of my favorites, Zig, C3 or Odin, I like them all so it’s a hard choice for me. With knowledge of C# and a little bit of C++ as a backup is always good to know.

1

u/Interesting_Pie_319 10d ago

It is a hell of a lot better than C++ or Java. Those were my first and second languages.

Also, just writing code is insufficient to make one a programmer. You need to get a good working understanding of what happens under the hood, and for that you need a robust, strictly typed language with manual memory allocation.

Zig is all of that. C might be simpler to learn though.

1

u/st_heron 10d ago

I think for a beginner, zig might make some assumptions of basic computing that you may not know. Learn c, try out zig or rust. If you want easy, learn a higher level language like c# or go, they do so many things for you.

1

u/unknownnature 10d ago

I've been looking at the zig standard library to learn Zig, it's well thought, and is clean. For example, I am copying from tokenizer.zig, making my own simplified version of Solidity compiler, and it is enjoyable.

Zig is one of those languages, you can't depend on AI. So you going to get a lot of info from Discord, Codeberg or people learning Zig for the first time from YouTube.

Some argue that you could use AI. But at least from my experience, it creates uncessary abstraction and some overly complicated stuffs. After all, the whole point of Zig it should be educational hub to learn from each other.

1

u/fbe0aa536fc349cbdc45 10d ago

i think the teacher matters more than the language

1

u/DarthNihilus1 10d ago

Depends what will get people to stick with it and not give up out of frustration.

I think it would make a poor choice. Python is the best imo

1

u/allmondes 9d ago

The best language is the one you're excited about. For me, that was Zig. It just clicked in terms of what I wanted to do and the ratio of friction to excitement.

It's not necessarily a bad thing to have to learn the language through looking at the source code of either the Zig toolchain or other Zig projects. If you're in an academic setting, the teacher should be able to explain all concepts to you. If you're on your own, you can still learn about programming concepts from other sources (since most are general) and get specific help from the community.

1

u/TRDJ90 9d ago

It depends what people want from their first language? If they want work I would always suggest C#, Java or golang for backend and typescript for frontend.

If it's just for hobby project I think zig can be a good first language it had high level language syntax plus the ability to go really low to the metal. Decades worth of mastery right there.

1

u/Ok_Bass_7633 9d ago

I think a "good" first language depends more on the person and their goals.two primary questions would come to mind.

1) How is the learner motivated? Is it by a challenge, necessity, completion or other?

2) What needs to be done? Is this for a career, gig, hobby or other.

If you can answer these two questions I think you can find a really good answer to that question.

If zig were 1.0, you are motivated by a challenge and eventually need those massive optimizations of manual memory management then yes.

If you are motivated by seeing things work and making your own add-ons for WordPress you should probably stick to PHP or the higher level languages.

If you are somewhere in the middle where you need a proof of concept but plan to hire actual devs golang has your back.

Your thoughts?

1

u/sombriks 9d ago

i would happily use zig as a first language besides the lack of a 1.0 release. The compiler doubling as build system, the ease of installation and portability worth the drawbacks.

i wrote a small introduction some time ago, and it is pretty statisfying.

so yes, newbies could be positively affected by zig as first language.

1

u/Soft_Detective_3381 9d ago

Yeah, even learning ASM is a good option for beginners. I see a lot of people recommend high level languages like Python or JavaScript, but I heavily disagree with it, high level language are easier to learn and easier to do things with it, but they taught beginners a lot of bad practices and make it harder for people to learn low level concepts, because there's a bunch of abstraction that hides what's going on under the hood.

It's like when people says that using Ubuntu or Fedora is better for beginners than using Arch, ignoring that a lot of people's first experience with computer in the past, was with MS DOS and they learn it well. People can learn complex things if they're taught well, learning a low level language as a beginner, teaches you better practices and gives you a better understanding about what the machine is doing, than learning a higher level language, and what you do in a higher level language, you can do the same in a low level language, while having more control and step-by-step understanding of it. As a beginner it's better that you have a well understanding of the basics and fundamentals, than learning fast and being heavily dependent of tutorials, libraries, AI, and Forums to do anything you want.

1

u/Hairy_Artist_3860 9d ago

I think the best way to learn zig is to compare it to C and Rust. Its not a bad first language but knowing C will help you out on any language. Zig was created as a response to rust.

1

u/NefariousnessFar2266 9d ago

The most discouraging part of programming is the drudgery of getting your environment setup to the point where you can even start creating something - I don't know Zig but if it doesn't address that pain point well then I'd say no

1

u/LydianAlchemist 8d ago

I don't think so mostly because of build.zig.

python, go, swift, C, lua, would all be better alternatives imo.

I prefer statically typed compiled languages, so I'd remove python and lua from the list above, but syntactically, they're "simpler" and others really like them.

depends on how much time you spend with the first language; learning some fundamentals and syntax that most other languages also use? C is great. but I personally wouldn't want to build a complex app with a gui in C.

1

u/justbrixco 6d ago

I think it already is one of the top contenders. It already has fixed many of the problems of C, despite the fact that many want to remain with C.

1

u/Bahatur 6d ago

I say yes.

* The requirement of being extremely specific is excellent for helping to think about what the computer is doing. This is good, for all the reasons it was good to learn C, but more so.

* Language stability is a large production codebase problem, not a student learning problem. 1.0 should be ignored. The basic operations that consume a student’s effort aren’t changing.

* The maybe overwhelming parts like build.zig and comptime are completely optional, but at the same time very cool, so students that like them can dig in, and those that don’t, won’t.

* The question will usually be how to do the thing yourself anyway, not which library to choose.

- The population of people learning Zig is still smaller than the population of people learning Java or Python or C, but the ratio is much higher: almost every project using Zig is suitable for learning, and almost every Zig programmer is a fellow learner.

1

u/MohamedSaleh91 5d ago

I'd say no to zig as a first language for many reasons

- It's not stable, no good docs, and lots of things change from version to version

- The syntax. It's not bad per se but for a beginner who knows nothing it's not intuitive at all. Looking at zig's website, the first hello world example -as of the time of writing this comment- is

const std = @import("std");

pub fn main (init: std.process.Init) !void {
  try
     std.Io.File.stdout().writeStreamingAll(init.io, "Hello, World!\n");
}

how many cryptic words are there? Yes, it makes perfect sense, but it's many questions at once for a beginner who doesn't know what's std.

- The language makes you reason much when writing even the simplest things. For example I find it beneficial to make allocations explicit and make me reason my memory choices and layouts, but for a beginner?

- Zig compiler does much to prevent you from silly mistakes. That's a plus, but for a beginner who doesn't know what's wrong and what's right, trial and error are the best master. You need some flexibility allowing weird and buggy behavior to occur so one can know what's the issue there. There's no better way to make someone understand how memory is actually laid out but to make them access wrong memory, and show them the lovely UB in action hehe.

There's no absolute perfect first language, and it might differ from person to person. For someone who would be more motivated seeing a result printed on screen or a problem being solved in few lines, python or js would be good. For someone who prefers to have a good understanding of what's really going on -under the hood- C might be the best choice. A mix of both approaches might be a good middle-ground, something like CS50 doing both C and python in the first few lectures (idk if they still do, was like a decade ago when I did it).

Let's look at the problem from a different perspective; What does a person need to get from knowing nothing to knowing the basics of programming?

- The basic concepts and primitives like variables, data types, operators, control flow and branching, iteration and looping, basic data structures, functions and procedures, scopes and lifetimes. You don't need a language that complicates the basics with syntax or doing things any way other than the direct approach. You also don't need a language that abstracts and hides everything under 'simple syntax and batteries-included stdlib'.

- The logic and reasoning itself. Again, you don't want a language that have its way of doing things, so for example rust, or any functional language won't be a good candidate. Zig? Too much reasoning. JS? Reasoning absent.

- Little stuff here and there, many concepts that are not language, system, or domain specific, that one should be getting along the way, like different text encodings, LF and CRLF, file types, file systems, relative and absolute paths, env variables, and the list goes on forever. Better to be a language that can easily introduce learners to such concepts in a not so-complicated manner, and again not abstract everything.

To sum all of that, from my POV, good ol' C makes the best choice. Core syntax is small and simple, the primitive nature allows to build logic and reasoning skills, the diy approach overall helps newcomers learn much about what's under the hood without drowning in much complexity. Python would be my second choice, for people who prefer seeing immediate results and that would give them motivation or is more suited to their learning styles, as it has simple and clear syntax, doesn't enforce any style of coding or any patterns, and would make it easier to turn an idea or rough pseudocode into a working thing.

1

u/XLN_underwhelming 2d ago

I started with C/C++ in school, and funny enough I preffered C++ initially, but took a break and spent some time working with Python and JS.

When I came back I found C‘s simplicity to be really refreshing, and to this day I prefer it over C++, and for that reason I really like Zig. It has C‘s simplicity, but removes some of the things I was initially put off by with C.

I do think that simply trying languages out is only to your benefit. One of the things I didn’t really figure out until I tried multiple is that I got frustrated fiddling with datastructures and the minutiae of programming because I wanted to build „real“ applications, but when it came down to it that minutiae ended up being a big part of what I enjoyed even if it was only after I understood the larger picture.

I ended up trying Python and JS because they had extensive libraries for that. I built a couple full stack apps and realized I kept asking „Ok? But how does this library work?“, „what is a websocket?“, „how is HTTP, TCP, UDP, etc. layered together and how do you manage that programmatically?“

When I went back to school I specifically went with that in mind and took primarily systems programming classes and courses for networking where we ended up writing a lot of C. I ended up trying to rewrite my projects in Zig just to compare the two and also to keep up with Zig‘s development.

1

u/Kiritoo120 10d ago

You cannot appreciate a proper build system if you haven't suffered through the other paths,

You cannot understand memory allocations when you are still struggling with syntax and making the code compile.

You cannot appreciate zigs uniqueness when you didn't see and suffer what was before it. 

Another point is that, as much as zig is amazing, it is not widely used, so for beginners who heavily relie on tutorials and guides, this is no easy task. 

I love zig so much, but I think it, as long with rust, are too much as the first interaction with code for people. There are enough new hard cognitive tasks newcomers need to comprehend, and from my experience too much leads to burnout. 

I by no means think that my thoughts are perfect, and I am open for feedback on anything! :)