8 ms·
Understanding the Odin Programming Language
- christophilus 2y agoI just started “Build Your Own Text Editor”[0], but using Odin instead of C. So far, I’m impressed with Odin. It’s the most ergonomic C replacement I’ve tried. I wish it had been around 25 years ago when I was professionally working with unmanaged code. [0] https://viewsourcecode.org/snaptoken/kilo/index.html https://viewsourcecode.org/snaptoken/kilo/index.html
- blame-troi 2y agoAs being able to use a language to write an editor is a personal must-have in a language, your mention of kilo caught my eye. I did a quick read through of the Odin overview and FAQ and my initial impressions are positive. Bonus points to them for multiple return values and no automatic fallthrough on switch. Have you tried zig? I'm casually looking for a C replacement and I took a quick look at zig but came away not liking the community vibe (some things were too dictatorial for my tastes). If you did anything with zig, how would you say the languages compare?
- dartos 2y agoOdin and Zig both have dictators. Both are very nice people as long as you’re nice yourself, imo. My opinions: Odin’s creator has some strong opinions around not prioritizing LSPs and QoL tools around Odin. Zig’s is a little more hard nosed about simplicity. Zig is a very small language for a reason. I’m on my zig arc now, but Odin is next.
- przmk 2y agoNot prioritizing tools is a mistake imho. I'd argue it helps a lot with adoption and you end up with useful tools.
- meheleventyone 2y agoOdin actually has a pretty great LSP already.
- dartos 2y agoIf your goal is viral adoption, I agree, but it sounds like Odin is kind of geared towards the graphics programming world and doesn’t require vitality at this stage.
- FullGarden_S 2y ago>Odin’s creator has some strong opinions around not prioritizing LSPs and QoL tools around Odin. no, he does not. He just doesn't use LSP but never did he ever oppose QoL tools. Odin has great support for LSP and they are working on other tools as well. Do note that Odin doesn't have a foundation like Rust or Zig so their pace of development will be at their own discretion. Please don't expect it to be similar to Zig or other well funded languages.
- dismalaf 2y ago> no, he does not. He just doesn't use LSP but never did he ever oppose QoL tools. He's somewhat against package managers (doesn't want Odin ecosystem turning into NPM or Crates.io where a single package draws in a thousand dependencies). But yeah, Odin's LSP is used by most Odin users, including staff at JangaFX.
- FullGarden_S 2y ago>He's somewhat against package managers yes and that is a design decision. Its not just the dependencies bloatware, there is also an issue of accidentally pulling in a GLP license code base and several others. But if one wishes to make a package manager for Odin, they can do so and other Odin users may use it if they found it to be really helpful but from what I know, Ginger Bill will never officially support it as it doesn't align with his vision of the language.
- gingerBill 2y agoThere is nothing in the design of Odin that prevents a package manager from being created, in fact quite the opposite. The decision, which is not design per se, is to not have an OFFICIAL package manager, nor even endorse a third party one.
- dartos 2y agoI recall a thread from a few years ago where people were saying that zig had better LSO support than Odin and saying that Odin should prioritize that more. I recall gingerBill saying that he’d rather work on the language than adoption. Which is a fine position to have. Never did I say he was morally against LSPs or anything, just that he has strong opinions on prioritizing its development vs the language itself. Please don’t put words in my mouth. I’m trying to be very clear. The Odin lsp I found (ols) is not official and not made by gingerBill. Which, again, is fine. It’s good that the community took up the burden of making an LSP.
- dismalaf 2y agoOdin has a great LSP. Gingerbill is mainly against package managers because ecosystems like NPM and Crates.io are a mess...
- anacrolix 2y agoThey are a beautiful mess. crates is actually fantastic. Being anti package management is very unproductive. It's gross but it's super productive
- dismalaf 2y agoOdin does have a pretty nice "package management" story. You can literally just throw a folder with Odin files into your project structure and it "just works". The compiler sees it and includes it automatically. I don't hate cargo either, I've also used Ruby for years, gem is nice, but in both ecosystems there's also a ton of abandoned packages, some that haven't been touched in years...
- lolinder 2y ago> You can literally just throw a folder with Odin files into your project structure and it "just works". The compiler sees it and includes it automatically. This is true of most modern languages. That's not the problem package management is solving. Package management is solving the problem of how you decide which versions of which files to put into your project, considering the fact that dependencies may form a complex graph, not a simple tree. A language can decide that it simply won't support complicated dependency graphs, which is a valid decision but is the opposite of having a nice package management story.
- dismalaf 2y agoWell, being able to simply chuck files into your project and not deal with actually importing, linking, etc... means that you can then just use something like git to manage files. Anyhow, I've used Odin, it's easy, never found the lack of package manager to be annoying. I've also used Rust, cargo is nice. I think I maybe lean a tad to the way Odin works, if for no other reason than crates.io is a graveyard of dead projects and you constantly have to see what's active and what's not, I find myself going to each project's GitHub anyway. With Odin I just import librairies straight from GitHub. And both are easier than C/C++'s lack of, well, anything.
- suby 2y agoZig's compiler error on unused variables is a deal breaker for me unfortunately. The language author also has an insulting attitude towards anyone who wants otherwise, categorizing them as bad programmers he doesn't want to work with and doesn't want using Zig. The compiler error on variables which are mutable when could be const is almost as annoying. Zig does not acknowledge that not all code is production code, that sometimes you want to prototype without having to backtrack and fix compiler errors to irrelevant things when the goal is prototyping and figuring out what you are building. It also adds friction to learning the language because statements you write will immediately get flagged as wrong -- is it actually wrong due to your unfamiliarity with the language, or is it just the lsp immediately flagging and underlining all unused as red. Better take a moment to check. Super annoying to me. I can't get past it, nor do I trust the author of Zig to not go even further in this direction. He has made it clear he will not compromise on this issue. There are more planned similar errors on the way here. At least it looks like they are no loner planning to do compiler errors on unused pub functions if they are not accessible from outside the package. Zig: Trust the programmer to manually manage memory, but not to clean up unused variables. The language is weirdly pedantic, in ways orthogonal to Rust.
- dsego 2y ago> Zig: Trust the programmer to manually manage memory, but not to clean up unused variables. That's such a good tagline, actually one of the things that annoyed me with zig as well. The other one is the lack of attention to syntax aesthetics and ergonomics, it's a bit all over the place and I am also not fond of semicolons.
- do_not_redeem 2y agoThe worst part is if you have an unused variable the compiler won't even show you the real errors until you fix all the warnings first. > Compile error: This variable of type `Foo` is unused Ok then, I'll just remove that, and... > Compile error: This function you're calling expects an argument of type `Foo` Just kill me.
- paulddraper 2y ago"Let me comment this line out" "Oh and I have to do this one too" "Oh and this five as well" "Almost there" "Nope"
- gingerBill 2y agoI am the creator of the Odin programming language. That's not even my opinion... I do not personally use an LSP for my own personal reasons (I found I PERSONALLY was less productive with such tools). I am not against the concept of autocompletion tools like an LSP. If you are more productive using one, that is great!!! OLS exists but OLS is just not "official"—even if it is very good from what many people have told me. The only reason it is not official is that none of the core team worked on it, including myself. As for QoL tools? Of course we want these but our philosophy is make sure the foundations are brilliant first before half-arsing the tool built on top of the foundations.
- melon_tusk 2y agoThe Zig-community is annoyingly political, whereas the Odin community and -creator focuses on technology.
- cgh 2y agoHow is the Zig community political? I use the language but I’m not involved with the community at all.
- melon_tusk 2y agoJust follow Andrew Kelley on whatever platform he hasn't ragequit from these days.
- poncho_romero 2y agoPlease give us some examples
- cgh 2y agoAndrew Kelley is just one guy and he’s allowed to express his own political opinions online, just as you are. What evidence is there that the community as a whole is “annoyingly political”?
- dpatterbee 2y agoThere's no community in the world that isn't political. Perhaps the issue is actually just that you disagree with the politics that are popular there?
- melon_tusk 2y agoNo, the "C community" and creators aren't making a political stance on things at all. Lua doesn't either. The Zig creator is very outspoken on political matters.
- poncho_romero 2y ago
- cultofmetatron 2y agoany word on this coming out in pdf? thats the version I strongly prefer for my ebooks
- jmacklin308 2y agoWhile not a first class solution, the EPUB version of the book converts to PDF fairly well (I'm not noticing anything wrong). There are plenty of tools to do so.
- johnisgood 2y agoI believe the issue is that things are not properly formatted, and does not look as good as it could. For text-only, EPUB is fine, otherwise I would rather prefer PDF, too.
- tasuki 2y agoCurious, why? I hate pdfs because of their fixed size. Whatever device I happen to use to view a pdf, it's always got a different size than I'd like... either too large (ok I can fix that by zooming out!), wrong proportions, or too small...
- cultofmetatron 2y agoI like that it looks like the print book. I have dual screen and when it comes to tech books. I few the pdf fullscreen on one monitor while trying things out actively on another. when I'm on the go, it looks great on a ipad. for novels where I'm reading for story, I use a kindle but for textbooks, I strongly prefer pdf
- karl_zylinski 2y agoHi, author here! The HTML version can be "printed to PDF". There is no "manually layouted" PDF available however. That requires manual typesetting the whole book, which is weeks or months of extra work. I will do that if I ever make it into a physical book. At that point an official PDF would also become available. That said, many of my readers like having the HTML version in a window next to their code window. I think it is the best experience on a computer. On the iPad I would probably read the EPUB. But if you prefer PDF, then print the HTML version to PDF. Have a nice day! /Karl Zylinski
- unwind 2y agoThis looks really nice and the prose had a positive/easy-going feel to it. When the actual code examples begin, the very first couple of lines confused me: package hellope import "core:fmt" Is the quoting of package names optional?
- argiopetech 2y agoBased on the official website[0], it would appear the package name is necessarily not quoted. This doesn't strike me as odd at all. It's an identifier, not a string. The quoting of the import, on the other hand... [0] https://odin-lang.org/docs/overview/ https://odin-lang.org/docs/overview/
- im_dario 2y agoIt looks like some borrowed Go convention, where package statements don't need to be quoted, but import statements may include URLs and, therefore, they are expected to be quoted.
- deleted 2y ago[deleted]
- gingerBill 2y agoAs the docs do state, the package declaration has nothing to do with the import path. The package name is there for consistent ABI, so that the link names are prefixed with that. The import _path_ is just that, a path to where the package is stored. They can be different but it is conventional that they are similar-ish.
- haspok 2y ago> A floating point number is a method for storing decimal numbers... I'm sorry, what?
- ComSubVie 2y agoWhat do you mean? It's exactly that in almost any programming language. What is it you don't understand: "method" (a representation) or "decimal" (a number that consists of a whole and a fractional part)?
- actionfromafar 2y agoMaybe OP reacted because a float only looks like it is a way to store decimal numbers, when it's only an approximation of decimal numbers. If you really need decimal numbers you need something like mpmath¹. As a shorthand to explain what a float is to someone, "a decimal number" is an OK start though. But sometimes that approximation breaks down even for simple examples, i.e. 0.1 cannot be represented as a float. This can be quite unexpected if your mental model is that "floats are decimal numbers with a certain precision". 1: https://mpmath.org/ https://mpmath.org/
- haspok 2y agoYou cannot represent an arbitrary or fixed precision decimal number in a floating point format. Or to put it in another way: "Most decimal fractions cannot be represented exactly as binary fractions." - from the Python tutorial The word "decimal" does not simply mean "a number that consists of a whole and a fractional part".
- bajsejohannes 2y agoI agree with OP that it's unnecessarily confusing. A "method" is a procedure. The floating point number is the result of that procedure, not the procedure itself. "Decimal" implies a ten based system, even though it's perfectly fine to say "binary decimal". Using your own replacement words, it would be clearer to write "A floating point number is a representation of a number with a fractional part".
- sklerk 2y agoI love Odin, and I'm glad to see it getting more attention. I've been working through Dave Churchill's COMP 4300 course[0] in Odin/Raylib rather than C++/SFML, and it's been a blast. [0] https://www.youtube.com/playlist?list=PL_xRyXins84_Sq7yZkxGP_MgYAH-Zo8Uu https://www.youtube.com/playlist?list=PL_xRyXins84_Sq7yZkxGP...
- raoulj 2y agoFlipped through the language overview on the website and noticed that matrices are limited in how large they can be because they're stack allocated [1]. Ergonomics of the language otherwise look solid but for my use case that would be fairly constraining [1] https://odin-lang.org/docs/overview/#technical-information-of-matrix-types https://odin-lang.org/docs/overview/#technical-information-o...
- fuhsnn 2y agoLooks like this is implemented with LLVM's builtin matrix type, also available as a Clang extension: https://clang.llvm.org/docs/MatrixTypes.html https://clang.llvm.org/docs/MatrixTypes.html
- gingerBill 2y agoActually we implement it manually ourselves the exact same way that the extensions work. This is because we have to support multiple different versions of LLVM which don't have those extensions.
- fuhsnn 2y agoThanks for clarifying!
- amjoshuamichael 2y agoMatrices, like any other primitive data type, are stack-allocated. Do you want matrices to be allocated on the heap? If you're looking to do Pandas-style data science, you'd have to write your own implementation, where you could adjust for exactly how you want to do the multiplication. The builtin matrices are typically pretty small (~4x4 or 3x3), a very common use case in graphics or games programming.
- nkrisc 2y agoAny reading recommendations for introduction to the fundamentals of manual memory management specifically? I tried learning C in the past but didn’t get very far without a compelling need to learn it. I’ve toyed with Odin a bit and the language in syntax is right up my alley, but the idea of manually managing memory is pretty foreign to me. I understand it broadly, but have no good idea about how to actually do it practically and properly. I will give this book a look as well since I see it covers the topic in some chapters.
- FullGarden_S 2y ago>Any reading recommendations for introduction to the fundamentals of manual memory management specifically here is a series written by the creator of Odin programming language about memory allocation https://www.gingerbill.org/series/memory-allocation-strategies/ https://www.gingerbill.org/series/memory-allocation-strategi... The core:mem package in standard library is a very great resource for memory management in Odin. The standard library's basically got it all.
- nkrisc 2y agoThank you, I’d missed that!
- amjoshuamichael 2y agoOdin has a builtin heap allocator that works the same way you would expect any other high-level language to do memory allocation–it's just that you have to free the memory yourself. Plus, Odin's built in `context` system makes it really easy to change what kind of allocator is used for different sections of code. For my use cases, I've never needed any more than a heap and an arena, detailed in this talk: https://www.youtube.com/watch?v=nZNd5FjSquk https://www.youtube.com/watch?v=nZNd5FjSquk Personally, my large Odin project uses a series of arrays to store specific data, and then everything else is stored in a temporary allocator, which is wiped between frames. Besides some graphics initialization & path resolution at initialization time, the heap allocator is never used. I never really have to worry about memory. That's similar to the design detailed in this talk by Ryan Fluery: https://www.youtube.com/watch?v=TZ5a3gCCZYo https://www.youtube.com/watch?v=TZ5a3gCCZYo Odin also has a tracking allocator which can be used to check for leaks or double frees. In debug mode, my program will print out all un-freed memory left after shutdown. If you're working outside of Odin, I've heard good things about Valgrind for C/C++: https://valgrind.org/ https://valgrind.org/
- EternalFury 2y agoThe door for new languages is rapidly closing; unless you are a craftsman and dilettante.
- rixed 2y agoWho's closing the door?
- EternalFury 2y agoI should have explained my reasoning. AI coding assistants are closing the door. They need a lot of training data to be good and useful. Established programming languages have a tremendous amount of that, so AI coding agents will do a good job there. C, PHP, Python, Java, etc. Garden variety and new programming languages have much less examples in the wild, so AI assistants will do a lesser job with those, unless their lineage leads to one of the established languages. Finally, the bulk of future developers will be lured to AI assisted coding and therefore won’t generate much training data for new programming languages. A vicious circle. All of the above is speculation on my part, obviously. Maybe AI assistants will get smart enough to master languages they have not been trained on.
- Herbstluft 2y agoYeah I also see the potential of LLMs to become the biggest enforcers of general technological and societal stagnation.
- EternalFury 2y agoYou can look at it this way. Or, you can see it as raising the bar for new entrants. If a new programming language has sufficient merits to overcome a poor level of AI assistance, then nothing will stop it, at least in some circles. But, if mainstream developers have become totally dependent on AI, it is going to be a high bar indeed. It would be interesting to bake AI into compilers of any new language, so that auto-correction and education of the programmer happens every time they compile. In general, though, I think people are too quick to surrender to AI.
- lenerdenator 2y agoDoes the compiler log an error if you try to compile a line of code with more than one "i" in it?
- sriram_malhar 2y agoCan someone with Odin experience tell me about a new feature? I'm looking for a unique hook, like Zig did with comptime.
- goodpaul6 2y agoI don’t think it’s trying to have some magical hook, it just feels better to program than C/C++ for most of their use cases. That being said, I find the error handling via multiple return values + or_return pretty nifty, and the vendored libraries give it a very “batteries-included” feel. For example, you can render hardware accelerated graphics and de/serialize JSON without downloading any packages.
- gingerBill 2y agoI am the creator of the Odin programming language but Odin doesn't have a "killer feature". The lack of a "killer feature" does mean it is a very weird language to market for (see: https://www.gingerbill.org/article/2024/09/08/odin-weird-to-market/ https://www.gingerbill.org/article/2024/09/08/odin-weird-to-...), but to summarize that article, Odin isn't trying to be hypeable, it's trying to be an extremely productive language for people looking for a C alternative for high performance modern systems.
- sriram_malhar 2y agoFair enough. The reason I asked is there are many languages that aim to fill the gap that Odin fills (Nim, Zig, Crystal). My use of the word "hook" wasn't meant in the sense of "killer feature"; it is some vague sense of what people believe should excite me to take a detailed look at the language spec. For example, I'd say "If you are a python programmer, you should take a look at Nim. Same syntax, automatic memory management, fast execution, and meta programming". For crystal, it would be the same set, except for the syntax (which resembles Ruby) Anyhoo, having read some more about Odin, I'll attempt an answer to my own question. These are the features -- the hooks -- that stood out from the competition for me 1. Array programming on fixed sized arrays. Very nice. 2. quaternion and matrix in-built types. This alone is worth the price 3. "where" clauses including numeric constraints on types (in parametric polymorphism) 4. relatively pain-free linking to C code of admission. 5. Small arrays for dynamically sized stack allocated arrays 6. Multiple return values that can be named. Consider me hooked! Thank you for all the hard work and sharing it generously with the world.
- fithisux 2y agoDo you know if odin can be used instead of C? For example driver or kernel development? Windows for example?
- karl_zylinski 2y agoThere's a blog post here about using Odin for making operating system: https://flysand7.hashnode.dev/writing-an-os-kernel-in-odin https://flysand7.hashnode.dev/writing-an-os-kernel-in-odin
- fithisux 2y agoThank you very much.
- kalekold 2y agoI'm not particularly impressed by Odin but maybe i'm not the audience. If you like strictly procedural languages (or a die hard C fan) it's probably fine but it feels like a 'My First Language™' kind of project. What I really miss are methods on structs a'la Go. Just simple receivers would be a great addition imho. Because of this choice, it's affected the entire stdlib and boy does it look old. Creating a typed variable to pass it to a stdlib init function (for allocation, etc) is terrible decision and it's everywhere. The stdlib looks muddled too. Odin is obviously heavily inspired by Go (among others) but it's learned nothing of the lessons of the Go authors. For example, Odin is a larger language and has fewer features. I got an ICE while compiling once and it reported something like `TODO(bill) support this`. Not a good look.
- gingerBill 2y agoThank you for your comment. Odin isn't trying to be "impressive", it's trying to be productive as an alternative for C on modern systems. Odin isn't my "First Language" and closer to my 20th. Odin is just not for you. Your complaint about the lack of methods means you don't want a C alternative, and that is absolutely fine. I have nothing inherently against methods but I believe that if you are to add them, you cannot just have _mere methods_ but also have something to take advantage of them. But by the time you need such a feature (like typeclasses/traits), it becomes far from being a C alternative now and being something closer in the realm of Rust. And what about the core library is muddled? What lessons from Go did I not learn?—I'll take "fewer features" as a compliment too. > I got an ICE while compiling once and it reported something like `TODO(bill) support this`. Not a good look. Did you make an issue for this? And how long ago was this? Because this most likely fixed/implement now, and was probably fixed very quickly too.
- thag12 2y agoi think you probably just aren't the audience. most of the things you miss are things i either am neutral on or actually enjoy (having written about ~20K lines of odin). the creating a variable and passing to the `init` procedure is something i actually like since it allows me to decouple my allocations and initializations in most cases (barring things that are backed by dynamic arrays like `core:container/queue`). it also ensures that the memory allocated by `init` procedures can outlive the structure that it was tied to, which is especially useful in the case of something like the string builder. if you simply want "method-style" autocomplete (i'm neutral on that), ols also does support that with `fake_method_completion` where you type `<variable>.<whatever>` and all procedures that take a `T` or `^T` as the first parameter show up as options. as far as having fewer features, i think it just depends on which ones you're talking about. imo, the odin generic system is much nicer to work with and the presence of real enums, bit_sets, enumerated arrays, `or_return` + friends, and a proper scoped-based defer (instead of go's function based) make it really nice to program in compared to go for me. that being said, the `core:thread` `Thread_Pool` is not a complete replacement for goroutines and i will say that the concurrency model of go works really well for a garbage-collected language. of course, the garbage-collected part there shows why something like goroutines don't really fit well in odin. on internal compiler errors, unfortunately, in a pre-1.0 language, those are bound to happen. fortunately, the time to fix can often be measured in a matter of hours rather than days/weeks.