Live data from Hacker News

Functional programmers need to take a look at Zig

pure-systems.org

81–90 of 163 posts

Re: Functional programmers need to take a look at Zig

#81
post #10

A functional programmer who casts away proper sum types and pattern matching is no functional programmer at all

I thought lisps were all functional programming, and lack sum types and pattern matching? In which case, what's the term for the "proper sum types and pattern matching" flavour of things?

Most Lisps have some sort of pattern matching in their standard library. Common Lisp has sum types with deftype.

Re: Functional programmers need to take a look at Zig

#82

While using "monads" in functional languages is a neat trick, I do not like them. In my opinion, the concept of automaton is fundamental and it deserves equal standing with the concept of function (even if it is a higher level concept that is built upon that of function). I believe that functional programming is preferable wherever it is naturally applicable, and most programs have components of this kind, but most c…

You can't just put assignment in a functional language though - you lose the ability to fearlessly refactor that's the whole point. You either need something like a stratified language (which I've never seen actually implemented, much less production-ready, as much as I like the design of Noether), or you use, well, monads.

Re: Functional programmers need to take a look at Zig

#83

Earlier quoted context omitted.

Java is a resource hog when you use patterns and libraries popular in Java land. When you are working in the Java ecosystem, you just assume that this much resource is needed by the app! But when you'll code the same thing in Go using the same methods, you'll find resource usage is really very low. We’ve a 1: 1 copy of the app; on JVM, it's using 2GB RAM using Spring Boot, and on Go, it runs on 512MB RAM and is blazi…

I cant really agree on Rust. It does take a bit more time to write the same code in rust vs go. But in my experience the code is much more likely to be incorrect in go than it is in rust. Which over longer periods means rust is easier to maintain.

On the other hand, most pieces of software in this world are kind of mediocre code written by unmotivated employees within tight timelines.

In such context, I think Go might be a better or at least, more realistic, compromise in most cases.

Re: Functional programmers need to take a look at Zig

#84
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 programming I can count on one hand the number of times meta-programming was an appropriate solution to a problem I had. Every time I reached for it, I got bit. There's a reason "when in doubt, use brute force" is sage advice, it may not be fast and glamorous, but it'll be a hell of a lot less opaque.

[1] https://odin-lang.org/

Re: Functional programmers need to take a look at Zig

#85
post #26

Earlier quoted context omitted.

I don't think so, where's the extra information in the Zig example? In Rust, which is arguably also a low level language, it looks like this: enum Option { None, Some(T), }

Low-level doesn’t mean more information, it means more explicit. In Zig, that means being able to use the language itself to express type level computations. Instead of Rust’s an angle brackets and trait constraints and derive syntax. Or C++ templates. Sure, it won’t beat a language with sugar for the exact thing you’re doing, but the whole point is that you’re a layer below the sugar and can do more. Option is trivi…

> Option is trivial. But Tuple? Parameterizing a struct by layout, AoS vs SoA? Compile time state machines? Parser generators? Serialization? These are likely where Zig would shine compared to the others.

I don't see how any of that becomes easier in the Zig case. It's just extra syntactic ceremony. The Rust version conveys the exact same information.

Re: Functional programmers need to take a look at Zig

#86

Earlier quoted context omitted.

Why did you give up on Java and Rust?

Java is a resource hog when you use patterns and libraries popular in Java land. When you are working in the Java ecosystem, you just assume that this much resource is needed by the app! But when you'll code the same thing in Go using the same methods, you'll find resource usage is really very low. We’ve a 1: 1 copy of the app; on JVM, it's using 2GB RAM using Spring Boot, and on Go, it runs on 512MB RAM and is blazi…

> using SpringBoot

well there's your answer, isn't it?

Re: Functional programmers need to take a look at Zig

#88

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…

Would love to use go for SaaS but things like OmniAuth (RoR) make me stay with Ruby. I actually never used ruby before, but I think its a swell language to do SaaS in.

Re: Functional programmers need to take a look at Zig

#89

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 went the same way but with only using Lisp dialects like Elisp and Clojure and Nix. Although I would ditch Nix too if another Lisp could supplant it too.

Elisp and Common Lisp for me, although I still use bash in the terminal.

Re: Functional programmers need to take a look at Zig

#90

Earlier quoted context omitted.

"slightly different ways to initialise stuff." can you elaborate? theres only what 11 datatypes in elixir?

Perhaps they are referring to the syntactic sugar around keyword lists? [a: 1, b: 2] == [{:a, 1}, {:b, 2}] Or maybe atom vs string keys in maps? %{a: 1} vs %{"b" => 1} Or keyword lists always needing to come last in lists? [some: :value, :another] # error [:another, some: :value] # valid Or maybe something else entirely. Those are just things I remember having to lookup repeatedly when I was first learning elixir.

These are the ones. I just can't remember them.
Post reply on HN