HACKER Q&A
📣 apoorvagk

Is there a simple and minimal language like C but without its footguns?


I want to pick a new programming language that is simple and minimal like C but does not have the type of footguns C has (segmentation faults, double-free issues, etc.)

C++, Java, Rust are far from minimal. Go feels minimal but it too has a lot of features compared to C and it has a garbage collector too.

Here are some things I am looking for:

* Compiles down to machine code.

* Does not have the footguns of C.

* Simple like C.

* Implementations available for all major OSes, at least, Linux, Mac, Windows, *BSDs.

After extensive search I got the feeling that it is difficult to find such a language. If I am willing to let go "simple like C", then it provides a lot of options like Rust, Nim, and all. Just asking here to see if I missed something during my search.


  👤 meretext Accepted Answer ✓
Take a look at Zig (ziglang.org). Not sure it meets all of your requirements, but looks like it might. I haven't worked with it yet, but it's on my radar, as is FORTH, for the simplicity aspect you mention. And I should mention Tcl, but that's a scripting language so not what you asked for, but just in case, no, Tcl isn't 'dead', it's in most of the Cisco and other IT infrastructure equipment that's getting this website to you, it runs most of Flightaware's infrastructure, and is in all sorts of places quietly doing its job; it's how SQLite was started (as a Tcl extension, and Tcl is still a first class citizen w/r to SQLite). The creator of Redis wrote a good article on Tcl (which Redis was started in). Oops. This became a Tcl sales comment. Sorry! :)

http://antirez.com/articoli/tclmisunderstood.html


👤 krapp
> Does not have the footguns of C.

> Simple like C.

You have to pick one, or give in on both and find a happy medium between the two. The way you get safety in a language is by abstracting over the simplicity.

I personally would suggest biting the bullet and going with C++, you can stick to a reasonably sane subset of the language but it definitely won't be C.


👤 cpach
Seems like Go might be able to fit your bill. AFAICT the designers of Go has gone out of their way to avoid adding cruft to the language.

Yes it has GC. What is it that you want to build though? Will GC be in the way? If so, I would consider Rust instead.

C is simple, true – but in many cases it seems like that fact pushes the complexity up to higher layers instead.

C still has it’s place in embedded. And our best kernels are currently written in C. Outside of those domains I don’t see much reasons to start a greenfield project in C.


👤 e12e
Pascal, modula, zig?

Zig sounds mostly like what you want, though: https://ziglang.org/

Possibly a subset of D could work, too:

https://dlang.org/blog/2018/06/11/dasbetterc-converting-make...

But likely the D language will be too big?


👤 hsn915
There are two publicly available contenders: Odin and Zig.

Each one has its own way in which it deviates from C in a way that some people might not like. Odin is probably a lot closer to C than Zig. Zig tries to bring some of the more recent ideas into the low level programming space (compile time null checking, builtin "T or error" types, etc.

https://odin-lang.org/

https://ziglang.org/

Of course there are some other contenders, but having looked at them, either they are not even serious enough, or they deviate from C way too much, with GC, closures, etc.


👤 ksec
Pascal, Zig, V and possibly Crystal. Or Das C although arguably that is a subset of D.

V isn't anywhere near finish. The closest thing should be Zig. But that is far from finish as well.

Crystal is more like Go than C. But I mean someone wrote a OS [1] using Crystal in her spare time.

Or just plan old Pascal.

I mean if you are looking for simplicity like C and compiled to machine code you virtually ruled out 95% of all programming languages. Other languages like Lua is simple. But certainly dont fit the bill.

[1] https://github.com/ffwff/lilith


👤 theonemind
You don't seem to like garbage collectors, or manual memory management (with which you'll get segfaults and double-free issues) or complexity (where the intermediate ground between manual and automatic memory management comes in, with compiler hints, etc.)

This doesn't seem like a satisfiable set of constraints. I'd recommend removing "not garbage collected" from the constraints, as automatic memory management mostly got introduced to reduce footguns.


👤 mikewarot
Free Pascal is more elegant, and has runtimes everywhere. Normally you can avoid pointers, however if you need to use them, the syntax makes it easy to see what you're doing.

Strings are memory managed for you, and can even include nulls.

See the Free Pascal project[1], and the Lazarus IDE[2]

1 - https://www.freepascal.org/

2 - https://www.lazarus-ide.org/


👤 melezhik
No one has mentioned it here, but maybe Pony?

👤 goodpoint
Nim is what you are looking for.

👤 bsenftner
Yes, it is called C with Experience. Write code like a fantasy scientist: track what you're doing, document what works and what does not, and maintain that reference-sheet across multiple projects. Like a scientist is supposed to work. Your foot guns will vanish.

👤 thuccess129
GNU's GCC has added Ada and NetBSD has that in a package. Space Technology uses Ada and Forth.

👤 sushsjsuauahab
"Java is far from minimal"

My web servers run with like 300MB of RAM and work fine on t2.nano serving thousands of users??

And also Java gives you full access to primitive types if you don't like OOP


👤 alex14fr
Just use C and be careful when you use pointers or arrays.

👤 _448

👤 sergiotapia
Nim!

👤 phendrenad2
I encourage you to reconsider the idea that C has footguns. Having written quite a lot of C, I no longer fear the rougher edges of C. Avoiding them takes time to get used to, but they're the price you pay for the ultimate simplicity of C.

👤 foobarbaz33
C with valgrind can be relatively safe. Sort of enforcing the safety outside of the language and into the surrounding tooling.

And sticking to some common heuristics goes a long way towards safety. Some people think it's impossible to write safe C, but you can.

So the answer is C.


👤 nicolaslem
Depending on your definition of machine code, Lua may fit the bill.

👤 arduinomancer
What about just picking a subset of C++?

C + smart pointers and container types?


👤 notmuffin
I personally love nim and zig for these reason

👤 enduku
red-lang isn't bad. Golang. Terra. Nim. Forth. Pascal. Zig. Rust.

👤 dv_dt
Forth?

👤 DubDouble
Footguns!? LOL