r/ProgrammingLanguages • • 4h 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?

6 Upvotes

23 comments sorted by

8

u/SilvernClaws 4h ago edited 4h 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.

6

u/vmcrash 4h 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?

-1

u/coderemover 2h ago

I don't know what the OP's problem is, but Go GC has some noticeable memory footprint. This is a common problem to all GC languages (Java is another one). It's very easy to beat Go programs on memory at least 3x with Rust.

0

u/ProgrammingLanguager 1h ago

Memory is plentiful in most applications. The JVM is not designed for embedded devices, but for client devices and especially servers.The performance the large amount of memory used affords it is generally the right trade off. (this is coming from someone who, for experience reasons, would choose rust over java for basically all applications!)

3

u/coderemover 1h ago

That was 10 years ago. Today memory is expensive. The memory that otherwise is wasted by GC can be used for e.g. caching which improves performance.

3

u/ProgrammingLanguager 1h 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

8

u/coderemover 4h ago edited 4h 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.

7

u/vmcrash 4h ago

Using a dedicated keyword for controlling visibility is even better, because changing the visibility means to just perform one change at one place.

6

u/coderemover 4h ago

Exactly.

The OP also needs to bear in mind that GC actually brings a lot of ergonomy to languages like Java or Go, so they don't really want a Go with no GC. They really want a language where GC was replaced with something else that is at least trying to deliver similar level of experience. From all the languages I know of, Rust is the closest to that goal, and C++ is the second best.
But this comes with some complexity tax, there is no free lunch. The alternative is error prone manual memory management like C or Zig; but that is shifting complexity from the language to the developer.

4

u/moltonel 3h ago

Rust ticks a lot of OP's boxes, some better than Go, but it is not simple and does not build quickly. 

1

u/coderemover 3h ago edited 2h ago

It's as simple as one can get in a language without GC.

And many things allow the programs to be simpler and more ergonomic than Go - e.g. sum types (enums), derive macros, ? operator for error propagation, or RAII (you don't even need defer, things get closed automatically and it is much harder to forget).

As for building quickly - neither Go is as fast at building as it was 10 years ago, nor Rust is as slow as it was 10 years ago, and many of those Rust is slow to build are just repeated perceptions from v1.0. There are a few things in Rust you can do that can kill your build times (overusing macros or generics), but the equivalents don't exist in Go.

Some of my Rust projects which are 500k+ lines of code in 200+ libraries build in 10 seconds on my laptop, cold. That's quite impressive speed of building, comparable to other modern languages.

2

u/nzconstructionlawyer 2h ago

It is not. There are numerous examples of far simpler languages without GC.

The additional features you list add complexity to the language and to programs. They make snippets of code look simpler and therefore you think they make programs simpler but programs are not their source code; the map is not the territory.

RAII for example adds enormous semantic complexity to the language (all the complexity around Drop).

The ? operator needs to be unwrapped in your head into the same control flow but it's implicit.

Macros are extremely complex.

Rust compile times are atrocious. In practice they're far worse than they were a few years ago because the ecosystem has exploded in complexity.

1

u/moltonel 1h ago

I love Rust, I generally choose it over Go, and I know where you're coming from, but

It's as simple as one can get in a language without GC.

is plainly false. Odin, Zig, C3, Nim, and many others are counter-examples. Rust might as simple as it gets considering all its goals, but there's a lot more to it than no GC and safety. Even within its comprehensive goals, Rust is now less simple than it could be. It worked fine before .async and ?, the macros systems would be designed very differently if they were added today, etc. Rust is very well designed, with all features justified and working in harmony, it's elegant and surprisingly easy to use. But it's still hard to recommend to somebody looking for a simple language.

Concerning build speed, yes the complaints are overblown, Rust has sped up while Go has slowed down, and devs should worry less about build speed (and about syntax, sigh). But there's still quite a gap between Go and Rust on that criteria, OP's argument is fair.

Some of my Rust projects which are 500k+ lines of code in 200+ libraries build in 10 seconds on my laptop, cold.

Lucky you. My 6K lines, 58 deps Rust project builds in 19s, about as long as my 1M line Go project. YMMV, don't trust anecdotes.

1

u/coderemover 1h ago

Zig moves the burden of memory management on the developer, like C. So it’s not comparable at all. Its simplicity comes from the fact of not having a GC replacement.

1

u/moltonel 50m ago

You absolutely can compare languages with different memory management strategies, many people do, especially on this sub. OP didn't ask for automatic memory management, they arguably did the opposite, and seem open to different feature compromises.

0

u/nzconstructionlawyer 2h ago

Rust is absolutely nothing like Go. It has extremely bad compile times, it's massively overcomplicated and it has a bad culture and so a bad ecosystem of packages.

1

u/coderemover 1h ago edited 1h ago

Compiling 100k lines per second is not “extremely bad compile times”. Go will always win at loc/s metric though, because of all that boilerplate that inflates the number of lines for the same functionality.

Comparing complexity makes no sense. Obviously an excavator is more complex than a shovel.

And you dare to speak about overcomplicating things when your language of choice did this atrocity:
https://mcyoung.xyz/2024/12/16/rangefuncs/
Seriously?

Every feature that Go steals from Rust turns out to be either limited (generics) or more complex (iterators). Can’t wait until Go team steals enums (there are plans).

0

u/5nord 2h ago

When the keyword is optional, the language increases your cognitive load. In C++ for example default is public for global symbols, but private for classes. Every language has slightly different defaults.

Go is very explicit and enforces discipline as a language design choice. Go has a very different philosophy than Rust.

3

u/potzko2552 3h ago

You are looking for Odin i think. But id give rust a try first

2

u/tandycake 4h 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 1h ago

C with something like libtask

1

u/kanareyka 12m ago

Hare might fit