Readit News logoReadit News
christophilus · 9 months ago
I 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

blame-troi · 9 months ago
As 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 · 9 months ago
Odin 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.

melon_tusk · 9 months ago
The Zig-community is annoyingly political, whereas the Odin community and -creator focuses on technology.
sklerk · 9 months ago
I 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...

raoulj · 9 months ago
Flipped 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-o...

fuhsnn · 9 months ago
Looks like this is implemented with LLVM's builtin matrix type, also available as a Clang extension: https://clang.llvm.org/docs/MatrixTypes.html
gingerBill · 9 months ago
Actually 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.
amjoshuamichael · 9 months ago
Matrices, 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.
unwind · 9 months ago
This 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 · 9 months ago
Based 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/

im_dario · 9 months ago
It 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.
gingerBill · 9 months ago
As 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.

Deleted Comment

nkrisc · 9 months ago
Any 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.

amjoshuamichael · 9 months ago
Odin 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

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

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/

FullGarden_S · 9 months 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-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 · 9 months ago
Thank you, I’d missed that!
cultofmetatron · 9 months ago
any word on this coming out in pdf? thats the version I strongly prefer for my ebooks
tasuki · 9 months ago
Curious, 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 · 9 months ago
I 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 · 9 months ago
Hi, 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

jmacklin308 · 9 months ago
While 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 · 9 months ago
I 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.
kalekold · 9 months ago
I'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.

thag12 · 9 months ago
i 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.

gingerBill · 9 months ago
Regarding internal compiler errors, I still hit on in MSVC every other month, and that's a compiler that has been in production for many decades at this point.

But as I said to him, did he file an issue and when was this? Because it was probably fixed by now, and if not, we'll try to fix it straightaway.

baranul · 9 months ago
Odin appears to only recently have been pressing the claim of Go alternative, as a new direction in its marketing hype. There are Go and Pascal influences, but Odin is arguably much more similar to and an alternative of Jai[1][2] (from Jon Blow). Maybe the strategy is to try to distance itself from the label of Jai-clone or Jai-lite.

If Jai goes public beta or releases books (upcoming from Ivo Balbaert), then Jai has the potential to kill off Odin, which appears to only been able to keep a smallish following (relatively fewer GitHub stars and lack of Wikipedia page) since its birth in 2015 or 2016. Odin's popularity, seems dependent on Jai not being public yet.

The languages which are truly close to Go, are: Go+ (goplus)[3], V (vlang)[4], and Borgo[5]. V has the methods on structs, as you have mentioned. Go+ and Borgo compile to Go. V compiles to C, along with other backend options, and has a Go2V transpiler. These languages are more of an evolution of Go, that provide additional features and functionality, and where the influence is much more obvious.

[1]: https://github.com/Jai-Community/Jai-Community-Library/wiki

[2]: https://youtu.be/M763xHjsPk4 (Jai vs Odin)

[3]: https://goplus.org

[4]: https://vlang.io

[5]: https://borgo-lang.github.io (note- weird issues over lack of license)

gingerBill · 9 months ago
Thank 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.

fithisux · 9 months ago
Do you know if odin can be used instead of C? For example driver or kernel development? Windows for example?
karl_zylinski · 9 months ago
There's a blog post here about using Odin for making operating system: https://flysand7.hashnode.dev/writing-an-os-kernel-in-odin
fithisux · 9 months ago
Thank you very much.