r/ProgrammingLanguages • u/ebol4anthr4x • 3d ago
Go with manual memory management / no garbage collector?
Go is my ideal programming language, except for there being no ergonomic way to work without the garbage collector (to my knowledge). Is there a language that has the simplicity and elegance of Go, but without a garbage collector?
Some big pros for Go in no particular order:
- dead simple cross-compilation
- first-class support for unit testing
- quick builds
- first-class support for debugging and profiling
- goroutines and channels are extremely ergonomic primitives for concurrency
A con for Go:
- the runtime is pretty hefty and results in large binaries.
Zig is the closest thing I have found, though I do find the build system a little complex. Profiling is do-able, though not great; the best way I've found is to use Tracy.
I am not a fan of Rust's syntax and am not able to develop at the speed of thought like I can with Go. This is definitely a skill issue but Rust just doesn't feel very ergonomic to me.
Odin is a strong contender. For profiling, Tracy seems to be the best option again, which isn't ideal. An allocator stored in context is exactly what I wish Go had. The syntax leaves something to be desired for me.
I need to look more into C3.
Any other languages I've missed?
18
u/ProgrammingLanguager 3d ago
What are you looking for in a language, exactly? Why do you want full memory control?
Zig and Odin are, generally speaking, languages made for someone who has spent years writing C or C++. Zig, which is the language I have more experience with, is indeed simple and very flexible - much of its modernity derives straightforwardly from an intuitive extension of a const context to metaprogramming. Any language with significant metaprogramming faculties (especially, arbitrary compile time code execution) is going to get slow in larger projects utilizing them - although the tradeoff Zig takes for its implementation generally results in far better compilation times than rust's proc-macros. LLVM is a constant across both.
To make a wider point though - there is a reason the systems languages most often adopted by higher level programmers are often as complex as C++ and rust. Getting close to emulating the power of a GC (with its power to arbitrary derail execution at any point, etc) at compile time and/or with RTS-friendly dynamics is a hard problem! In some cases, it is better left to the user, but once your project gets large enough the burden of managing this will prevent you from "speed of thought" programming if you lack experience in the area (apologies if I'm making an undue assumption on that).
For simplicity and speed of thought writing, where you don't /need/ full manual memory management, languages like Nim or Swift, which borrow only the simplest of rust's tricks (move semantics and optimisations) and combine them with nicely abstracted reference counting via ARC, might be the better choice. You'll get good memory usage, tiny binaries, and predictable performance characteristics, while the source code can remain at a a level of abstraction and simplicity comparable to Go. This also applies to third party high performance/low footprint/embedded focused implementations of other, simple GC languages
21
u/SilvernClaws 3d ago edited 3d ago
Odin is pretty much the closest you'll get to Go syntax wise.
V is also pretty close in many aspects and has manual memory management in theory. Unfortunately the language is basically built around lying about how it manages memory and a bunch of other issues, so your mileage may vary.
C3 and Zig are both great options, but both not exactly similar to Go. It takes a while for Zig's build system to click, but then it gets much better. It's not declarative, you're basically building a graph of dependencies and steps programatically. Which other build tools also do, just not as explicitly.
11
u/vmcrash 3d ago
What exactly do you want to improve by removing the GC? Is Go too slow for your project? Do you notice some delays caused by the GC?
5
u/potzko2552 3d ago
You are looking for Odin i think. But id give rust a try first
16
u/coderemover 3d ago edited 3d ago
The language you’re looking for is Rust, don’t judge it by the syntax. Syntax is a very subjective thing and don’t get fooled by the number of keywords. Using a dedicated keyword for e.g. controlling visibility is not any more complex than using capital / small letters or underscores.
2
u/GardenerAether 2d ago
i remember thinking that memory management could be fully automated without the need for a garbage collector using a continuation passing style wrapper and linear types. james faure seems to agree with this so its nice to know im not completely crazy lmao. im not entirely sure of any existing implementations myself though, haha '
3
u/L8_4_Dinner (Ⓧ Ecstasy/XVM) 2d ago
Blender is my ideal food blending tool, except for there being no ergonomic way to work without the noise of the motor (to my knowledge). Is there a kitchen tool that has the simplicity and elegance of a blender, but without any noise?
The issue here is you're not thinking of the design as a whole, e.g. why did Go include a garbage collector as part of its design?
The GC is not a "feature" of Go. It's an intrinsic building block. A lot of the things that are "simple" in Go can't exist without a GC.
If you have alternative ideas, try writing the code by hand in the Go-like language that you're thinking about, and then write by hand the (C/assembly/whatever) code that it will produce (or could produce) out of its compiler back end. Reason out to yourself how that produced code could have been produced from the inputs. Repeat the exercise until you're happy with the source code and with the back end output. Then write down the specs and build the compiler. The result will be so popular that you'll have to beat off the inevitable crazy fans with a stick.
Good luck!
3
u/tandycake 3d ago
Another choice would be Jai.
Odin and C3 are great options though.
However, all 3 of these are lacking in a good desktop GUI framework. If you're more into games, CLI apps, and/or immediate-mode GUIs, then no problem.
1
u/Glittering_Gur5701 3d ago
C with something like libtask
1
u/chibuku_chauya 2d ago
Yeah, you missed C.
1
u/matthieum 2d ago
It's not clear to me how low-level you wish to go. Your mention that being able to customize Allocator is a strong point for Odin doesn't match any of the points in the pros/cons on Go, for example.
It's also unclear if you're looking for a language to put code in production today -- Go & Rust are mature -- or you're working towards an ideal -- Odin & Zig are not mature.
It's also unclear how much memory safety matters to you. Rust is memory safe, Go nearly is, but Odin & Zig are definitely not.
If you're open to less mature implementations, which will affect the quality of the debugging experience, then you may be interested in exploring the "Rust alternatives". A lot of people have been working on Rust without borrow-checking, or Rust with more flexible borrow-checking, and there may be something there that tickles your fancy.
For Rust without borrow-checking, Hylo offers an interesting paradigm I think. No more lifetimes/groups at all! Woot!
Otherwise, on the Rust with more flexible borrow-checking, and even less mature than Hylo, you may want to check Valen (which aims at excellent Rust FFI) or Zeta (which was announced ~2 months ago).
1
u/five5years 1d ago
Weird that you say Odin's syntax "leaves something to be desired". It is about as close to Go syntax and your described tastes as possible.
1
u/ProgrammingLanguager 1d ago
To give a very straightforward answer as opposed to my long comment: Hare (harelang.org) is in a lot of ways exactly what you've described
1
u/Rigamortus2005 3d ago
Odin
1
u/kanareyka 3d ago
Hare might fit