Also I think Odin struck the right balance of features while trying to keep to the spirit of C.
I found this claim a bit strange. do people actually use metaprogramming in Zig a lot?
IMO AST Macros are an even bigger problem than text substitution. Debugging metaprogramming of any kind past a certain point of complexity is a royal pain in the ass (even in a Lisp, Forth or Prolog), but AST explorers are next to useless for complicated logic problems that involve needle in a haystack searches of side effects. If you're dealing with a large AoS of heterogeneous SoAs which influence each other to shuffle around, and most of the related code and the structures themselves are generated via AST macros, you better be really comfortable with assembly analysis and debugger scripting.
- It is not distributed across machines. No distributed fault tolerance issues.
- It doesn't run on a resource constrained embedded system, with poor visibility, but in your dev environment.
- It runs in a single thread; no flaky race conditions or deadlocks to debug.
- Its expansion-time performance rarely matters; and it is rarely bogged down with machine dependencies or other low-level stuff.
- It is unit-testable with cases does construct X expanding to construct Y.
I would rather debug a macro than any number of other things I've also debugged.
var x: [sqrt(LENGTH)]f32 = undefined
i think calling "instantiating a generic type" meta-programming is weak, since you're not doing any of the metaprogramming yourself, though i would concede that if debugging is the concern there is a point there.same goes for "using std.debug.print"
Where you start to see actual metaprogramming in Zig is in functions like @typeInfo, @alignOf, @offsetOf, which actually let you operate on language constructs (ie: looping over the fields of a struct). This is not extremely out of the ordinary, but it's not done "as much as possible".
Another place that metaprogramming shows up in Zig is code generation using the build system. I've never done this, and I would argue this is usually recommended to be done as little as possible, rather than as often as possible.
Edit: I read the article, and while I think that the author was wrong about Zig pushing metaprogramming "as much as possible", they were fairly accurate in how it is used in the rest of the article, like for serialization. The thing is, most of my programs are not serialization. I use serialization as a means to do other things.
Odin is a rather simple, performant, pragmatic, procedural language, fixing especially things in C with regards to its type system and infrastructure (such as packages), adding niceties such as `defer` while being at it. I, as a C programmer, have it far higher up my list of languages to try than Zig or Rust by a rather large margin.
btw: "C alternative means a language that will last for 50 years" seems a snide that could be applied to any language less than 20 years old? I'm not sure what that's concretely meant to criticize here? Is Zig more a 50-year language than Odin, if so how? Odin is used for rather serious commercial products at JangaFX btw: https://jangafx.com/ and is quite beloved by some people using it.
Additionally, I don't think a C replacement should be immediately intuitive to someone who has only ever used C. To entice people away from on of the most popular and stable programming languages ever created, you must offer more than an incremental improvement. There needs to be a paradigm shift, which necessitates some degree of learning on the part of the developer.
[1] https://techtheworld.net/2024/03/06/the-nsa-list-of-memory-s...
https://gcc.gnu.org/onlinedocs/gcc-15.1.0/gm2/
Or Ada,
https://gcc.gnu.org/onlinedocs/gcc-15.1.0/gnat_ugn
Maybe C++, given that the three main C compilers are written in it?
https://devblogs.microsoft.com/cppblog/the-great-c-runtime-c...
https://petereisentraut.blogspot.com/2013/05/moving-to-c.htm...
For anyone unfamiliar with Odin that might misinterpret this, Odin has structs and parametric polymorphism for those structs. What it does not have is operator overloading or methods (which also means no constructors or destructors). In this sense, its product types are like ocaml's, only without methods too. Odin is not object oriented.
GingerBill has shouted out Go, but Odin doesn't particularly feel like a Go flavo(u)r.
https://wiki.dlang.org/Tutorials
Comparatively mature, there's even a freeware book which is quite good:
https://news.ycombinator.com/user?id=WalterBright
Zig is also worth mentioning, and pops up frequently.
If you're on here, Walter, you're my hero. I also once interacted with Brendan Eich, who I admire as much for his role in web history as for his activism.
Do you mean his homophobia?
"originated as a re-engineering of C++"
"influenced by Java, Python, Ruby, C#, and Eiffel"
"design by contract, ranges, built-in container iteration concepts, and type inference"
"array slicing, nested functions and lazy evaluation."
"Java-style single inheritance with interfaces and mixins"
"function overloading and operator overloading"
"supports five main programming paradigms" (including OOP)
... et cetera
Though it does support things like in-line assembly and the like, I'm sure most C programmers would pass on it, as a C-alternative, based on those factoids.Haven't gotten around to trying it out, but skimmed the documents a lot at one point. Always try to keep tabs on it, doesn't get the love it should.
D's scope seems to go far beyond what your average C programmer would want in a language; "use only 15% of the language and you'll be fine" (paraphrasing: "use only the 'better-C' subset", if that is what you meant, and it does seem to be a subset of D) seems a weird proposition; it still complicates things, as in collaboration, idiomatic feel and look of code, the amount of knowledge required to be competent in the language, complexity of a compiler implementation, portability of code etc... and by that logic you'd have to prefer C++ over C as well (since a lot of C is valid C++), or prefer C plus one safety feature added over C; but the "rawness"/limited scope/small size/procedural nature of C is what's appealing for many to begin with.
I for one think that a proper C replacement (C's strength also being the simplicity in which to implement a compiler for example, being the reason it's so ubiquitous in the embedded world) will be a much more limited proposition than D is.
Edit: And having been curious, even "Better-C" still has things many C-programmers wouldn't particularly like. Going by things listed here https://en.wikipedia.org/wiki/D_(programming_language)
RAII
Full metaprogramming
Nested functions, nested structs, delegates and lambdas
Member functions, constructors, destructors, operating overloading, etc.
...
Where to draw the line will be different person to person, but D doesn't seem to be a language "in the spirit of C", or a "modern version of it", at all.Viewing it as a C++ alternative makes much more sense. A `Better-C` "limit yourself to a subset of the language" compiler flag doesn't change that much.
I'd say a couple, not many.
> RAII
Who wouldn't like RAII?
> Metaprogramming
As a way to avoid preprocessor macros? Yes please.
> Nested functions
Already offered as extension.
> Member functions
I'm sure no C programmer would object to that.
> constructors, destructors
This yes. Agreed.
> operating overloading
Instead of _Generic()? Why not?
That D exposes a curated subset of D doesn’t make it a C alternative, even though the ”betterC” aims to target people looking for a C alternative
But why? You comment does not clarify what does this subset lack which prevents it being used as a C alternative. The intention is explicitly stated and the "spirit" argument is weak as overly subjective.
[1] D as a C Replacement (187 comments):
https://news.ycombinator.com/item?id=20323114
[2] Adding ANSI C11 C compiler to D so it can import and compile C files directly (105 comments):
By the way, code that I wrote yesterday is legacy.
Capitalizing method calls (`rl.InitWindow()`) seems to place the importance on the Method being called, but at first glance (ASP, or Go off the top of my head) it muddies the waters. If this isn't clear, consider that capitalizing ALL code would reduce clarity as all letter shapes are now essentially the same (a box).
I spend most of my time in c, c++, ruby, and javascript, but maybe I should try to do a personal project in Go (or Odin) for this reason alone.
In Go it has a specific meaning: starting an identifier with a capital causes it to be exported for use in other packages. Identifiers with a starting lowercase char are package private.
Apologies if this is explaining what you already know...
The original UNIX folks really love lowercase. Executables are lowercase, most file names are lowercase, file extensions are, etc. That extends to C where DMR and Ken Thompson chose lowercase names for keywords, built-in types, and standard library functions. If I remember right, Thompson uses all lowercase in most of his communications too, so I suspect it comes from him. Or maybe it was a flex because the PDP-11 could do lowercase when some other early computers didn't support it at all?
The early Pascal compilers from Niklaus Wirth and friends appear to be all caps, probably because that's all the machines supported. The language itself generally isn't case sensitive. (I say "generally" because there are many flavors of Pascal.)
When Anders Hejlsberg created Turbo Pascal (which is also case-insensitve), he introduced a convention of lowercase for keywords what we now call PascalCase for function and type names and (judging by the Wikipedia article) a mixture of PascalCase and camelCase for variables.
Perhaps because Straustrup built on C but is a Dane like Hejlsberg, he picked a mix for C++: camelCase function and variable names with PascalCase type names.
These conventions then flowed down through time. Java was heavily inspired by C++ and takes the same convention. C# is another Hejlsberg creation and follows his preferences. JavaScript follows Java. (It must annoy Hejlsberg to no end that his third baby TypeScript breaks with his own convention.)
The Odin convention is Pascal case (lower_case_procedures, Capitalized_Enums_And_Structs).
For Odin native libraries, we usually for the convention of `snake_case` for variables and procedures and `Ada_Case` for types. However for anything that is third-party/foreign, we try to keep to the same convention as the original library to make it easier to people reference the original documentation, as well as not have any of the problems that certain naming conventions cannot be translated to another. So the raylib code uses the original raylib naming conventions because of the reasons I described.
Many people complain that this is horrible, but not people who have actually tried it. It works very well, lets you bridge over differences in C++ library conventions, Unix C conventions and Microsoft conventions in a project that interfaces all of them, without getting users upset. (There’s more to it - consistency for some identifier can be enforced, there’s a smart source reformatted, and more)
Odin has all the features Go has (even struct tags https://odin-lang.org/docs/overview/#struct-field-tags), but adds:
- proper enums
- unions https://odin-lang.org/docs/overview/#unions
- built-in optional https://odin-lang.org/docs/overview/#maybet
- or_else/or_return/or_continue/or_break https://odin-lang.org/docs/overview/#or_else-expression (scroll down for the others)
- distinct types https://odin-lang.org/docs/overview/#distinct-types
- named arguments https://odin-lang.org/docs/overview/#named-arguments
- built-in matrix type https://odin-lang.org/docs/overview/#matrix-type
- built-in quaternions
- ternary operator, but you can use `bar := 1 if condition else 42` instead of ? and : if you'd like https://odin-lang.org/docs/overview/#ternary-operator
- default parameter values https://odin-lang.org/docs/overview/#default-values
- fantastic C integration
- forced in/exclusive range operators ..< and ..= https://odin-lang.org/docs/overview/#range-based-for-loop
- can get the zero value of any type using `{}` https://odin-lang.org/docs/overview/#zero-values
- defer if <condition> https://odin-lang.org/docs/overview/#defer-if
- explicit procedure overloading https://odin-lang.org/docs/overview/#explicit-procedure-over...
- bunch of vendored libraries https://pkg.odin-lang.org/vendor
- bit_set/bit_field https://odin-lang.org/docs/overview/#bit-sets https://odin-lang.org/docs/overview/#bit-fields
- proper slices (not the Go monster which combines a dynamic array along with slices) https://odin-lang.org/docs/overview/#slices
- `for x in xs` instead of `for _, x := range xs`, and `for &x in xs` if you want `x` to be addressable
- implicit selector expressions `.Member_Name` https://odin-lang.org/docs/overview/#implicit-selector-expre...
- parametric polymorphism with a ton of intrinsics https://odin-lang.org/docs/overview/#parametric-polymorphism
- - along with `where` clauses (similar to Rust) https://odin-lang.org/docs/overview/#where-clauses
Language cohesion has been _incredibly_ well thought out.
You can find odds and ends of these things in other Pascal successors like Delphi, Oberon and Object Pascal. Truth is though, I never found these languages compelling. Why? Because none of them were anywhere close to being the same kind of simplicity as Pascal, and they were too wrapped up in flashy, trendy things that went out of style. Where Odin wins out is that it distinctly lacks the 90's OO craze hangover, and it never feels particularly more complicated or bloated. It's an audaciously tasteful proposition for a language. A C replacement? No, not really. But as a C++ programmer who's fed up with the lack of things like structure introspection and ergonomic sum types, I'm keeping a very close eye on Odin.
[1] - https://c3-lang.org/
[2] - https://harelang.org/
Agree. Oberon comes close, but has other orthodoxies like upper-case keywords, and it lacks the low-level support of e.g. Delphi. I spent a lot of time with extending Oberon, but backward compatibility prohibited some features I thought were necessary. My forthcoming Micron language is this kind of "better Pascal" you mentioned; essentially it's an Oberon withouth orthodoxies and with the power of C (without its disadvantages); there are language levels from minimal, stack-less systems, up to dynamic dispatch and optional garbage collection. See https://github.com/rochus-keller/micron/.
It is by no means pascal-simple - although the subset used by 95% of programs is.
It does have everything you need including macros, unsafe access, minimal OO but these are almost exclusively used by library developers.
Instead we ended up with UCSD Pascal, Object Pascal, TMT Pascal, Quick Pascal, VMS Pascal, Delphi and what not.
By the time it came to be, ISO Extended Pascal was largely irrelevant, outside some UNIX compilers that supported it.
The Borland linage, after taking over Apple's design, which had input from Niklaus Wirth, is my favourite, then their management messed up.
In an ideal world, Modula-2 or Ada would have taken over, sadly no big name OS vendor, ever felt like adopting them.
As for Oberon, when I came to learn it, Oberon-2 was already out, eventually Component Pascal and Active Oberon were much more interesting to me.
While I appreciate Niklaus Wirth work, I was never a fan of the minimalism he tried to pursue with Oberon-07. Then rather use Go.
In the end, nothing of this will matter in the age of AI assisted tooling and code generation.
Arguing what is the best language is getting akin to argue about Assembly language syntax, when most people are using optimizating compilers.
My view is that the core of Pascal was actually the correct place to start rather than the core of C. C won out of Pascal purely because the original Pascal didn't fix its problems quick enough, and all of the successors also tried to focus on other fancier things like OOP or GC or whatever. C still remained "basic" and its preprocessor allowed for enough extensions for lacking language features, whilst not adding any of those fancier things.
For Odin, I tried to take the lessons of what I and others were emulating in C and just make them core constructs. Odin initially didn't have many of the constructs it has now such as parametric polymorphism or explicit procedure overloading, but all of them came about as a result of solving the problems people used the preprocessor for or other new features. For example, the explicit procedure overloading came about seeing how people use the (relatively new) C11 `_Generic` feature, and realizing that they were trying to emulate this aspect pretty much.
Odin also took a lot of the GNU C extensions and incorporated them directly (some of which are not in the latest version of C): `0b` literals, nested procedures (but not scope capturing), `type_of`, `case` ranges (`..<` and `..=` in Odin to be more explicit about the range bounds), array initializes with ranges, unnamed structs/unions, empty structs, and so much more.
Odin isn't a C++ alternative by any stretch, but I have seen a lot of C++ programmers really like it because it feels like it has just enough to make them feel at home whilst still have the control and more explicitness that C offers.
And what sort of time frame in terms of 1.0? I found Odin lacks the marketing push from Zig or Rust.
The reason for the lack of "social media presence" is because Odin is kind of weird to market for: https://www.gingerbill.org/article/2024/09/08/odin-weird-to-...
It's not "hypeable" like Zig or Rust mainly because it doesn't have any "killer features" but rather is a very pragmatic language by design. The people Odin attracts are also not the types of people to evangelize Odin either, since they are not there for the hype-train but to actually program.
So if you can help us find a way to market Odin itself without lying or exaggerating or overblowing minor features, then that would be very much obliged. It's a lot harder than you think.
As for "1.0", we have never worked to a timeframe for anything nor any sort of roadmap. The reason being is that we do not want to give false promises/hope about anything. Roadmaps are purely for advertisement, and the problem is, we don't even work to one so why present one? The other problem is that for "1.0", the language itself is well known: it's pretty much what you see today. But "1.0" for the general tooling? Now that's a harder question. We have plans but since everything is being worked on as we go (mostly volunteers), we cannot say when things will be finished. The biggest project at the moment is `core:os/os2`, the replacement for the `core:os` package. `core:os` was the first package ever written for Odin and it's absolutely dreadful and needs replacing. And that's what we've been doing with `core:os/os2`, slowly. And when it is ready, we will tell people many months in advance when we will make it the official one. This will be a breaking change, but probably the last biggest one for Odin.
From what little I've seen of Odin, it doesn't have anything in particular that's especially headline-grabbing. However, Odin does have one thing that Zig doesn't, and it's that the language is considered "complete" despite its git repository being newer than Zig by a year. When it comes to programming languages, I do feel like there's something to be said for ease-of-implementation, and although Zig _feels_ simple from a feature-set point of view, I imagine it has a much higher bar to clear in terms of implementation complexity.
Perhaps not modern C++, but I would absolutely place it in the same weightclass as CFront and C++98 (albeit with less bugs and more ergonomics than those). I know you've placed the language adjacent to gamedev, so an appropriate metaphor, I feel like Odin is up to the task of making something with the complexity of a Goldsrc game, or a Dreamcast game. I feel like I could churn out half a million lines of high density soft real-time code quite happily.
Excited to see how it evolves through the years. Keep up the good work!
After several thousand lines, it proved all of my major worries incorrect, and has been an absolute pleasure.
It has since replaced my usage of Go, which I had been using since release.
I would highly recommend giving it a proper shot!
I remember believing these were important:
- methods (turned out I mainly wanted working intellisense, which Odin does even without methods)
- a package manager (still a gripe, but git submodules do the trick somewhat)
- expressions (so I could assign the result from a `switch` statement to a variable for instance, but I can use an #inline proc if I _really_ want to)
- private by default (I had forgotten how many times I wanted to use something private from a library, and had to fork it instead)
- - although possible to make something private in Odin, nowadays I'd rather things be prefixed with underscores instead
Also, here are my list of things I'd still prefer changed, but are less important: https://forum.odin-lang.org/t/what-features-of-odin-do-you-d...
It's not trying to be memory safe, but rather try and catch many common mistakes that C does not catch easily.
As for use-after-free, I'd argue that is more of a problem with the memory allocation strategy in a language like C or Odin. And a change to something like an Arena like memory allocation strategy or something else reduces issues like that by a hell of a lot. `malloc`/`free` like approaches to memory allocation make use-after-free a lot more common because it making you micromanage allocations on a per-value level rather than on a per-shared-lifetime level. It's rare a single value has a unique lifetime, and I'd argue never in many projects.
ObjC is pretty much the sweet spot for me in terms of language complexity and cognitive load over C, while providing so much more. It's really a shame that a lot of people (and I'm not pointing any fingers at anyone specifically) can't get past the [..] syntax, which comes from making ObjC a pure superset of C.
So for example if I have a server, instead of allocating a Request object for each incoming request I should pre-allocate an arena of N request objects and just keep reusing them? Doesn't this blow up memory usage if I have a static pool of objects that may not be actually needed depending on traffic?
For example, "errors as values" is a point that Odin makes, but it does make it in a slightly different light from Go. Whereas Go has an `error` type that encompasses all errors, Odin does not. Instead, it treats some types (booleans, enums, unions) as "special", in that they support things like `or_return`, which are typically your error propagation statements. Oh yeah, `or_return` is another big point, it does simplify a lot of `if err != nil { return err }` type of code.
And another big similarity to Go is the declaration syntax. It was inspired by one of Rob Pike's (iirc) comments on twitter about how they should have used a different syntax for Go instead.
From personal experience though, there are some things in Odin that I wish Go had. Its features play along together so nice, and it's so satisfying having three different language features come together in a nice logically-coherent simple way. That said, I don't think Odin is capable of replacing Go. Things like server-side logic and lightweight threads are probably where Go still excels at and beats Odin.
For systems-level programming I'd pick Odin though.
I don’t particularly enjoy working on the types of problems Zig or Rust aim to solve. I spend the majority of my time working at layer 4, and Go makes it immensely enjoyable. But sometimes I want a bit more control over the hardware and don’t want to pay the cost of a GC. Odin feels just right.
In my case, the assortment of syntactic features like OOP, compile-time macros, or even the borrow checker suck all the fun out of programming. That’s why I still enjoy writing C programs, footguns and all.
I like pretty much every choice that has been taken when designing the language, except maybe the lack of namespaces, which can be solved anyway with prefixes.
The lack of OOP features is the best part for me, it's rewiring my brain in a good way and I can now also reason much better about RDBMS schemas. Data oriented design is the most helpful approach I've stumbled upon in my career.
Understanding the Odin Programming Language - https://news.ycombinator.com/item?id=42348655 - Dec 2024 (97 comments)
Moving my game project from C to the Odin language - https://news.ycombinator.com/item?id=42030704 - Nov 2024 (19 comments)
Golang developers should try Odin - https://news.ycombinator.com/item?id=41969839 - Oct 2024 (7 comments)
Marketing the Odin programming language is weird - https://news.ycombinator.com/item?id=41913319 - Oct 2024 (101 comments)
Odin isn't getting more features. The syntax is done - https://news.ycombinator.com/item?id=40873431 - July 2024 (3 comments)
Introduction to the Odin Programming Language - https://news.ycombinator.com/item?id=40688899 - June 2024 (60 comments)
Odin Programming Language - https://news.ycombinator.com/item?id=38836512 - Jan 2024 (102 comments)
Small joys of programming in Odin - https://news.ycombinator.com/item?id=36812175 - July 2023 (61 comments)
A Review of the Odin Programming Language - https://news.ycombinator.com/item?id=32799499 - Sept 2022 (140 comments)
I like Odin - https://news.ycombinator.com/item?id=32626543 - Aug 2022 (204 comments)
Odin Programming Language - https://news.ycombinator.com/item?id=30394000 - Feb 2022 (42 comments)
The Odin Programming Language - https://news.ycombinator.com/item?id=22199942 - Jan 2020 (141 comments)
The Odin Programming Language - https://news.ycombinator.com/item?id=20075638 - June 2019 (3 comments)
WhereIsTheTruth•1d ago
- RTTI: just give me compile time type introspection and let me disable RTTI without making the language unusable
- when/import: just let me wrap an import inside a when block, being forced to split my file in 3 made me quit the language
rwbt•1d ago
flysand7•21h ago
gingerBill•21h ago
People who want CTTI is because they think it will produce better code because it is specialized for that type, and that is partially true, but also it will produce a hell of a lot more code. The canonical example of what I mean is the difference between doing something like `core:fmt` in Odin, which is a fixed cost at both compile-time and run-time, and then doing something closer to `std::format` in C++ (or other similar things in other languages) which will do a specialized procedure for each set of argument types. The former might be a huge initial cost if you only have a single type you want to print, but that cost is always the same regardless of many more types you add, it's also easier to debug. The latter is a small initial cost per type, and when the types get more and more complex, you also produce more and more code, which in turn increases the compiling time and binary/executable size.
As for the conditional imports, we did use to allow them but we found that what people were doing with them was kind of missing the point of the platform-specific features of the `package` system, and their code was always better if it actually utilized the package system correctly. There were some other quirks with the conditional imports which did confuse people because they didn't realize how things had to be executed (to allow for out-of-order type checking) and just disallowing it in the first place just solves that too (as a consequence, not as a goal).
thegeekpirate•15h ago
@(require) import "x_a"
@(require) import "x_b"
when ODIN_OS == .Windows { x :: x_a } else when ODIN_OS == .Linux { x :: x_b }
x.do_thing()