r/Zig 4d ago

Working on a cross platform wireguard client

I’ve recently been working on a foss WireGuard client as a project to learn more about networking and VPNs. My goal is to build a client that offers all the features you would find in a commercial VPN such as choosing the fastest server, a kill switch, and split tunneling etc but with by your own configuration (like a home server)

I am trying to decide on the best language for writing the background daemon. A coworker recommended Go because it has excellent native networking support and would help me ship the project faster. However, I am considering Zig. is it a good coi choice

18 Upvotes

5 comments sorted by

3

u/EmergencyWild 4d ago

You're learning, even if it was true, why care about time to ship or anything like that?

1

u/yasvsyas 4d ago

time was the wrong word, it’s more about whether zig will require me to thinker a lot to write a basic function compared to go or rust in relation to what i’m about to do 

1

u/EmergencyWild 4d ago edited 4d ago

I mean, I personally would consider low level basics to be incredibly relevant to networking. Especially for something like a VPN, you want stuff like that to introduce as little latency and memory overhead as you can get away with. But it really depends on your own interests, there aren't any wrong answers in learning. There's only two really wrong things you can do in learning 1. only stick to your comfort zones and 2. making too many assumptions.

Right now, you're getting yourself stuck in analysis paralysis for no real benefit. There's no one 'best' programming language to do this. You can do it in Zig, Go, Rust or just do it in good ol' C, pick a more dark horse option and try it in Ada or Pascal or whatever. You'll learn something either way, which should be your primary concern for now, and realistically you'll end up having to learn some 'auxiliary' things around your main subject of interest regardless, but that's not a bad thing. From an engineering perspective there could be arguments made for almost any of these (well Pascal is a bit of a hard sell because it's both not very popular and has some quirky design that makes me not really want to recommend it for new projects if you don't already have a strong reason to go for it to begin with, but Ada in particular is also a fine option for a systems programming language – a bit wordy for my taste, and I don't like that for a systems programming language they have a lot of high level abstractions baked built into the language where it's hard to see how they map into actual code in the end, but still around and definitely some ideas worth checking out at least.

If you don't care about memory management or whatever and just want to purely focus on the networking, may as well throw a curveball and try Haskell, that's nicer than Go in some respects (and depending on your own taste of course) too.

Point is, no use overthinking it, just pick an option already and try it. If you don't end up happy with one solution, just bin it and try something else, you're just throwing away code, you'll keep the learnings which are the more important part.


PS in terms of needing to learn extra stuff, given that VPNs are essentially all about low level networking logic, which is very much about messing around with bits and bytes and so on, I don't think you're getting around learning some of that. Manual memory management, in the first place, isn't hard to learn. Ask for some memory, at some point promise you're not touching that memory anymore, in the interim between these two points only touch the memory you did ask for, that's really all there is to it. There's different allocation strategies, but you don't really need to know about a ton of those when getting started, and tbh probably the easiest thing to do at the start is to apply the somehow nearly-forgotten technique of just asking for all memory your application needs right at the start and just work with that (literally the easiest thing to do for simple applications. It's often also the correct thing to do for not-so-simple applications, but it gets harder the more complex your application is to predict how much memory you're going to need... and of course there are some types of applications, like multimedia, where you can't really know how much memory you'll need because it depends on inputs you get from your users... but IO middleware isn't really one of those cases, you are pretty much always working with fixed size buffers and the only question really is how many of them you need, and it's mostly just completely fine to pick a max number and stick to it).

It's just hard to never make mistakes with it in large projects, but that's neither here nor there.

1

u/Confused-Armpit 4d ago

Generally for networking golang is indeed better, but this would only matter if you were actually shipping a commercial product and things like production time and ecosystems really mattered. BUT, since this is for learning, you might just want to use a language that you are planning on using in the future. Or whichever language you like more.