Crystal is a general-purpose, object-oriented programming language designed and developed by Ary Borenszweig and Juan Wajnerman and over one-hundred listed contributors.[1] Crystal is developed as open source and its syntax is inspired by Ruby. Crystal is statically type-checked but without having to specify the type of variables or method arguments. Its first official release was released in June 2014.[2][3] While the original Crystal compiler was written in Ruby, in 2013 a new compiler written using the Crystal programming language itself was released.[4] The current release version is 0.11.1 and the language is in an active development phase.
Description
Although resembling the Ruby programming language in syntax, Crystal compiles to much more efficient native code using an LLVM backend, at the cost of disallowing the dynamic aspects of Ruby. Recent benchmarks have demonstrated that Crystal has a performance broadly similar to C for a wide range of computing tasks.[5][6][7] The language has automated garbage collection and currently offers a Boehm collector. Crystal possesses a macro system and supports generics.
Examples
This is the simplest way to write the Hello World program in Crystal:
puts "Hello World!"
Or using an object-oriented programming style:
class Greeter
def initialize(name)
@name = name.capitalize
end
def salute
puts "Hello #{@name}!"
end
end
g = Greeter.new("world")
g.salute
HTTP Server
require "http/server"
server = HTTP::Server.new(8080) do |context|
context.response.content_type = "text/plain"
context.response.print "Hello world! The time is #{Time.now}"
end
puts "Listening on http://0.0.0.0:8080"
server.listen
References
External links