The Dio Programming Language

Homepage Documentation Safety Syntax and FAQs

Efficient by default

Return values are better

Many people would print a list of numbers by using the following code (Next version will have a WriteLine)

for v in [5, 8, 32, 9, 14]
{
//itoa is defined as itoa(u64 val) u8[23]
puts(itoa(v))
}

Dio sees itoa returns a fixed length array of 23 bytes. Instead of itoa calling malloc everytime it's called and instead of forcing the caller to pass in a buffer, Dio will allocate the array on the stack and pass in the reference for you. No malloc is necessary

Inline data in class

class Example { int a, b[25], c[], d?, e[10]? }

Dio tries to be as efficient as possible and doesn't use boxing. Variables a, b and d address are inside of the struct. Since c length is unknown c is a pointer and length field which will be initialized in the constructor. Because d and e are nullable there will be an invisible variable created which the compiler will use to say if d and e are null or not. The invisible variable is only created when the nullable variable isn't a pointer (such as the variable c).

Good Function Parameters

test(int a, b, c; string name; u8 simple_data[25], userdata[]) u8[]

These are extremely common data types. If you have written a lot of C++ your function would have const, references (or pointers), move assignment operator and other noise.userdata would likely be two variables (pointer and size).

That's exactly what Dio does by default. None of the parameters can be modified and none of them are null. Because simple_data length is known it will be a simple pointer. userdata is type that has a pointer and length field. The array being returned will be owned by the calling function. The calling function will know to free the data so there are no memory leaks