Out of the ODIN-ary

I’ve been playing with ODIN, a (relatively) new C-like language designed for building games. It’s a statically typed compiled language with absolutely nothing in common with Lucee other than the most important feature of both in that they just work. They’re designed for a job and do they do it.

The designers of ODIN wanted to incorporate some of the features of high level languages and amazingly enough they succeeded. It’s not often you return to Lucee from using a low level language and find yourself missing features, but with ODIN you really do.

Here are three of the best (in decreasing rank), that I’d love to see in Lucee:

1. key, value iterations

There are no objects in ODIN. It’s all data driven. This is is standard thinking in the games industry where the overhead in making objects and fetching values via methods is just too slow when you’re blasting aliens.

Looping over a struct is as simple as

for key, value in data {

}

Yes, a statically typed compiled language actually looks like that. key is immutable (obvs), and value in ODIN is a copy. You can change that by using &value, which would be the expected behaviour in Lucee.

2. key, index array loops

Ever need the value and the position of elements in an array? This syntax solves that:

for value, index in arraydata {

}

You can actually use &value in ODIN and change the value as you loop. Having the index available for a quick update is just as easy.

3. Multiple return values

Of course any language that allows you to pass a struct by reference allows you to return as many values as you like, but sometimes it’s nice to explicitly list the expected return values from a function. In Lucee, it would look something like this:

total, count = object.addVal(myVal);

private numeric, numeric function addVal(numeric myVal) {}
2 Likes

Lucee has

loop collection=st key=“key” value=“value” {
}

Or

structEach( st, function(k, v, st){
});

Array has index, item for loop and arrayEach

1 Like