Crystal (programming language): Difference between revisions

Content deleted Content added
Updated version to latest stable release
not needed when the title already contains the disambiguation
 
(45 intermediate revisions by 28 users not shown)
Line 1:
{{AboutShort description|theObject-oriented [[programming language]]||Crystal (disambiguation)}}
 
{{Infobox programming language
| name = Crystal
| logo = Crystal language logo.svg
| paradigm = [[Multi-paradigm programming language|Multi-paradigm]]: [[Object-oriented programming|object-oriented]], [[Concurrent computing|concurrent]]
| released = {{Start date and age|2014|06|1819}}<ref>{{factCite web|url=https://crystal-lang.org/2014/06/19/crystal-0.1.0-released.html|title=Crystal 0.1.0 released!|website=crystal-lang|date=January19 June 2014 2021}}</ref>
| designer = Ary Borenszweig, Juan Wajnerman, Brian Cardiff
| developer = Manas Technology Solutions
| latest release version = {{wikidata|property|referencepreferred|references|edit|P348|P548=Q2804309|P348}}
| latest release date = {{startStart date and age|{{wikidata|qualifier|preferred|single|P348|P548=Q2804309|P348|P577}}|df=yes}}
| typing = [[Type system#Static type checking|static]], [[Type system#Inferred type checking|inferred]], [[Type system#structuralNominal type system|structuralnominal]], [[Duck_typing|duck]]
| influenced by = [[Ruby (programming language)|Ruby]], [[C (programming language)|C]], [[Rust (programming language)|Rust]], [[Go (programming language)|Go]],<ref name="rel_0.18.0"/>go [[C Sharp (programming language)|C#]],<ref name=multithread"rel_0.18.0"/> [[Python (programming language)|Python]]<ref name="rel_0.18.0"/>
| programming language = Crystal
| platform = [[IA-32]] (i386), [[x86-64]], [[AArch64]]<ref name="platform-support" />
| operating system = [[Linux]], [[macOS]], [[FreeBSD]], [[OpenBSD]], [[Microsoft Windows|Windows]]<ref name="platform-support" />
| license = [[Apache License 2.0]]
| file ext = .cr
| website = {{URL|https://crystal-lang.org}}}}
}}
 
'''Crystal''' is a [[high-level programming language|high-level]] [[general-purpose programming language|general-purpose]], [[object-oriented programming]] language, designed and developed by Ary Borenszweig, Juan Wajnerman, Brian Cardiff and more than 300400 contributors.<ref name="contributors" /> With syntax inspired by the language [[Ruby (programming language)|Ruby]],<ref name="rel_0.18.0"/> it is a [[compiled language]] with [[Type system#Static type checking|static type-checking]], but specifying the types of variables or method arguments is generally unneeded. Types are resolved by an advanced global [[type inference]] algorithm.<ref name="type-inference-i" /><ref name="devm" /> Crystal
is currently in active development. It is released as [[free and open-source software]] under the [[Apache License]] version 2.0.
 
Line 26 ⟶ 24:
Work on the language began in June 2011,<ref name="story"/> with the aim of merging the elegance and productivity of Ruby with the speed, efficiency, and type safety of a compiled language.<ref name="why_crystal"/><ref name="story"/> Initially named ''Joy'', it was quickly renamed to ''Crystal''.<ref name="story"/>
 
The Crystal compiler was first written in Ruby, but later rewritten in Crystal, thus becoming [[Self-hosting (compilers)|self-hosting]], {{as of |November 2013|lc=true}}.<ref name="goodbye_ruby"/> The first official version was released in June 2014.<ref name="rel_0.1.0"/> In July 2016, Crystal joined the [[TIOBE index]].
 
== Description ==
Although resembling the Ruby language in syntax, Crystal compiles to much more efficient native code using an [[LLVM]] backend, at the cost of precluding the dynamic aspects of Ruby. However, theThe advanced global type inference used by the Crystal compiler, combined with the use of [[union type]]s, gives Crystalit more the feel of a higher-level scripting language more so than many other comparable programming languages. The languageIt has automated garbage collection and currently offers a [[Boehm garbage collector|Boehm collector]]. Crystal possesses a macro system and supports generics as well as both method and operator overloading. Crystal'sIts concurrency model is inspired by [[communicating sequential processes]] (CSP) and implements light-weightlightweight fibers and channels (for communicatinginterfiber between fiberscommunication), inspired by [[Go (programming language)|Go]].<ref name = "rel_0go multithread">{{cite web | url=https://forum.18crystal-lang.0"org/t/crystal-multithreading-support/6622/19 | title=Crystal multithreading support | date=23 February 2024 }}</ref>
 
== Examples ==
=== Hello World ===
This is the simplest way to write the [["Hello, World!" program|Hello World]] program in Crystal:
 
<syntaxhighlight lang="crystal">
Line 62 ⟶ 60:
server = HTTP::Server.new do |context|
context.response.content_type = "text/plain"
context.response.print "Hello world! The time is #{Time.nowlocal}"
end
 
Line 90 ⟶ 88:
<syntaxhighlight lang="crystal">
desired_things = [:unicorns, "butterflies", 1_000_000]
p typeof(desired_things.first) # typeof returns the compile time type, here (Int32Symbol | String | SymbolInt32)
p desired_things.first.class # the class method returns the runtime type, here Symbol
</syntaxhighlight>
Line 115 ⟶ 113:
puts value # => 2
</syntaxhighlight>
 
== Adoption ==
 
In 2020, it was reported that the infotainment units in vehicles produced by [[Nikola Corporation]] were written in Crystal.<ref>{{cite web |last1=Pettinati |first1=Martin |title=Nikola Motor Company: Crystal powered dashboards on the trucks of the future {{!}} Manas.Tech |url=https://manas.tech/blog/2020/02/11/nikola-motor-company/ |website=Manas Technology Solutions |language=en |date=11 February 2020}}</ref> Much of the backend of the [[Kagi (search engine)|Kagi search engine]] is written with Crystal.<ref>{{cite web |title=Zac Nowicki – Tales from Kagi {{!}} CrystalConf 2023 |url=https://www.youtube.com/watch?v=r7t9xPajjTM |date=13 November 2023}}</ref>
 
== Further reading ==
Line 129 ⟶ 131:
| isbn = 978-1-68050-286-2
| url = https://pragprog.com/book/crystal/programming-crystal
}}
* {{citation
| first1 = George
| last1 = Dietrich
| first2 = Guilherme
| last2 = Bernal
| date = May 27, 2022
| title = Crystal Programming
| publisher = [[Packt Publishing]]
| isbn = 978-1801818674
}}
* {{citation
Line 137 ⟶ 149:
| trans-title = The Ruby-like programming language Crystal
| work = [[Linux Magazine|Linux Magazin]]
| issue = 033/2016
| issn = 1432-640X
| language = de
Line 148 ⟶ 160:
<ref name="platform-support">
{{cite web
| url = https://github.com/crystal-lang.org/crystalreference/wiki/Platform-Supportplatform_support.html
| title = Crystal Platform Support
| work website = Crystal Wikicrystal-lang.org
| via = [[GitHub]]
}}
</ref>
Line 161 ⟶ 172:
| via = [[GitHub]]
}}
</ref>
</ref>
<ref name="type-inference-i">
Line 195 ⟶ 205:
<ref name="why_crystal">
{{cite web
| url = httphttps://motion-expressadlerhsieh.com/blogp/why-use-crystal-lang
| title = Why Crystal programming language?
| last = Hsieh
| first = Adler
| date = September 20, 2015
| website = motion-expressadlerhsieh.com
}}
</ref>
Line 221 ⟶ 231:
| date = June 16, 2016
| website = crystal-lang.org
| quote =
| quote = It's heavily inspired by Ruby, and other languages (like C#, Go and Python).
}}
</ref>
<ref name="devm">
{{cite web
| url = https://devm.io/ruby/crystal-ruby-programming
| title = Programming with Crystal: 'A language for humans and computers'
| date = July 3, 2023
| website = devm.io
}}
</ref>
Line 228 ⟶ 246:
== External links ==
* {{Official website|crystal-lang.org}}
* [https://crystal-lang.org/reference/ Documentation]
* {{Github|crystal-lang}}
* [https://reddit.com/r/crystal_programming /r/crystal_programming subreddit]
* [https://crystal-ann.com Crystal Announcements]
 
[[Category:Programming languages]]
[[Category:Multi-paradigm programming languages]]
[[Category:Object-oriented programming languages]]
[[Category:ProgrammingConcurrent programming languages created in 2014]]
[[Category:Software using the Apache license]]
[[Category:Statically typed programming languages]]
[[Category:Cross-platform free software]]
[[Category:Cross-platform software]]
[[Category:Free and open source compilers]]
[[Category:Software using the Apache license]]
[[Category:Programming languages created in 2014]]
[[Category:2014 software]]