Live data from Hacker News

Understanding the Odin programming language

odinbook.com

51–60 of 163 posts

Re: Understanding the Odin programming language

#51

[flagged]

You're thinking too much along the lines of "language x can or can't do y". See: Turing complete.

Ultimately it all boils down to machine code. Programming languages avoid the tediousness of programming in that, express program flow in a more concise / elegant way, and manage complexity for the project at hand.

How that's done, is a matter of taste, and how well the tools suit the job. Existing runtime environments (say, browsers with highly-optimized JS engine) are important here.

> Show me what you made with this language - it will help me better understand the use case(s) and trade-offs.

That's the spirit!

Re: Understanding the Odin programming language

#52
post #16

Earlier quoted context omitted.

Did you try Swift? Its interoperability with C (and even C++) is great IMHO.

It's GC

Pedantically I’ll say it’s reference counted, and someone else will say that’s still a form of GC and I’ll just save us the mini-thread.

Reference counting has deterministic timing, you can run a deconstructor without registering objects for deletion and running any known finalizers (what you need to do in all GC langs I’m aware of.)

Re: Understanding the Odin programming language

#54
post #48

I wonder if this will help them get a wikipedia page. (not sure whether this comment is a joke or serious...)

It would, but the book has existed for a while now, which is a good thing for anyone looking to learn Odin. The author, Karl, has had time to polish and update the text. He has his own Discord and is also available in the Odin Discord and makes helpful posts there as well.

Re: Understanding the Odin programming language

#55

Earlier quoted context omitted.

Out of curiosity: In your opinion, could a minimal system to develop in Odin be squeezed into a device like the one(s) you targeted? That's assuming maybe some tweaks to the toolset, doing without some niceties, but not cutting core features out of the language. Asking 'cause I have a passing interest in programming languages that allow for native development on really small implementations (think sub-1MB on bare met…

Odin is not like JS or something where you'd need a VM or transpilation process to target an embedded system. It's just C with nicer syntax and modern data structures, there's no "squeezing" required. You just compile for the target you want to run on. Here's a UI framework, if you scroll down you'll see it on a Raspi Pico: https://github.com/MadlyFX/Ansuz

I think you missed "native development". I'll rephrase:

Could a toolset to develop in Odin be made to run on (not just target) an STM32 microcontroller like you used?

> It's just C with nicer syntax and modern data structures

That suggests the above would (in theory) be possible for any device that's roughly in the same class as "can run a C compiler". Correct?

Re: Understanding the Odin programming language

#57
post #3

Having fun with this. Never bought into rust (have studied, have a (mostly AI-generated app in rust). Wrote some Zig but Odin is even less overhead for me. I first loved Zigs built-in build system but having tried to wrap/use C libraries from both, I must say I prefer Odin. Wrapping some sqlite 3 API’s for my first little Odin program - just because I need so little of the API that it seems easier this way - and spea…

If the major obstacle for adopting Rust is C interop, you may find my project CO2[1] appealing. It helps you to define C crates, `#include` C headers, while exporting a Rust API with Rust types in your crate boundary.

[1]: https://github.com/hkalbasi/co2

Re: Understanding the Odin programming language

#58

Earlier quoted context omitted.

I think those guys both hate C++ so much that they want to dismiss everything about it instead of using all the features that work for them like most people. My interpretation is that games want to allocate large pools of resources, like GPU buffers, cpu memory, etc, and reuse that memory over and over. Ie: Reinitialize it. They might say this, but there isn't a good technical rationalization here since anyone can cr…

Hate C++? They both use(d) it...

I didn't say they don't know it.

Re: Understanding the Odin programming language

#59
post #27

Earlier quoted context omitted.

Games ? Many have talked about it, but many also make their games work inside of Unity and so on, so, depends on the project. My angle is systems programming, and there, it absolutely matter. If you are performance sensitive, then you try to avoid crossing the user-space -> kernel boundary more than you have to. Eg, ask for lots of memory, manage with arenas. Interestingly Odin and Zig both lean into this heavily. Ru…

> My angle is systems programming, and there, it absolutely matter. If you are performance sensitive, then you try to avoid crossing the user-space -> kernel boundary more than you have to. Eg, ask for lots of memory, manage with arenas. This gives the misleading impression that ordinary memory allocators are materially different from arena allocators. They aren't. Both types of allocators first ask for a big block o…

Look up a few comments, I do systems programming. I am aware, you are barking up the wrong tree, friend.

That said. You asked about C, which I use for my job. Most every large C code base end up abandoning the stdlib (such as it is) and inventing their own. Since they do, we aren’t as hurt by abandoning it as you would be in e.g. Rust - the rust stdlib is useful, the C stdlib is.. not great.

Once you abandon the stdlib, a likely first stop is writing your own routines for allocating and freeing memory. There are different approaches here, from glib’s or sqlite’s alloc and free routines to people writing an allocator abstraction (basically a struct with a vtable for allocating/realloc/free) and when you build your own “stdlib” around this abstraction, you are fine.

As for why you may want arenas vs other allocation strategies, that again deals with how often you are comfortable going across the user-space/kernel boundary and how clever you can be with your allocations or how much internal fragmentation you can accept.

As with all other stuff, it depends. But arenas are often great when you can assert that a series of objects share the same lifetime (death time, rather). In these cases, your amortize the syscall cost, have nearly no additional work to manage the memory (contrast to e.g. the complexity of jemalloc) and can free a series of objects in constant time.

Re: Understanding the Odin programming language

#60

Earlier quoted context omitted.

Casey Muratori and Jon Blow have pushed this concept frequently. They largely don't deeply elaborate, which is sad because I am a professional game developer who is interested in precisely presented knowledge so I can apply it to my work. My interpretation is that games want to allocate large pools of resources, like GPU buffers, cpu memory, etc, and reuse that memory over and over. Ie: Reinitialize it. In my experie…

Casey spends a lot of effort on what he considers an anti-pattern where you're making a huge number of separate objects. I think a lot of this comes from Java, a language where all the user defined types actually are obliged to be heap allocations. If I make a Goose type, and I say I want a Goose, Java will allocate space on the heap for the Goose and put my Goose there, that's really how Java works. If I make a grow…

Java doesn't mandate the usage of a heap - it can in certain cases avoid doing so and allocate on the stack (escape analysis).

Besides, as mentioned java's allocations are much closer to something like using an arena in a low-level language, then a "slow" malloc. It uses thread-local allocation buffers, where you have a large buffer with a pointer pointing to the start of the free region. Allocation is just a pointer bump, not even needing synchronization since it is per a single thread. As it gets full, the GC moves out still alive objects in the background and resets the buffer.

This is pretty much the most efficient one can be after per-object type arenas and simply not allocating.

Post reply on HN