Trying out odin language

Doing some experiments with odin and raylib

It is small demo of a bf runner, coupled together with some

audio shaders demo I found on the web that I used as a starting point.

I expected being able to share some pictures of it here, but I will be fighting de 100kb limits to post something nice to look at.

odin has an structure that I find many different from what I am used to, specially in loops

bf_multi_step :: proc(n : int){
    for i in 0..= (length - 1){
            return
        }
        bf_step_eval(prog[prog_index])
        prog_index += 1
        max_index_used = max(max_index_used,mem_index)
    }
}

bf_step :: proc() {
    if prog_index >= (length - 1){
        fmt.eprintln("program execution finished")
        return
    }
    bf_step_eval(prog[prog_index])
    prog_index += 1
    max_index_used = max(max_index_used,mem_index)
}

bf_execute :: proc(program : string){
    prog_index = 0
    stash_index = 0
    prog = strings.clone(program)
    len1 := len(program) 
    out_s = ""
    for {
       if prog_index >= len1 - 1{
            break;
        }
        bf_step_eval(prog[prog_index])
        prog_index += 1
    }
    
    fmt.eprintln("program execution finished")
    fmt.eprintln(out_s)
}

It is weird to me.

Coming with raylib, miniaudio and other libraries is really nice.

Seems like a good way of writing prototypes.

I want to see if I can use the performance related features in some program later.

=> /u/LucasMW/image/351.jpeg

#odin #programming

=> ๐Ÿš€ LucasMW

2024-10-25 ยท 3 months ago ยท ๐Ÿ‘ norayr

5 Comments โ†“

=> ๐Ÿš€ clseibold ยท Oct 25 at 21:31:

Odin is very much influenced by Golang (and Pascal), according to its creator. The for loops that you see are becoming more and more common in new languages, like Golang, Odin, (JAI), and Rust. You can still do the traditional for loops in all of these languages, btw: for i := 0; i < 12; i++ {. But using ranges often makes things more readable and it's just simpler and more intuitive to write and read. One thing Odin has over Golang is it lets you use ranges backwards too, iirc, which I quite like.

Odin's biggest flaw right now is a lack of a TLS library (last time I checked, at least). Other than that, it's like a much better Golang with no GC, imo. I also really like how it handles memory allocators. And the way it handles strings is amazing, although it takes a little bit to get used to, as a string type is just a u8 slice. It's not totally dissimilar to Golang. Very different from C's crappy strings thuogh.

Zig's for loops are what I would call weird (as hell, lol). But zig also has something kinda like ranges, I think.

=> ๐Ÿš€ LucasMW [OP] ยท Oct 25 at 21:36:

It is not the for loop with ranges that I find weird, but the lack of while(condition). I was forced to do for { if (!condition) break }} which I find very counter intuitive.

But maybe that's my mistake and there is another way to do while loops that I missed?

I wish I could try jai, but I believe I lost the opportunity to join the compiler beta list.

=> ๐Ÿš€ clseibold ยท Oct 25 at 21:39:

Oh, gotcha! Yeah, Golang also lets you do for { with no expression, and it acts like a while loop. I think the idea is if we have that, then we don't need a separate keyword while that does the exact same. But yeah, that is an interesting choice, but you get used to it. For loops are just while loops with a variable counter, tbh. If you take away the variable initializer and the variable incrementer from a for loop, you literally get a while loop.

Note that Odin does have do { } while loops for those who use them (I don't like do... while loops).

=> ๐Ÿš€ LucasMW [OP] ยท Oct 25 at 22:04:

By the way, Do you know a good devtool for odin? I use sublime text, (odin creator also seems to use it), but I still haven't find how to configure it to have decent autocomplete (showing me all functions of said import) or how to "go to definition" of functions from core and vendor libraries. I wish I had these both

=> ๐Ÿš€ clseibold ยท Oct 25 at 22:14:

@LucasMW Yeah, there's ols (Odin Language Server), but I don't know if it supports sublime. I know it supports VSCode and you can get it on the new Zed text editor too (https://zed.dev). You can find ols here:

=> โ€” OLS Github

If you are using VSCode or Zed, then just download the Odin extension for the respective text editor, and ols will be downloaded by those extensions.

Proxy Information
Original URL
gemini://bbs.geminispace.org/u/LucasMW/21228
Status Code
Success (20)
Meta
text/gemini; charset=utf-8
Capsule Response Time
97.59358 milliseconds
Gemini-to-HTML Time
0.608418 milliseconds

This content has been proxied by September (ba2dc).