Draft:Odin (programming language): Difference between revisions

Content deleted Content added
mNo edit summary
No edit summary
 
(41 intermediate revisions by 8 users not shown)
Line 1:
<!-- Do not remove this line! -->
{{Short description|Programming language}}
{{AFC submission|d|n|u=Ncfishy|ns=118|decliner=S0091|declinets=20230815193453|reject=yes|ts=20230815182138}} <!-- Do not remove this line! -->
{{Draft topics|software|computing|technology}}
{{AFC submission|d|v|u=Xplane80|ns=118|decliner=Artem.G|declinets=20211121183548|reason2=neo|small=yes|ts=20211118005047}} <!-- Do not remove this line! -->
{{AfC topic|other}}
{{AFC comment|1=I think If submission is rejected by an Afc reviewer, so, don't submit for review, I suggesting you, firstly you ask for advice [[Wikipedia:WikiProject Articles for creation/Help desk/New question|here]] for your submission. ~~ <span style="background-color:magenta; padding: 2px 5px 1px 5px">[[User:Aviram7|<span style="color:white">αvírαm</span>]]<nowiki>|</nowiki>[[User talk:Aviram7|(tαlk)]]</span> 12:37, 27 November 2023 (UTC)}}
{{AfC submission|||ts=20230815182138|u=Ncfishy|ns=118}}
 
{{AFC submission|d|v|u=Xplane80|ns=118|decliner=Artem.G|declinets=20211121183548|reason2=neo|ts=20211118005047}} <!-- Do not remove this line! -->
{{AFC comment|1=None of the sources used are reliable and/or independent and nothing suggests this can meet the notability guidelines. [[User:S0091|S0091]] ([[User talk:S0091|talk]]) 19:34, 15 August 2023 (UTC)}}
 
{{AFC comment|1=of 9 refs 6 are from odin website, and 2 are youtube videos [[User:Artem.G|Artem.G]] ([[User talk:Artem.G|talk]]) 18:35, 21 November 2021 (UTC)}}
Line 9 ⟶ 10:
----
 
{{Short description|Programming language}}
 
{{Draft topics|software|computing|technology}}
{{AfC topic|other}}
 
{{Infobox programming language
Line 15 ⟶ 18:
| logo = The_odin_programming_language_logo.svg
| paradigms = [[Imperative programming|imperative]], [[Procedural programming|procedural]]
| designer = Ginger Bill Hall
| released = {{start date and age|2016|0706|0702}}
| latest release version = dev-20232025-0x06<ref>{{cite web |title=LatestRelease releasesdev-2025-06 |website=[[GitHub]]· odin-lang/Odin |url=https://github.com/odin-lang/Odin/releases/tag/dev-2025-06 |website=GitHub |access-date=3 June 2025 |language=en}}</ref>
| latest release date = {{Start date and age|2025|06|02}}
| latest preview version =
| latest preview date =
| typing = [[Static typing|Static]], [[Strong typing|strong]], [[Type inference|inferred]], [[Nominal_type_system|nominal]], [[Structural_type_system|structural]], [[Generic programming|generic]]
| platform = [[x86-64]], [[ARM architecture|ARM]]/[[AArch64|ARM64]], [[WebAssembly]]
| operating system = [[Cross-platformMicrosoft Windows|Windows]], [[Linux]], [[macOS]]
| license = [[BSD_licenses#3-clause|3-clause BSD]].<ref>{{cite web |title=BSD 3-clause license |website=[[GitHub]] |url=https://github.com/odin-lang/Odin/blob/master/LICENSE|access-date=2023-11-27}}</ref>
| file ext = .odin
| website = {{URL|https://odin-lang.org/}}
| influenced by = [[Pascal (programming language)|Pascal]]<ref>{{cite web | url=https://gamefromscratch.com/odin-programming-language/ | title=ODIN Programming Language | date=13 April 2022 }}</ref>, [[C (programming language)|C]], [[Go (programming language)|Go]], [[Oberon-2]], [[Newsqueak]], [[JAI_(programming_language)|Jai]]<ref>{{cite web |title=Jai vs Odin systems programming languages | website=[[YouTube]] |url=https://www.youtube.com/watch?v=M763xHjsPk4 |access-date=2022-07-06}}</ref>, [[GLSL]]<ref>{{cite web | url=https://odin-lang.org/docs/faq/ | title=Frequently Asked Questions }}</ref>
}}
'''Odin''' is an [[imperative programming|imperative]], [[General-purpose programming language|general-purpose]], [[compiled programming language|compiled]] and [[statically typed]] [[system programming language]].<ref>{{cite web | url=https://www.youtube.com/watch?v=2YLA4ajby00 | title=Interview with Odin language creator gingerBill | website=[[YouTube]] }}</ref><ref>{{cite book |last1=Zylinski |first1=Karl |title=Understanding the Odin Programming Language |date=December 9, 2024 |edition=1st |url=https://www.amazon.com/Understanding-Odin-Programming-Language-Zylinski-ebook/dp/B0DQ1V7LW4 |access-date=24 May 2025}}</ref> It is designed as an alternative to the [[C_(programming_language)|C programming language]]<ref>{{cite web |title=Introducing Odin Lang (Japanese) |url=https://qiita.com/sh1so6/items/40bdda93d6fa2f094fd7 |access-date=2019-09-29 |website=Qiita}}</ref><ref>{{Cite web |date=2022-11-04 |title=Programming Games by Hand Using Odin |url=https://community.codenewbie.org/patrickodacre/programming-games-by-hand-using-odin-55lh |access-date=2023-11-27 |website=CodeNewbie Community 🌱 |language=en}}</ref>. It has features such as compile-time [[parametric polymorphism]], [[array programming]], and [[Type_introspection|runtime reflection]].<ref name=":0">{{cite web |title=Odin programming language review (quality of life) |url=https://graphitemaster.github.io/odin_review/#quality-of-life}}</ref><ref>{{Cite web |title=Writing an Operating System in Odin |url=https://flysand7.hashnode.dev/writing-an-os-kernel-in-odin |access-date=2023-11-27 |website=flysand7's blog |date=22 November 2023 |language=en}}</ref><ref>{{Cite web |last=hasen |date=2022-08-25 |title=Why I like Odin |url=https://hasenjudy.wordpress.com/2022/08/25/odin-praise/ |access-date=2023-11-27 |website=Hasen Judy |language=en}}</ref>
'''Odin''' is an [[imperative programming|imperative]], [[General-purpose programming language|general-purpose]], [[compiled programming language|compiled]], [[statically typed]], and [[distinct types]] using [[system programming language]] designed by [[Ginger Bill]]<ref>{{cite web | url=https://www.youtube.com/watch?v=2YLA4ajby00 | title=Interview with Odin language creator gingerBill | website=[[YouTube]] }}</ref>
 
The language comes with bindings for several libraries and graphics APIs such as [[OpenGL]], [[DirectX]], [[Simple DirectMedia Layer|SDL]] and [[Vulkan]].<ref>{{Cite web |last=Mike |date=2022-04-13 |title=ODIN Programming Language |url=https://gamefromscratch.com/odin-programming-language/ |access-date=2023-11-27 |website=GameFromScratch.com |language=en-US}}</ref><ref>{{Cite web |title=Odin/vendor at master · odin-lang/Odin |url=https://github.com/odin-lang/Odin/tree/master/vendor#readme |access-date=2023-11-27 |website=GitHub |language=en}}</ref>
The language supports: [[compile-time]] [[parametric polymorphism]], [[Type introspection|runtime reflection]], [[cross-compilation]], [[manual memory management]], [[array programming]], and [[AoS_and_SoA|SOA]] data types.<ref>{{cite web | url=https://www.youtube.com/watch?v=iCqW_RepcW0 | title=Overloading and/Or (Multi) Methods in Julia, C, Odin, Nim, C#, & TypeScript | website=[[YouTube]] }}</ref><ref>{{Cite web|title=Overview|url=https://odin-lang.org/docs/overview/|access-date=2022-10-20|website=odin-lang.org}}</ref><ref>{{cite web | url=https://graphitemaster.github.io/odin_review/#quality-of-life | title=Odin programming language review }}</ref><ref>{{cite web | url=https://medium.com/swlh/something-is-happening-to-our-programming-languages-and-i-like-it-a66447beade | title=Something is Happening to Our Programming Languages, and I like It | date=31 May 2020 }}</ref>
 
== ExampleHistory ==
Work started on the language in July 2016<ref>{{cite web |title=Odin first commit |url=https://github.com/odin-lang/Odin/commit/f7a669d342c96451a3e0be84e2e51af8631f90ec |website=GitHub |access-date=24 May 2025 |language=en}}</ref>. Designer Bill Hall decided 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>. It was considered sufficiently widely used to be added to GitHub's Linguist in July 2020<ref>{{cite web |title=Odin's pull request to Linguist |url=https://github.com/github-linguist/linguist/pull/4676 |website=Github}}</ref>.
<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>
 
== Design ==
Odin is designed to be an alternative for the [[C_(programming_language)|C programming language]]<ref>{{cite web |title=Introducing Odin Lang (Japanese) |url=https://qiita.com/sh1so6/items/40bdda93d6fa2f094fd7 |website=Qiita |access-date=2019-09-29}}</ref> to achieve "high performance" on "modern systems"<ref>https://odin-lang.org/</ref><ref>{{cite web | url=https://www.c3-lang.org/compare/#odin | title=Comparisons with other languages - C3 Documentation }}</ref>, with features like compile-time [[parametric polymorphism]], [[array programming]], and [[Type_introspection|runtime reflection]].
 
=== Syntax ===
Odin's declaration syntax is inspired by Newsqueak and Jai.
<syntaxhighlight lang="go">
// Variable declarations
x : int = 123
x := 123 // Type inference
 
// Constant value declarations
X :: 123
Y : int : 123
 
// Function declaration
Z :: proc() {}
</syntaxhighlight>
 
=== Explicit procedure overloading ===
Odin has [[Function_overloading|procedure overloading]]<ref>{{cite web | url=https://graphitemaster.github.io/odin_review/#procedure-groups | title=Odin programming language review }}</ref>, but unlike C++ the overloads have to be specified explicitly.
<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 shader languages like 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>{{cite web |title=A review of the Odin programming language |url=https://graphitemaster.github.io/odin_review |website=graphitemaster |access-date=2022-09-10}}</ref>. 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.
 
==Comparisons with other languages==
The syntax of Odin partially resembles [[Go (programming language)#Syntax|Go]]'s syntax<ref>{{cite web |title=Low-Level Programming with Odin Lang |url=https://dev.to/patrickodacre/low-level-programming-with-odin-lang-perfect-for-beginners-5cc3 |website=Dev |access-date=2022-09-21}}</ref> with many adjustments.
 
Compared to C, Odin:
 
* Removes text-based preprocessing stage
* Introduces [[strong typing]]
* Adds array programming and improves [[Type introspection|runtime reflection]]
* Has explicit [[function overloading]]<ref>{{Cite web|title=Overview|url=https://odin-lang.org/docs/overview/|access-date=2022-10-20|website=odin-lang.org}}</ref>
 
Compared to Go, Odin:
 
* Has [[manual memory management]]<ref>{{cite web | url=https://dev.to/patrickodacre/low-level-programming-with-odin-lang-perfect-for-beginners-5cc3 | title=Low-Level Programming with Odin Lang - Perfect for Beginners }}</ref>
* Does not have interfaces
* Lacks language-level concurrency primitives, but implements them as part of its core library
 
==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}}
* [[Go (programming language)|Go]]
 
* [[PascalD (programming language)|PascalD]]
* [[CV (programming language)|CV]]
* [[GoRust (programming language)|GoRust]]
* [[Zig (programming language)|Zig]]
*[[Newsqueak]]
*[[Array_programming|Array Programming]]
*[[Basic_Linear_Algebra_Subprograms|Basic Linear Algebra Subprograms (BLAS)]]
*[[SIMD]]
 
==References==
Line 178 ⟶ 54:
 
== External links ==
* {{Official website|https://odin-lang.org/}}
 
* [https://odin.handmade.network/ Odin at Handmade Network]
*{{Official website|https://odin-lang.org/}}
*[https://odin.handmade.network/ Odin at Handmade Network]
 
[[:Category:Programming languages]]
[[:Category:Cross-platform free software]]
[[:Category:Cross-platform software]]
[[:Category:Free compilers and interpretersopen source compilers]]
[[:Category:Programming languages created in 2016]]
[[:Category:Statically typed programming languages]]
[[:Category:Systems programming languages]]
[[:Category:Software using the BSD license]]
{{Drafts moved from mainspace|date=November 2021}}