Chapter 4. Language Summaries
The rest of this report examines the purpose of each language and how some of its features reflect that purpose.
Crystal
Although the proponents of many languages claim good performance, developers who make speed of execution a high priority still fall back on C or one of its derivatives. Crystal is the latest attempt to achieve both performance and the highly structured, compact code permitted by Ruby. Thus, Crystal is procedural and object oriented. It allows for both explicit typing and type inference, like many scripting languages, offering the fool-proof typing of traditional compiled languages and the simplicity of classic scripting languages.
The resemblance to Ruby can be seen in such syntax features as the
do loops in the following calls to a database. The activities in
this snippet will be familiar to anyone who has accessed a database
from a programming language using something like the Open Database
Connectivity standard:
DB.open "sqlite3://./data.db" do |db|db.exec "CREATE TABLE contacts (name VARCHAR(30), age INT)" db.exec "INSERT INTO contacts VALUES (?, ?)", "Frank", 30 db.exec "INSERT INTO contacts VALUES (?, ?)", "Alexa", 33 db.query "SELECT name, age FROM contacts" do |rows|
rows.each do name, age = rows.read(String, Int32) person ...