If Odin Had Macros
Posted3 months agoActive3 months ago
gingerbill.orgTechstory
calmpositive
Debate
30/100
Odin Programming LanguageMacrosSystems Programming
Key topics
Odin Programming Language
Macros
Systems Programming
The article discusses the potential addition of macros to the Odin programming language, sparking a discussion on the language's design choices and their implications for development speed and memory safety.
Snapshot generated from the HN discussion
Discussion Activity
Very active discussionFirst comment
4d
Peak period
22
Day 4
Avg / period
7
Comment distribution28 data points
Loading chart...
Based on 28 loaded comments
Key moments
- 01Story posted
Sep 26, 2025 at 5:13 AM EDT
3 months ago
Step 01 - 02First comment
Sep 29, 2025 at 5:33 PM EDT
4d after posting
Step 02 - 03Peak activity
22 comments in Day 4
Hottest window of the conversation
Step 03 - 04Latest activity
Oct 12, 2025 at 4:07 AM EDT
3 months ago
Step 04
Generating AI Summary...
Analyzing up to 500 comments to identify key contributors and discussion patterns
ID: 45384438Type: storyLast synced: 11/20/2025, 1:35:57 PM
Want the full context?
Jump to the original sources
Read the primary article or dive into the live Hacker News thread when you're ready.
Odin doesn’t support closures (a la C++ or Rust)
The thing is, I don’t understand why.
Odin’s FAQ says it’s because closures require automatic memory management. [0] But if that’s the case, why do languages like C++ and Ada [1] support closures?
[0] https://odin-lang.org/docs/faq/#does-odin-have-closures
[1] https://learn.adacore.com/courses/advanced-ada/parts/resourc...
> I’d argue that actual closures which are unified everywhere as a single procedure type with non-capturing procedure values require some form of automatic-memory-management. That does not necessarily garbage collection nor ARC, but it could be something akin to RAII. This is all still automatic and against the philosophy of Odin.
C++ doesn't have this feature either. A C++ closure does not have the same type as a regular C-style function with the same argument types and result type. The types of functions and closures are not unified.
And C++ does have RAII, which the author feels is a kind of automatic memory management and against the philosophy of Odin.
So C++ doesn't have the feature G.B. says is impossible. I don't know enough to comment on Ada.
> For closures to work correctly would require a form of automatic memory management which will never be implemented into Odin.
I suppose you can insist Bill thinks "correctly" means all that verbiage about unified types - but then a reasonable question would be why doesn't Odin provide these "not correct" closures people enjoy in other languages ?
RAII is entirely irrelevant, the disposal of a closure over a Goose is the same as disposal of a Goose value itself. In practice I expect a language like Odin would prefer to close over references, but again Odin is able to dispose of references so what's the problem?
I just watched a recent Polonius talk ( https://m.youtube.com/watch?v=uCN_LRcswts ) and came away very impressed with the difficulty of implementing (or even modeling) the borrow checker. Or maybe you're referring to something else?
The answer in the Odin FAQ maybe could be expanded to say "many uses of closures require automatic memory management, and while Odin could add some kind of support for closures to handle the uses that don't, it'd add too much complexity and too much potential for bugs to be worthwhile". Not to speak for gingerbill, here.
Although I am a man who seemingly seems to love the idea of a freedom of a language like nim,julia,lisp,(scala?) etc., just langauges which can give you a lot of freedom in general, my intention has always been: I have been asking for freedom irl, what is wrong with giving developers freedom in programming languages.
I can still respect this opinion and I followed up on pragmatic choice and I mean, its Mr's Wilson's language and honestly the freedom to have a language like this might be freedom in it of itself too and I can respect his opinions and I might check odin again later too.
https://skytrias.itch.io/todool I saw it from Odin lang page a long time back ago and I actually really loved this tool/ am thinking of creating an open source alternative in an another language like golang/kotlin/typescript/nim (i like to imagine things and be lazy sometimes lol) but there are definitely a lot of projects like jangafx which are written in odin iirc which are definitely really impressive
I will also think about this statement more as I do think that the reason why I sometimes lack intention is because I want to define good first, I don't want to take my opinions and run with it if they hurt people directly or indirectly and I am willing to have lack of opinions first to really understand the situation I suppose but I can respect his opinion in this thing too. Something worth thinking about for me. So thanks!
So that was my perspective when I had written up my comment.
What are some really good languages for FFI? Lua as you suggest?
I have always had this notion that FFI is really hard and so firstly I would like to ask if that's really true and secondly is there a langauge which can make it easy to work with FFI the most? Like do you suggest lua for something?
[0]: https://github.com/dibyendumajumdar/ravi-ffi
I feel I'm forced to reach for FFI if I want to do anything graphical e.g Wayland or OpenGL. Otherwise it's optional
Making these types of programs relatively easy in Go (with stdlib ways to manipulate source code) has been a huge boon to the ecosystem (golangci-lint linters, code gen tools).
I'd love to see examples of what that looks like in Odin
That's a little tricky because almost anything can be a metaprogram. They're basically used when something could be "simplified" by writing a DSL, but you don't want to invent a whole new language (but you're going to anyway).
But some examples off the top of my head:
- For HTTP routers: HTTP methods (GET/POST/PATCH/DELETE/QUERY) are used when requesting a route. Instead of setting up the boilerplate of registering a url route and handling the different possible http method calls, a developer might want to use a more ergonomic macro to handle all the setup. (e.g. @<HTTP method>(<string of url>, <lamda function that returns a string that is sent back to the browser>)
- For MVC Frameworks (Same thing for MVVM, MVCL, MV*, etc... frameworks): Making a Model, View and Controller Macro that takes a name and a function and hooks it up to the application.
- For standards implementations: Adding special/non-standard bounds checking that is only calculated during compile time and removed from runtime for performance purposes (e.g. This int can only be between the ranges of -12 <-> 378 and 10621 <-> 11012)
- For game design: This level can only be solved by following the specified sequence. During the compile/build step, a proofer is run that ensures that the conditions for solving the level still hold. That way if someone adds a teleport item later in development, it doesn't break earlier levels.
- For testing: To mark a test case for a function
Asking because there was a recent Odin thread on HN where someone said that there are currently no bindings to a GUI framework for Odin.