News for hackers. Stuff that matters.
Re:Zig self hosted compiler is now capable of building itself by cercatrova on Saturday April 16, 2022 @11:36AM (#31053131)
I was thinking of learning Rust but it seems a bit overkill due to manual memory management as compared to languages with similar speed like Nim, Zig, and Crystal. How would one compare these languages?

Is it worth learning Rust or Zig and dealing with the borrow checker or manual memory management in general, or are GC languages like Nim or Crystal good enough? I'm not doing any embedded programming by the way, just interested in command line apps and their speed as compared to, say, TypeScript, which is what I usually write command line apps in.

Re:Zig self hosted compiler is now capable of building itself by lijogdfljk on Saturday April 16, 2022 @12:58PM (#31053940)
It's funny i came to Rust from Go, Python, NodeJS, etc after a combined .. 15 years or so. I've been using Rust full time (work & home) for ~2 years now.

Obviously i'm biased, but i quite enjoy it. I find i am more efficient now than before, because it manages to give me the ease of the "easier" languages quite often with a rich set of tooling when i need to go deeper.

Personally i feel the concern over the borrow checker is way overblown. 95% of the time the borrow checker is very simple. The common worst case i experience is "oh, i'm borrowing all of `foo` when i really want `foo.bar` - which is quite easily solved by borrowing just the `.bar` in a higher scope.

The lifetime jazz is rarely even worth using when compared to "easier" languages. Throw a reference count around the data and you get similar behavior to that of them and you never had to worry about a single lifetime. Same goes for clones/etc.

I often advocate this. For beginners to use the language like it was a GC'd language. A clone or reference count is often not a big deal and can significantly simplify your life. Then, when you're deeper into the language you can test the waters of lifetimes.

So yea. Your mileage will vary i'm sure. But i find Rust to be closer to GC'd languages than actual manual languages, in UX at least. You won't screw up and leak or introduce undefined behavior, which is quite a big UX concern imo.

Re:Zig self hosted compiler is now capable of building itself by capableweb on Saturday April 16, 2022 @05:31PM (#31056265)
The perspective of someone who is learning Rust (but not professionally) during the last few months. :

- The borrow checker is one of the easier parts of Rust to grok, it's just as you say, not that complicated in the end.

- Traits are more annoying to understand and find in source code when they can get added from anywhere, and suddenly you code gets extra functionality, or it's missing the right one unless you import the right crate but there is no "back-reference" so you're not clear what crate the code actually comes from.

- Crates/libraries are harder to grok with their mod.rs/lib.rs files and whatnot, in order to structure your application over many files.

- Macros are truly horrible in Rust, both to write and debug, but then my only experience with macros are with Clojure, where writing macros is basically just writing normal code and works basically the same way

- Compilation times when you start using it for larger projects tend to be kind of awful. Some crates makes this even worse (like tauri, bevy) and you need to be careful on what you add as some can have a dramatic impact on compilation speed

- The async ecosystem is not as mature as it seems on first look. I'm really looking forward to it all stabilizing in the future. Some libraries support only sync code, others only async but only via tokio, others using other async libraries. Read somewhere that eventually it'll be possible to interop between them, time will tell.

- Control flow with Option/Result and everything that comes with it is surprisingly nice and something I'm replicating when using other languages (mainly a Clojure developer by day) now.

My development journey was PHP -> JavaScript -> Ruby -> Golang -> Clojure with doing them all the capacity of backend/frontend/infrastructure/everything in-between, freelancing/consulting/working full-time at long term companies, so take my perspective with that in mind. Rust would be my first "low-level" language that I've used in larger capacity.

Re:Zig self hosted compiler is now capable of building itself by Georgelemental on Saturday April 16, 2022 @07:10PM (#31056917)
`rust-analyzer` lets you find the trait/impl that provides a method, if you don't have it in your IDE you should get it.
Re:Zig self hosted compiler is now capable of building itself by capableweb on Sunday April 17, 2022 @05:31AM (#31059632)
True, that does help when you want to dig into things. I think my main pain-point here is that without extra tooling, the reference is not surfaced. Compare this to Clojure, where every reference is explicit, things normally don't get "magically" created in your scope. Just by searching for a var in the current file upwards (up to the `ns` declaration), you can find out where code is coming from, which is not always possible in Rust.
Re:Zig self hosted compiler is now capable of building itself by jackosdev on Saturday April 16, 2022 @09:14PM (#31057553)
It takes you to the trait definition but not the specific implementation. There is an open issue looks like a hard problem to solve, but intellij does it so must be doable.
Re:Zig self hosted compiler is now capable of building itself by klabb3 on Saturday April 16, 2022 @03:10PM (#31055154)
> Personally i feel the concern over the borrow checker is way overblown. 95% of the time the borrow checker is very simple.

I have been using Rust professionally as well and had a different experience. For anything singlethreaded I agree with you. For any asynchronous behavior, whether it's threads or async or callbacks, the borrow checker gets very stubborn. As a response, people just Arc-Mutex everything, at which point you might as well have used a GC language and saved yourself the headache.

However, enums with pattern matching and the trait system is still unbeatable and I miss it in other languages.

Re:Zig self hosted compiler is now capable of building itself by melony on Saturday April 16, 2022 @03:07PM (#31055138)
The problem is that when lifetimes cause you problems, it can force the entire feature development to stop until the problem is fixed. There is no reasonable escape hatch or alternative (clone doesn't always work).
Re:Zig self hosted compiler is now capable of building itself by klabb3 on Saturday April 16, 2022 @03:23PM (#31055273)
+1. My programming style normally consists of trial-and-error style prototyping for a couple of iterations, and then later refining that into something that's solid and robust. I find Rust's inofficial "prototyping mode" difficult to combine with it's regular "production grade mode" for practical purposes.
Re:Zig self hosted compiler is now capable of building itself by pornel on Monday April 18, 2022 @09:49PM (#31078999)
Rc/Arc is usually the escape hatch. I presume you put raw pointers under the "no reasonable" caveat, but if the borrow checker is wrong and you're right, they can be the right tool too. They're not unreasonable if the alternative was to use a different language that couldn't guarantee this safety either.

I know dealing with the borrow checker can feel like a dead-end sometimes, but dealing with it is something that you can learn. Things that it can't handle fall into a handful of common patterns (like self-referential structs). Once you learn what not to do, you can recognize and avoid the issues even before you write the code.

Re:Zig self hosted compiler is now capable of building itself by bobajeff on Saturday April 16, 2022 @05:36PM (#31056309)
That sounds like good advice. I'll keep that in mind next time I attempt to use Rust on something.
Re:Zig self hosted compiler is now capable of building itself by pyjarrett on Saturday April 16, 2022 @06:44PM (#31056756)
Ada is another option without a GC. I wrote a search tool for large codebases with it (https://github.com/pyjarrett/septum), and the easy and built-in tasking and pinning to CPUs allows you to easily go wide if the problem you're solving supports it.

There's very little allocation since it supports returning VLAs (like strings) from functions via a secondary stack. Its Alire tool does the toolchain install and provides package management, so trying the language out is super easy. I've done a few bindings to things in C with it, which is ridiculously easy.

Re:Zig self hosted compiler is now capable of building itself by throwaway239i3j on Saturday April 16, 2022 @12:07PM (#31053445)
Of the ones you mentioned, Zig is the only one that has explicit memory management.

> Is it worth learning

Languages are easy to pick up once you understand fundamentals. The borrow checker is intuitive if you have an understanding of stack frames, heap/data segment, references, moved types, shared memory.

You then should be asking "Is it worth using?", then evaluate use cases.. pros/cons.. etc.

For CLI, Rust is likely the easiest given it's macros, but if you struggle with the borrow checker then it won't be. You will be fighting the compiler instead of developing something.

Depending what your CLI program is doing, you might want to evaluate what libraries are available, how they handle I/O, and parallelism.

JavaScript has incredibly easy and fast concurrent I/O thanks to libuv and v8.

Re:Zig self hosted compiler is now capable of building itself by travisgriggs on Saturday April 16, 2022 @03:16PM (#31055200)
>> Is it worth learning

> Languages are easy to pick up once you understand fundamentals. The borrow checker is intuitive if you have an understanding of stack frames, heap/data segment, references, moved types, shared memory.

I see this sentiment often. In the last 10 years, I have come up a level in raw C, learned Kotlin, Swift, Python, Elixir/Erlang, and a smattering of JavaScript, all coming from a background that included Fortran and Smalltalk.

My problem with the dialogue is what is meant by “learn.” I have architected, implemented, and maintain different components of our products in all these languages currently. I think that demonstrates I have “learned” these languages, at least at this level of “picked up.” But I can’t write Python the way Brett Canon does. Or Elixir the way Jose Valium does. Or any of their peers. And in that regard I still very much feel I have not “learned”.

I spent a couple days playing with Zig a month or so ago. I became familiar with the way it worked. I could spend another month or so in that phase, and then could probably comfortably accomplish things with it. But I don’t think I’d feel like I’d “learned” it.

It reminds me of my experience learning Norwegian. I lived in Norway for 2 years and did my best to speak as much Norwegian as I could. At six months I could definitely get by. At 13 months, as I embraced the northern dialect, I was beginning to surprise Norwegians that I was from the states. I started dreaming in Norwegian at some point after that. But even at 24 months, able to carry on a fluid conversation, I realized I still could “learn” the language better than I currently knew it.

So I guess, it always seems there needs to be more context, from both the asker and the answerer, when this “should I learn X” discussion is had. Learning is not a merit badge.

Re:Zig self hosted compiler is now capable of building itself by jgillich on Saturday April 16, 2022 @12:36PM (#31053754)
I've found that Go is not elegant enough for me and Rust is too difficult to write (I started using Rust in 2015 and after years of trying I eventually realized Rust doesn't make sense for most apps), so I'm all in on Crystal. Despite not having much prior Ruby experience, I absolutely love the language.
Re:Zig self hosted compiler is now capable of building itself by pizza234 on Saturday April 16, 2022 @01:46PM (#31054355)
Crystal doesn't have built-in support for parallelism, let alone production-grade support. This is a significant lack for a modern language.

For a language that is around 8 years old, this may be a serious problem, since the surrounding ecosystem has been probably written without parallelism in mind, and it may take a very long time to be updated (if ever).

Re:Zig self hosted compiler is now capable of building itself by npn on Saturday April 16, 2022 @02:44PM (#31054927)
> Crystal doesn't have built-in support for parallelism

They do, but it is hidden inside a compiler flag, if you compile your prject with `Dpreview_mt` then it will come with multi-threaded support. This has been an experimental feature for a few year though, and there is not much improvement since it first got introduced.

Personally I don't use crystal for this kind of feature, and it runs stable enough when I use it for some cpu intensive tasks when I rarely need it.

Crystal really shines when you need something that you usually write a python/ruby script to do, especially for tasks that run for hours. Converting some script from ruby to crystal and run it in production mode typically reduce the time consumed to 1/5 or even 1/10 of the original depends on the job. As someone who have to read gigabytes of text files regularly, Crystal is currently the best one for the task.

The compilation time for released binary is something need much improvement though. And I'm not sure if they can even achieve incremental compilation.

Re:Zig self hosted compiler is now capable of building itself by pizza234 on Sunday April 17, 2022 @06:55AM (#31059964)
> hey do, but it is hidden inside a compiler flag, if you compile your prject with `Dpreview_mt` then it will come with multi-threaded support

It depends on the domain. From a production perspective, an flag-gated functionality that has been experimental for two or more years, is not "built-in". Plus, as explained, the ecosystem (I think I've read even the stdlib) doesn't give guarantees about thread safety

For small-scall scripting, then sure, it could be useful - but anything will do. I've evaluated for use at my company, and discarded it, because of the lack of libraries. Sadly, this is a chicken-and-egg situation. I've also evaluated contributing to it, but I won't until multithreading is stable.

Re:Zig self hosted compiler is now capable of building itself by npn on Sunday April 17, 2022 @04:28PM (#31064150)
> I've evaluated for use at my company

Well this might be the problem. In corporate environment you can't afford to be too adventurous.

Personally I solve the "lack of libraries" problem by using more than one language, then connect them via child process call or some persistent storage like database or plain text files.

But it's entirely a different matter when the code need to be used by a lot of people.

Re:Zig self hosted compiler is now capable of building itself by sanxiyn on Saturday April 16, 2022 @03:10PM (#31055156)
I use PyPy for such cases. Is Crystal better than PyPy?
Re:Zig self hosted compiler is now capable of building itself by npn on Saturday April 16, 2022 @03:48PM (#31055501)
I think Crystal is better than Python in term of language design. Unlike Ruby and Python that were way older, crystal is relatively new, so they learned from other languages mistake and try to improve it, result in a more cleaner language.

For the cases mentioned, I think crystal is immensely helpful: - Reading/writing files are easy, usually a single method will give you the result you want. - Working with directories are nice, things like `Dir.mkdir_p`, `Dir.each_child`, `File.exists?`... all existed to make your life easier. - Like ruby, you can invoke shell command easily using backticks - There are some useful libraries to for console app, like `colorize` or `option_parser`. Crystal is a battery included language, so the standard library is filled with useful libraries. - Working with lists and hashmaps is a breeze, since the Enumerable and Iterable modules are filled with useful methods, mostly inspired from ruby land. - Concurrent is built in, so you can trivially write performant IO-bounded tasks like web crawlers.

For a project that made by a handful of people, I just can't praise the dev team enough for making a language this practical.

Re:Zig self hosted compiler is now capable of building itself by zozbot234 on Saturday April 16, 2022 @12:45PM (#31053827)
Modern Rust is much more straightforward than it was in 2015. It's effectively two different languages, albeit maintaining backward compatibility (i.e. code written for Rust 1.0 should still compile today, with proper edition settings).
Re:Zig self hosted compiler is now capable of building itself by bscphil on Sunday April 17, 2022 @02:52AM (#31059046)
Suppose I wanted to try learning Rust again; is there a resource for someone with a lot of (hobbyist) programming experience, and experience with low level languages and memory management (e.g. C), but not complicated low-level languages, like C++?

When I tried to work with Rust a few years ago I found it utterly impenetrable. I just had no idea what the borrow checker was doing, did not understand what the error messages meant, and honestly couldn't even understand the documentation or the tutorials on the subject. Understanding what is happening in C or Zig is pretty easy; in Rust it's always been a nightmare for me. I just really don't grok the "lifetime" concept at all, it feels like I'm trying to learn academic computer science instead of a programming language.

Rust feels to me like a powerful, expressive language for professional programmers at the top of their game. That's a complement for any language. But it comes at the cost of mind-numbing complexity for anyone who's not an expert.

Re:Zig self hosted compiler is now capable of building itself by zozbot234 on Sunday April 17, 2022 @06:05AM (#31059778)
> Suppose I wanted to try learning Rust again; is there a resource for someone with a lot of (hobbyist) programming experience, and experience with low level languages and memory management (e.g. C), but not complicated low-level languages, like C++?

The official Rust book is targeted at novices with some programming experience. There's also Rustlings https://github.com/rust-lang/rustlings for a more practical approach.

> When I tried to work with Rust a few years ago I found it utterly impenetrable. I just had no idea what the borrow checker was doing, did not understand what the error messages meant, and honestly couldn't even understand the documentation or the tutorials on the subject

The compiler diagnostics have improved a lot over time. It's quite possible that some of the examples you have in mind return better error messages.

> in Rust it's always been a nightmare for me. I just really don't grok the "lifetime" concept at all, it feels like I'm trying to learn academic computer science instead of a programming language.

Academic computer science calls lifetimes "regions", which is perhaps a clearer term. It's a fairly clean extension of the notion of scope that you'd also find in languages like C or Zig. It's really not that complex, even though the Rust community sometimes finds it difficult to convey the right intuitions.

Re:Zig self hosted compiler is now capable of building itself by bscphil on Sunday April 17, 2022 @09:39AM (#31060718)
Fair enough, I do need to have a look at the book again, although that was one of the sources I found impossible to understand a few years back. I think there's a temptation to talk about lifetimes in extremely abstract terms under the assumption that the reader already understands and appreciates the abstraction. I, however, was never able to build up an intuition for it, and so tutorials that didn't explain what was happening in detail sailed over my head.
Re:Zig self hosted compiler is now capable of building itself by lijogdfljk on Saturday April 16, 2022 @01:00PM (#31053956)
I second zozbot234's statement about it being far better than it was in those days.

The language team has done a great job rounding rough edges, and this next roadmap is slated for even more polishing. They heavily prioritize dev experience which is why i think people like myself (a GC'd language person historically) use and love Rust so much.

Re:Zig self hosted compiler is now capable of building itself by sanxiyn on Saturday April 16, 2022 @11:56AM (#31053319)
Zig uses manual memory management too (even more manual than Rust), so that's a bit strange question.
Re:Zig self hosted compiler is now capable of building itself by zigger69 on Saturday April 16, 2022 @05:59PM (#31056471)
It's really easy in Zig to be honest. Just put `defer thing.deinit()` in the right scope and you're done. You gain explicitness and know exactly what's going on in your Code. Everything is obvious. That's the reason Zig is so incredible simple and easy to read. Zig also has a GPA that will tell you about memory leaks or anything.
Re:Zig self hosted compiler is now capable of building itself by puffoflogic on Saturday April 16, 2022 @07:04PM (#31056888)
And in rust you just put `` in the right scope and you're done. This is perfectly explicit and you know exactly what's going on in your code. Everything is obvious.
Re:Zig self hosted compiler is now capable of building itself by zigger69 on Sunday April 17, 2022 @08:21AM (#31060352)
You can execute arbitrary code on drop operations by implementing `std::ops::Drop` for a type.
Re:Zig self hosted compiler is now capable of building itself by pornel on Monday April 18, 2022 @10:00PM (#31079078)
A `.deinit()` function could also run some arbitrary code that does weird and unexpected things. The point is that reasonable people don't abuse functions like that — if they do abuse, don't use their code. Neither Rust nor Zig is a sandbox that could stop actively stupid/malicious code.
Re:Zig self hosted compiler is now capable of building itself by dralley on Saturday April 16, 2022 @11:15PM (#31058144)
Rust's ownership rules are no less explicit. The object dies when the owner of the data goes out of scope.
Re:Zig self hosted compiler is now capable of building itself by cercatrova on Saturday April 16, 2022 @12:01PM (#31053363)
Interesting, based on their code samples it looked to me like a GC language since (at least from what I saw) I didn't see anything regarding memory management.
Re:Zig self hosted compiler is now capable of building itself by elcritch on Saturday April 16, 2022 @02:33PM (#31054820)
It’s easy, IMHO, to mistake Zig as a GC’ed language or more broadly as a memory safe systems language. It’s neither but it is a nicer C.
Re:Zig self hosted compiler is now capable of building itself by sanxiyn on Saturday April 16, 2022 @12:05PM (#31053397)
I am not sure what code samples you looked at, but https://ziglearn.org/chapter-2/ should give you an idea.
Re:Zig self hosted compiler is now capable of building itself by pizza234 on Saturday April 16, 2022 @01:48PM (#31054376)
> or are GC languages like Nim or Crystal good enough?

Any programming language is good enough for their own use cases :) It's a matter of understanding which the use cases are.

I'm a big Rust fan, but I nonetheless believe that the use cases for programming languages with manual memory management are comparatively small, in particular, since GC has been improved a lot in the last decade.

For undecided people, I conventionally suggest Golang. Those who at some point need deep control, will recognize it and change accordingly.

Re:Zig self hosted compiler is now capable of building itself by kaba0 on Sunday April 17, 2022 @02:25PM (#31063000)
Why Go? It is quite terrible in expressiveness and if you do commit to a GC you have plenty of better choices. But to each there own, otherwise I agree that systems programming is a niche and a good GC is an overwhelmingly good tradeoff in almost every case.
Re:Zig self hosted compiler is now capable of building itself by zigger69 on Saturday April 16, 2022 @05:43PM (#31056357)
Crystal: compilation speed is just too slow, sadly. Nim and Zig: I'd definitely just go with Zig. It's an extremely simple language, has no macros (but something much better than macros), is explicit, and in the long run it's just going to be worth it much more than Nim.
Re:Zig self hosted compiler is now capable of building itself by mlindner on Saturday April 16, 2022 @11:42AM (#31053192)
Memory has to be managed by something. The more decisions that are made for you in how that happens the less flexibility there is for certain situations.
Re:Zig self hosted compiler is now capable of building itself by cercatrova on Saturday April 16, 2022 @11:48AM (#31053250)
Sure but my use cases would be stuff I'd normally write in TypeScript or Python that already have garbage collection. Like I said I'm not doing embedded programming so I don't have too much of a need to manage memory.

My question could be further constrained then to be, is learning Rust or Zig despite its manual memory management worth it for applications that are normally already garbage collected in their current implementations? Or are languages like Nim and Crystal enough? Does Rust and Zig have other benefits despite manual memory management?

Re:Zig self hosted compiler is now capable of building itself by MarcusE1W on Saturday April 16, 2022 @12:07PM (#31053442)
The way you describe your use case I think you are fine with a language with garbage collection like Nim (which has has a syntax a bit like Python) or Crystal. I would also throw Go in the ring or if you are interested to learn a bit of functional programming then you also could look at Ocaml.

Zig has no garbage collection btw, but makes it easier than C to handle that. Another language without garbage collection that helps a lot to avoid memory issues is Ada (Looks a bit like Pascal). So there are alternatives to Rust.

Re:Zig self hosted compiler is now capable of building itself by adgjlsfhk1 on Saturday April 16, 2022 @12:06PM (#31053416)
imo, most code can do just fine with GC. modern GCs can be relatively low overhead even with guaranteed small pauses (10ms). furthermore, most code that can't handle pauses can be written to not allocate any memory (so GC can be temporarily turned off). as such, the only two places where you need manual allocation are for OS development, and hard real time requirements.
Re:Zig self hosted compiler is now capable of building itself by Comevius on Saturday April 16, 2022 @12:29PM (#31053677)
When tail latency (high-percentile latency) is important GC is not a good choice. Wait-free (threads progress independently) concurrent algorithms also need wait-free memory reclamation with bounded memory usage to be able to guarantee progress.

But most software are throughput-oriented.

Re:Zig self hosted compiler is now capable of building itself by pjmlp on Saturday April 16, 2022 @01:53PM (#31054422)
Additionally, not all GCs are made alike, and languages like D, F#, C#, Nim, Swift, among others, also offer value types and manual memory management, if desired.
Re:Zig self hosted compiler is now capable of building itself by elcritch on Saturday April 16, 2022 @02:44PM (#31054932)
Also Swift and Nim w/ ARC use reference counting, which generally give much better latency and lower memory overhead. Reference counting is part of the reason iOS devices don’t need as much RAM.

Nim’s ARC system also doesn’t use atomic or locks which means it’s runtime overhead is very low. I use it successfully on embedded devices for microsecond timed events with no large tail latencies.

Re:Zig self hosted compiler is now capable of building itself by pjmlp on Saturday April 16, 2022 @03:01PM (#31055081)
Reference counting is a GC algorithm.

I wouldn't buy into much Apple marketing regarding its performance though,

https://github.com/ixy-languages/ixy-languages

It makes sense in the context of tracing GC having been a failure in Objective-C due to its C semantics, while automating Cocoa's retain/release calls was much safer approach. Swift naturally built on top of that due to interoperability with Objective-C frameworks.

Nim has taken other optimizations into consideration, however only in the new ORC implementation.

Still, all of them are much better than managing memory manually.

Re:Zig self hosted compiler is now capable of building itself by elcritch on Saturday April 16, 2022 @03:48PM (#31055500)
> I wouldn't buy into much Apple marketing regarding its performance though,

I wouldn’t make claims on Swifts overall performance, but just it’s memory usage (really Obj-Cs) and particularly for GUI development. Java’s GCs have always been very memory hungry, usually to the tune of 2x. Same with .Net. Though to be fair Go’s and Erlang’s GCs have much better memory footprints. Erlang’s actor model benefits it there.

Agreed, they’re all better than manual memory management.

Re:Zig self hosted compiler is now capable of building itself by kaba0 on Sunday April 17, 2022 @02:22PM (#31062965)
OSs and hard real time can also be written in managed languages — there are many research OS written in managed languages (with a bit of assembly, but you also need it for C as it is not low-level either), like Midori, and there are even hard-real-time JVMs used in military settings like jamaicavm.
Re:Zig self hosted compiler is now capable of building itself by mlindner on Saturday April 16, 2022 @01:09PM (#31054032)
Rust's memory management is "manual" but it feels automatic for most uses.
Re:Zig self hosted compiler is now capable of building itself by fyzix on Saturday April 16, 2022 @04:49PM (#31055975)
Nim strikes a great balance. No need for a low level language for cli and general software. I liked crystal but the lack of support on windows and lackluster dev experience made me stick to Nim.

Nim also can double as a web language by transpiling to JS.

Re:Zig self hosted compiler is now capable of building itself by arc776 on Sunday April 17, 2022 @09:15AM (#31060602)
Nim's super power is being ridiculously productive (at least for me). Hack stuff out like a Python script, yet it runs really fast and is a tiny self contained executable, so you can just use it as is and move on to the next task. If you want manual memory management, that's easy too. Want to use a C/C++ library? No worries you have ABI compatibility. As you mention compiling to JS lets you use it as a web language and share code and types between front and back end.

Then you can automate code generation with the sublime macros, which are just standard Nim code to create Nim code. No new syntax or special rules required - any Nim code can be run at compile time or run time, so you can use standard/3rd party libraries at compile time to write macros and give the user a slick syntax whilst removing boilerplate.

I really miss languages without straight forward metaprogramming after using Nim. It's something that multiplies the power of a language, rather than just adds to it.

Re:Zig self hosted compiler is now capable of building itself by exikyut on Sunday April 17, 2022 @07:35AM (#31060144)
I haven't properly looked into Nim yet, and the sibling comments here make for some interesting signalling.
Re:Zig self hosted compiler is now capable of building itself by quazar on Sunday April 17, 2022 @04:22AM (#31059412)
I would not recommend Nim.
Re:Zig self hosted compiler is now capable of building itself by throwamon on Sunday April 17, 2022 @07:52AM (#31060224)
Thank you so much for such a profoundly insightful comment. I'm now even thinking of changing professions thanks to it.
Re:Zig self hosted compiler is now capable of building itself by planetis on Sunday April 17, 2022 @05:35AM (#31059643)
I like Nim.
Re:Zig self hosted compiler is now capable of building itself by cxr on Friday April 22, 2022 @05:57AM (#31119854)
> just interested in command line apps and their speed as compared to, say, TypeScript

There are no fast languages, only fast language implementations.

NodeJS/V8 is pretty fast (even faster than you probably think)—particularly if you're already doing things like making the sort of compromises where you limit yourself to writing only programs that can be expressed under the TypeScript regime. It's usually the case that it's not the NodeJS runtime that is the problem but rather the NodeJS programming style that is the source of the discomfort with "speed" that you will have experienced.

Re:Zig self hosted compiler is now capable of building itself by Siira on Sunday April 17, 2022 @02:05AM (#31058872)
I haven’t tried Zig yet, but I liked Common Lisp better than Go and Rust for fast CLI apps/scripts. You need to dump an image with all your deps already loaded, and then you can run small scripts with instant compilation very fast. It’s an ergonomic language with good IDE support in emacs. There are some rough edges around (inconsistent API design, the package manager not using HTTPS, …), but tolerable.
Re:Zig self hosted compiler is now capable of building itself by cercatrova on Sunday April 17, 2022 @03:58AM (#31059308)
Common Lisp doesn't offer features like sum types right? I am under the impression that it is a dynamically typed language like most Lisps, but I could be wrong.
Re:Zig self hosted compiler is now capable of building itself by adenozine on Monday April 18, 2022 @11:38AM (#31072149)
You might peek at Coalton.

https://coalton-lang.github.io/reference/

I don’t think it has sum types, but it offers a rather sophisticated and very functionally oriented type system that compiles back to SBCL. It looks neat, haven’t found time to play yet…

Re:Zig self hosted compiler is now capable of building itself by Siira on Sunday April 17, 2022 @11:53PM (#31067222)
It has optional typing, but as it’s fast without it, I haven’t dug into them. I don’t know about a union type though.
Re:Zig self hosted compiler is now capable of building itself by nicoburns on Saturday April 16, 2022 @12:29PM (#31053678)
If you're doing things like command-line apps you'll probably find Rust much easier to work with than Zig. You can write high-level code that looks basically like TypeScript in Rust, whereas Zig is more manual. Nim and Crystal are easier from a language perspective, but they have much smaller ecosystems.
Re:Zig self hosted compiler is now capable of building itself by Tozen on Saturday April 16, 2022 @05:06PM (#31056108)
Besides Rust and Zig, you might want to check out Vlang and Odin, who are in the same category.
Re:Zig self hosted compiler is now capable of building itself by cercatrova on Saturday April 16, 2022 @05:16PM (#31056171)
I remember reading a lot of controversy about V back when I first heard about it so I decided not to look into it further [0], but I'll take a look again. Odin looks interesting, Pony does as well.

[0] https://news.ycombinator.com/item?id=25511556

Re:Zig self hosted compiler is now capable of building itself by Tozen on Sunday April 17, 2022 @12:50PM (#31062218)
A lot of the so-called Vlang controversy appears to have been disguised allegiance and competition between the newer languages. Looks more like various people defending their interests. Languages like Odin, Zig, Nim, Crystal are far older than Vlang. When Vlang came along and got a lot of sudden popularity and funding, looks like various competitors sought to bash it and hoped it would disappear.

In addition, such detractors were acting like a brand new programming language would be a finished polished product from day 1, when that was not the case for their far older languages. For instance, Odin and Crystal are older than Vlang, but has been surpassed by it in various respects.

And don't get me wrong, I like Odin. That's because Odin is among the newer breed of languages that have continued the trend in which Go started of non class-based OOP and more generalized OO, that are contenders to be alternatives to C/C++ (like Zig).

In the case of Vlang, it has clearly been developing rapidly and consistently, and continually gaining in popularity. Simply looking at their releases (and release schedule) along with their documentation (which various newer contenders are lacking in even that), will show a lot of the controversy is without merit or distortions of language development reality.

https://github.com/vlang/v/releases https://github.com/vlang/v/blob/master/doc/docs.md https://modules.vlang.io/

Re:Zig self hosted compiler is now capable of building itself by kaba0 on Sunday April 17, 2022 @02:29PM (#31063030)
It doesn’t help that plenty of claims on the V website was simply ridiculous, like transpiling C to V and making it memory safe (or some insane compile speed claim transpiling Doom, if I remember well?). Also, memory safe without a runtime and without a rust-like borrow-checker.. these are simply impossible lies. Not sure about its current state, hopefully these are all removed and the sane claims are in progress.
Re:Zig self hosted compiler is now capable of building itself by Tozen on Sunday April 17, 2022 @02:46PM (#31063172)
It is better to actually use the language, particularly as it is presently, versus refer to old disputable controversies from years ago. There are no false claims on their website (in my opinion), though of course there will be things people can dispute and argue about, as there is with all developing programming languages.

If a person does their research, then they would have clarity on the subjects. This is partly why I think it is better to refer people to the website or advise them to do their own evaluation, as oppose to reference critics or 3rd party websites who may have hidden motives and are advocates for a competing language. I think the competition between the newer languages has come to that point.

Re:Zig self hosted compiler is now capable of building itself by super_flanker on Sunday April 17, 2022 @09:20PM (#31066292)
> There are no false claims on their website

Are you sure about this? Let's look at their first feature, "No null". Ironically every vlang project including compiler itself is full of `isnil`[0] check.

This is just trailer for their lies; once start digging you'd find misrepresentation in every major features they advertise.

0: https://github.com/vlang/v/search?q=isnil

Re:Zig self hosted compiler is now capable of building itself by kaba0 on Sunday April 17, 2022 @06:33PM (#31065140)
Then could you please tell me the actual memory model of the language? Because that is the numero uno thing I want to know about a language, yet I constantly read contradicting thing on vlang’s model. (Is it boehm gc?)
Re:Zig self hosted compiler is now capable of building itself by Tozen on Sunday April 17, 2022 @09:21PM (#31066299)
Vlang has multiple methods of optional memory management. This should not be so hard to grasp, as this is the case for other languages too. Take Nim, for example. It has several: gc:refc, gc:markAndSweep, gc:boehm, gc:go, gc:arc, etc...

Vlang has both the options of Autofree and GC, or you can do it manually. As the language is still developing (like other languages such as Crystal, Odin, and Zig), users should know these memory management options are experimental and still being refined.

Re:Zig self hosted compiler is now capable of building itself by phendrenad2 on Saturday April 16, 2022 @02:06PM (#31054560)
I recommend C. Once you get the hang of it, it's as fast as writing Rust code (and you don't have to think about borrow checks).
Re:Zig self hosted compiler is now capable of building itself by cercatrova on Saturday April 16, 2022 @02:51PM (#31054997)
Yeah, I sure love debugging segfaults. I've used C before and it was cool to learn but I haven't used it since.
Re:Zig self hosted compiler is now capable of building itself by phendrenad2 on Saturday April 16, 2022 @03:16PM (#31055212)
Once you've used C enough, you get the skill to avoid writing segfaults, and when a segfault happens, they're a lot easier to debug.

However, since you're just interested in writing a fast command-line app, what about the JVM or .NET? Those have a startup time issue, but once they're running they're very fast, less than an order of magnitude slower than C/Rust/Zig/etc.

Re:Zig self hosted compiler is now capable of building itself by kaba0 on Sunday April 17, 2022 @02:32PM (#31063053)
My biggest gripe with C is not even the manual memory management, since with Valgrind and friends they are not that hard to debug. But how do you solve such a basic issue like having a vector-like data type for different types? Its “macro” system is just a disgusting hack, I could just as well write a sed script instead. And the other option is runtime-overhead or copy-pasting code..
Re:Zig self hosted compiler is now capable of building itself by phendrenad2 on Monday April 18, 2022 @07:37PM (#31078109)
> vector-like data type for different types

When using C, if you want something from a higher-level language, usually you'd just do what that language's runtime does internally. So for a vector of heterogeneous objects, you could do a linked-list of pointers to the data objects. Something like:

    struct VecItm { struct VecItm next; void *data; size_t data_len; char objTypeId; };
Is it more work? Yes. But at this point I would stop and consider if I really need a heterogeneous collection. Do we really need to store a list of objects with arbitrary sizes? What if we have 3 types of objects, in 3 arrays, and we store index into those arrays?

    struct Foo { unsigned byte x; };
    struct Bar { unsigned word x; };
    struct Baz { unsigned long x; };

    struct Foo foos[256];
    struct Bar bars[256];
    struct Baz bazzes[256];

    // objTypeId: 0 = foo, 1 = bar, 2 = baz
    struct VecItm { struct VecItm next; unsigned int idx; char objTypeId; };
Or what if we can do something even better? What if Foo, Bar, and Baz all have a max size that isn't too wildly different? Can we store them all in an array directly?

    // objTypeId: 0 = foo (x contains 8 bits), 1 = bar (x contains 16 bits), 2 = baz (x contains 32 bits)
    struct VecItm { unsigned long x; char objTypeId; };
    struct VecItm vecItms[256];
> Its “macro” system is just a disgusting hack

It's really not that bad. It can result in spaghetti-code where your macros are using other macros and they're spread all over a header file. But if you use them surgically, only when needed, they don't cause much trouble.

> I could just as well write a sed script

The benefit of C macros over sed is if you use some language-aware tooling like an IDE (such as CLion), it will syntax-check and type-check your macros.

Re:Zig self hosted compiler is now capable of building itself by kaba0 on Tuesday April 19, 2022 @04:29AM (#31080811)
I don’t want a heterogeneous “array”, I want a generic one. Your first example is the overhead I talked about, most high-level languages don’t do this at all. Pointer chasing is really pricey on this level.

Your second example misses the auto-growing part. Sure, I want an array, but if that becomes too small, I automatically want to realloc the underlying data to a larger array. And I want to use it for Foo, for int and for any sized objects, generally.

C++ can create the proper zero-overhead abstraction over it by generating code for each type I use it for, C to my knowledge can’t do so without copy-pasting code or doing things with runtime overhead, resulting in (often) much slower code.

Re:Zig self hosted compiler is now capable of building itself by phendrenad2 on Tuesday April 19, 2022 @09:16AM (#31082661)
In that case copy-pasting is the way, and macros make the copy-pasting much less onerous. This could be messy if there are a lot of types, but I have yet to see a program where having auto-growing vectors of many different types was absolutely essential.