== History ==
Work started on the language in 2016. The creator gingerBill wanted to make a language that could replace his needs for [[C (programming language)|C]] and [[C++]].<ref>{{Cite web |date=2016-07-08 |title=The Odin Programming Language |url=https://handmade.network/forums/t/1338-the_odin_programming_language#7533 |access-date=2023-11-27 |website=Handmade Network |language=en-US}}</ref> Since then the language has been developed as open source on GitHub.<ref>{{Citation |title=The Odin Programming Language |date=2023-11-27 |url=https://github.com/odin-lang/Odin |access-date=2023-11-27 |publisher=Odin}}</ref>
== Syntax and features ==
Odin's syntax is similar to that of Go and Jai.<ref>{{Cite web |date=2022-09-21 |title=Low-Level Programming with Odin Lang - Perfect for Beginners |url=https://dev.to/patrickodacre/low-level-programming-with-odin-lang-perfect-for-beginners-5cc3 |access-date=2023-11-27 |website=DEV Community |language=en}}</ref><ref>{{Citation |title=Jai vs Odin systems programming languages (Non-spicy takes!) |url=https://www.youtube.com/watch?v=M763xHjsPk4 |access-date=2023-11-27 |language=en}}</ref> The following is a simple example program written in Odin:<syntaxhighlight lang="go">
package main
import "core:fmt"
main :: proc() {
program := "+ + * 😃 - /"
accumulator := 0
for token in program {
switch token {
case '+': accumulator += 1
case '-': accumulator -= 1
case '*': accumulator *= 2
case '/': accumulator /= 2
case '😃': accumulator *= accumulator
case: // Ignore everything else
}
}
fmt.printf("The program \"%s\" calculates the value %d\n",
program, accumulator)
}
</syntaxhighlight>
=== Memory management ===
Memory is manually managed in Odin. The language has built-in support for custom allocators. Custom allocators can be passed to called procedures by assigning <syntaxhighlight inline=1>context.allocator</syntaxhighlight> with the desired allocator.<ref>{{Cite web |last=Zhiyanov |first=Anton |date=2023-07-31 |title=Trying Odin (with a playground) |url=https://antonz.org/trying-odin/ |access-date=2023-11-27 |website=antonz.org |language=en}}</ref>
=== Explicit procedure overloading ===
Odin has [[Function_overloading|procedure overloading]], but unlike languages like C++, the overloads have to be specified explicitly:<ref>{{cite web |title=Odin programming language review (procedure groups) |url=https://graphitemaster.github.io/odin_review/#procedure-groups}}</ref>
<syntaxhighlight lang="go">
bool_to_string :: proc(b: bool) -> string {...}
int_to_string :: proc(i: int) -> string {...}
// "to_string" is will call either "bool_to_string" or "int_to_string" depending on type.
to_string :: proc{bool_to_string, int_to_string}
</syntaxhighlight>
===Array programming===
Odin provides [[array programming]]<ref>{{cite web | url=https://bgthompson.com/blog/octonions-in-odin.html | title=Generating the multiplication table for octonions in Odin }}</ref><ref>{{Cite web|title=Overview|url=https://odin-lang.org/docs/overview/#array-programming|access-date=2022-10-20|website=odin-lang.org}}</ref>, enabling arithmetics on array elements:
<syntaxhighlight lang="go">
a := [3]f32{ 1, 2, 3 }
b := [3]f32{ 5, 6, 7 }
c := a * b
d := a + b
e := 1 + (c - d) / 2
fmt.printf("%.1f\n", e) // [0.5, 3.0, 6.5]
</syntaxhighlight>
The language also features "swizzling" of arrays, similar to the operation in [[Shading language|shading languages]] like [[OpenGL Shading Language|GLSL]].<ref>{{cite web | url=https://www.khronos.org/opengl/wiki/Data_Type_(GLSL)#Swizzling | title=Data Type (GLSL) - OpenGL Wiki }}</ref>
<syntaxhighlight lang="go">
// Declaring type Vector to be the same as array of 3 f32's.
Vector3 :: [3]f32
// Cross product using swizzle function
cross :: proc(a, b: Vector3) -> Vector3 {
i := swizzle(a, 1, 2, 0) * swizzle(b, 2, 0, 1)
j := swizzle(a, 2, 0, 1) * swizzle(b, 1, 2, 0)
return i - j
}
// Cross product using shorter swizzle notation
cross_shorter :: proc(a, b: Vector3) -> Vector3 {
i := a.yzx * b.zxy
j := a.zxy * b.yzx
return i - j
}
</syntaxhighlight>
====Matrix support====
A <code>matrix</code> is a [[Matrix_(mathematics)|mathematical type]] built into Odin.<ref name=":0" /> It is a regular array of numbers, arranged in rows and columns. Odin's matrix support allows for ''matrix-array and matrix-matrix operations'' making it a [[Basic_Linear_Algebra_Subprograms#Level_3|Level 3 Basic Linear Algebra Subprogram]]ing language.
<syntaxhighlight lang="text">
a: matrix[2, 3]f32 // matrix that has 2 rows and 3 columns with an element type of f32
b: matrix[3, 2]f32 // matrix that has 3 rows and 2 columns with an element type of f32
v: [2]f32 // array that has 2 elements with an element type of f32
a = matrix[2, 3]f32{
1, 9, -13,
20, 5, -6,
}
b = matrix[3, 2]f32{
3, 5,
7, 9,
}
v = [2]f32{2, -4}
m := a * b // matrix-matrix multiplication
vp := m * v // matrix-array multiplication
</syntaxhighlight>
The internal representation of a <code>matrix</code> in Odin is stored in [[Row-_and_column-major_order|column-major]] format<ref>{{cite web | url=https://odin-lang.org/docs/overview/#matrix-type | title=Overview }}</ref> while the matrix literals are written in standard (row-major like) order (e.g. <code>matrix[2, 3]f32</code> is internally <code>[3][2]f32</code> (with different a [[Data_structure_alignment|alignment]] requirement)). Column-major is used in order to utilize ([[SIMD]]) vector instructions effectively on modern hardware, if possible.
==Notable software built with Odin==
* [[EmberGen]], a real-time [[Voxel|volumetric]] [[Fluid_animation|fluid simulator]] by [[JangaFX]]<ref>{{cite web | url=https://jangafx.com/software/embergen/ | title=EmberGen: Real-Time Fluid Simulations for Fire, Smoke, and Explosions! }}</ref><ref>{{cite web | url=https://gamefromscratch.com/embergen-real-time-fluid-simulation-2/ | title=EmberGen Real-Time Fluid Simulation | date=9 May 2022 }}</ref><ref>{{cite web | url=https://www.allanmckay.com/289/ | title=Episode 289 - EmberGen | date=9 March 2021 }}</ref>
==See also==
{{Portal|Free and open-source software|Computer programming}}
*[[Pascal (programming language)|Pascal]]
*[[C (programming language)|C]]
*[[Go (programming language)|Go]]
*[[Newsqueak]]
*[[Array_programming|Array Programming]]
*[[Basic_Linear_Algebra_Subprograms|Basic Linear Algebra Subprograms (BLAS)]]
*[[SIMD]]
==References==
|