Live data from Hacker News

Functional programmers need to take a look at Zig

pure-systems.org

91–100 of 163 posts

Re: Functional programmers need to take a look at Zig

#91
My stack today is kinda nice but perhaps a bit odd:

- Go - backend + CLIs

- TypeScript - fronted, occasionally zx for more complex scripts

- Nushell as my scripting language (I’ve been relentlessly using it everywhere I can instead of bash/zsh and man it is such an improvement)

I heard so much good stuff about both Zig and Rust and would love to eventually get to know one of them.

Re: Functional programmers need to take a look at Zig

#92

These days I just use a few languages: 1. Go, when I first saw code I wrote almost a decade ago still compiles and runs in Go, I decided to use Go for everything. There were some initial troubles when I started using it a decade ago, but now it's painless. 2. Haskell, I use it for DSL and state machines. 3. Bash for all deployment scripts and everything. 4. TypeScript, well for the frontend. Lately, I’ve been using G…

The funny thing is how ubiquitous TypeScript/JavaScript is. There is no escape. I also only use four languages: C#, F# (for DSL), Powershell (for deployment) and... TypeScript. Despite we have different tastes in language and are in completely different ecosystems, TypeScript is still the lingua franca lol.

Whether there is any escape from JS/TS is a matter of what you are building and who is around you. If you are building SPAs all day, then sure, you will probably have to deal with the JS/TS ecosystem. If you are just building websites, then basically any traditional web framework would do. Only that then it depends on whether you have to work with people, who don't know web basics or people who want to use JS web frameworks even when there is no need, in majority, so that you get no choice, but to work as a team.

In theory most websites could be done statically with rendered HTML and CSS and maybe a little bit JS, but not mandatory, and having noscript fallback flows. MPAs are fine for most things and having noscript fallback flows can also be done kind of systematically, and in many cases isn't that difficult. Just that these days not many people bother or care.

Re: Functional programmers need to take a look at Zig

#93

My stack today is kinda nice but perhaps a bit odd: - Go - backend + CLIs - TypeScript - fronted, occasionally zx for more complex scripts - Nushell as my scripting language (I’ve been relentlessly using it everywhere I can instead of bash/zsh and man it is such an improvement) I heard so much good stuff about both Zig and Rust and would love to eventually get to know one of them.

Nushell, from their website, looks a lot like PowerShell's idea of a shell, but less verbose.

Re: Functional programmers need to take a look at Zig

#94
post #66

Earlier quoted context omitted.

Of course you can: you just have to define it in your type. The output set becomes a union type of the normal output and whatever you want as an exception. If you write this as a monad, your get very similar syntax to procedural code.

I get what you are saying, but… An exception is different to an Either result type. Exceptions short circuit execution and walk up the call tree to the nearest handler. They also have very different optimization in practice (eg in C++)

I'm what way is that different? You return early and the call Cascades up the call chain until you handle it (otherwise it's always an "either" results)

In practice you use something like an exception monad, which makes this a lot more ergonomic since you don't need to carry a case distinction around for every unwrap: an exception monad essentially has an implicit passthrough that says "if it's a value, apply the function, if it's an exception just keep that". You only need to "catch" the exception if you actually need the value. I'm this case the exception monad is not that different from annotating a function with "throws": your calling function either needs it's own throws (=error monad wrapper) in which case exceptions just roll through, or you remove the throws, but now need to handle the exception explicitly (=unwrap the monad).

Re: Functional programmers need to take a look at Zig

#95
post #72

Question for Zig users: Can comptime blow up compile times? Does it have arbitrary cutoffs like C++ template depth?

You can think of comptime (as of zig 0.16) as an interpreter that evaluates code with very limited optimization. So yes, naive use of comptime can definitely grind compilation to a halt.

Zig tackles the halting problem a bit differently by putting the evaluation cutoff in userspace through the compiler builtin function `@setEvalBranchQuota`. You bump up the quota as you see fit.

Re: Functional programmers need to take a look at Zig

#96
post #93

My stack today is kinda nice but perhaps a bit odd: - Go - backend + CLIs - TypeScript - fronted, occasionally zx for more complex scripts - Nushell as my scripting language (I’ve been relentlessly using it everywhere I can instead of bash/zsh and man it is such an improvement) I heard so much good stuff about both Zig and Rust and would love to eventually get to know one of them.

Nushell, from their website, looks a lot like PowerShell's idea of a shell, but less verbose.

Yup. Which is kinda funny, because back when I was a young dev using Windows I never liked nor understood PS.

Re: Functional programmers need to take a look at Zig

#97

I would encourage everyone remotely interested in Zig to have a look at Odin[1]. If like me, you read that article and found yourself muttering "what the hell," then you might appreciate Odin's simplicity and design consistency. I am definitely in the minority here, but I am not a fan of the kind of meta-programming that Zig and Rust offer, with Rust being especially atrocious. In the two decades I've been programmin…

Same. Meta programming is nice when it fits the problem, but most meta programming I’ve seen has been a net negative.

Odin is also my favorite language in its class. It’s genuinely a gem.

Re: Functional programmers need to take a look at Zig

#98

These days I just use a few languages: 1. Go, when I first saw code I wrote almost a decade ago still compiles and runs in Go, I decided to use Go for everything. There were some initial troubles when I started using it a decade ago, but now it's painless. 2. Haskell, I use it for DSL and state machines. 3. Bash for all deployment scripts and everything. 4. TypeScript, well for the frontend. Lately, I’ve been using G…

I also LOVE Go, but recently rewrote a small tool to Lisette [1]. Its was the most fun i had in a long time while programming.

I can Highly recommend it, specially because you have Haskell experience (you get all the usual suspects, like ADTs, exhaustive pattern matching etc) in Lisette code. It has a fast compiler too, and produces human readable Go code. It also comes with great tooling out of the box (formatter/lsp etc).

1. http://lisette.run

Re: Functional programmers need to take a look at Zig

#99
post #93

Earlier quoted context omitted.

Nushell, from their website, looks a lot like PowerShell's idea of a shell, but less verbose.

Yup. Which is kinda funny, because back when I was a young dev using Windows I never liked nor understood PS.

> when I was a young dev … never understood PowerShell

This makes me feel old.

Re: Functional programmers need to take a look at Zig

#100
post #62

These days I just use a few languages: 1. Go, when I first saw code I wrote almost a decade ago still compiles and runs in Go, I decided to use Go for everything. There were some initial troubles when I started using it a decade ago, but now it's painless. 2. Haskell, I use it for DSL and state machines. 3. Bash for all deployment scripts and everything. 4. TypeScript, well for the frontend. Lately, I’ve been using G…

I am in a similar place. Especially regarding Bash. Used to be in a few companies where most developers just couldn’t/wouldn’t write in more than one language and it was always a pain to maintain different runtimes, languages, packages and internal dependencies of things that could have been a 20-line bash script, and had to be maintained and updated from time to time. I understand people have their own limitations a…

Funny, I have also converged on shell scripts for simple scripting or configuration, but I use /bin/sh for portability. Many of the machines I use do not even have bash installed.
Post reply on HN