
The Crystal Programming Language - type0
https://crystal-lang.org/
======
tomhoward
Previous discussions:

[https://news.ycombinator.com/item?id=9669166](https://news.ycombinator.com/item?id=9669166)
(3 years ago)

[https://news.ycombinator.com/item?id=10014178](https://news.ycombinator.com/item?id=10014178)
(3 years ago)

[https://news.ycombinator.com/item?id=10803635](https://news.ycombinator.com/item?id=10803635)
(2.5 years ago)

[https://news.ycombinator.com/item?id=15574714](https://news.ycombinator.com/item?id=15574714)
(5 months ago)

~~~
fuzzythinker
Some news in the past 5 months:

Crystal is now %100 funded for a full-time developer working on core -
[https://twitter.com/CrystalLanguage/status/98229223882167500...](https://twitter.com/CrystalLanguage/status/982292238821675008)

Crystal Automated Release towards 1.0 - [https://crystal-
lang.org/2018/03/09/crystal-automated-releas...](https://crystal-
lang.org/2018/03/09/crystal-automated-release.html)

A summary of why vs. why not - [https://medium.com/@DuroSoft/why-crystal-is-
the-most-promisi...](https://medium.com/@DuroSoft/why-crystal-is-the-most-
promising-programming-language-of-2018-aad669d8344f)

Web Frameworks Status:

Rails inspired (with Influence from Phoenix):

Amber -
[https://github.com/amberframework/amber](https://github.com/amberframework/amber)

Lucky -
[https://github.com/luckyframework/lucky](https://github.com/luckyframework/lucky)

Both look healthy in terms of community and updates but Amber seems to have a
slight edge.

Sinatra inspired:

Kemal - [https://github.com/kemalcr/kemal](https://github.com/kemalcr/kemal)

------
neokantian
I had a quick look at the language and checked about my two pet pieves. What
does the code look like when handling JSON data? (that is when I slammed the
door on Golang) What does the code look like when starting an external
process, supplying stdin, args and capturing return code, stdout, and stderr?
(that is when I slammed the door on lua). Well, I must say that crystal-lang
manages to dodge the bullet twice. It handles both situations quite elegantly.
So, yes, I am interested.

~~~
013a
What exactly frustrates you about Go's JSON handling? In my experience its
among the best in typed languages. Define a struct (or just use an untyped
map), optionally specify json tags for field names, pass it and the json to
json.Unmarshal. Go is _literally_ designed for this use case; systems
programming, sharing messages between systems. Compared to other typed
languages like Rust or Java, its at least as simple, if not simpler.

~~~
tigershark
Compare it with F# type providers where you don’t need to generate any struct
and you can access the JSON object in a _type safe_ way with autocompletion in
your IDE and maybe you will understand what is frustrating...

~~~
IshKebab
How is that possible? You either need to specify the types up front (like Go)
or give up on static type safety (like Python). It's impossible to have both.

~~~
actsasbuffoon
Actually, you can have both. Many languages in the ML family (Haskell, F#,
etc.) can ensure complete type safety without having to define the shape up-
front.

Your data comes out of the JSON structure wrapped in a functor, and you can
only access it in ways that deal with missing data.

It’s hypothetically possible to recreate this approach in Python, but I don’t
think it would be Pythonic.

~~~
013a
Its hypothetically possible to recreate this approach in any language. Grab
the item in the map at that key -> check that it exists -> check that the type
is what you expect.

Its not idiomatic in most mainstream languages. Except, that's how most JSON
libraries which validate against a static structure are implemented, they just
abstract the reflection away via some interface.

~~~
actsasbuffoon
> Its hypothetically possible to recreate this approach in any language.

Yes, I didn't mean to imply that I was providing an exhaustive list of
languages where this approach could be implemented. I merely mentioned Python
because it had been brought up several times in the thread.

> Grab the item in the map at that key -> check that it exists -> check that
> the type is what you expect.

I'd argue with that phrasing. _You_ don't check for the key, nor do you check
the type. That would imply something like an if-statement to ensure the
presence of a key, and switching over a type. In such a system, you could
forget to check for null, or make some other mistake that causes the program
to fail at run time.

The functor approach does not rely on the developer checking anything. It is
100% type safe, enforced by the type system, cannot crash at run time, and
does not require you to provide a data type to extract the data into.

------
odammit
When I was younger, I programmed predominantly in Java and types were
infuriating to me.

Then I found ruby and loved how simple it was to not worry about a type
system.

Then I found out how infuriating it was to not have types.

Now I’m older and appreciate having types.

Cool story, bro.

Crystal looks cool!

~~~
weavie
There's a lot more to Types vs No Types than Java vs Ruby would imply!

~~~
nine_k
Indeed. You learn e.g. Haskell and find that Java painfully lacks in the types
department. You learn Perl and find that Ruby is unexpectedly rigid in the
types department :)

~~~
yellowapple
Perl also has the ability to effectively build class instances from scratch by
manually blessing arbitrary data structures (usually hashes, but not much
stopping you from blessing an array or scalar). For some folks (like me), it's
a blessing for making hard problems at least slightly easier to solve. For
others, well, there's always Moose.

Basically, a lot of Perl's object-orientation weirdness derives from it all
being exposed to you. It's an excellent learning experience if you ever want
to know what it means to be a "class" or an instance thereof, since "methods"
are just ordinary subroutines that expect your object (or class, for
constructors) as the first argument, and class instances are just ordinary
scalar/array/hash objects blessed with a package name. Nothing hidden or
abstracted away. Simple and flexible enough to fit into the TMTOWTDI
philosophy.

------
mosselman
I built a client for [http://woordenlijst.org/#/](http://woordenlijst.org/#/)
(Dutch word existence checker basically) and it is super fast. The syntax is
only slightly different from Ruby and it starts up instantly.

The only thing that I have against crystal is that my compiled binary didn't
work on all other machines I tried it on. Even the practically identical
macbook of a friend of mine. Looking around on their wiki pages and in the
issues on github didn't give me any real solutions. So right now, as the
version numbering suggests, it isn't ready for production.

~~~
yorwba
When a compiled binary doesn't run on a different machine with the same
hardware, it's probably a problem with dynamic linking. That seems to have
been discussed on the issue tracker [https://github.com/crystal-
lang/crystal/issues/2003](https://github.com/crystal-lang/crystal/issues/2003)

~~~
mosselman
Thanks, I have looked over this thread a while back, but it did not fix my
issues. I might give it another go sometime.

------
WJW
Crystal is pretty neat and ticks off almost all of the boxes for me atm (For
example the websockets server functionality in Kemal is super neat), but the
lack of proper parallelism is kind of a killer. I know it's in the works, but
afaict it has been so for almost a year now without much news...

~~~
pjmlp
Parallelism is always possible UNIX old style, use multiple processes.

It is anyway the trend we are getting back to, after we have learned our
lesson how threads and plugins can bring whole processes down, while being
good vehicles for security exploits.

~~~
WJW
While forking is always possible, there are some things that it does solve
well enough IMO. For example, sharing and reusing database connections via a
connection pool is much nicer if all threads can actually access the same
memory. Shared memory is both a curse and a blessing of course :|

~~~
hawski
One can always use a bit of shared memory between processes. At least it would
be contained to the parts that one really want to share. There are a few ways
to do that. The easiest one is mmap MAP_SHARED|MAP_ANONYMOUS.

------
naiyt
I've been a fan of Ruby for about 5 years, but lately I've been leaning a lot
more heavily towards statically typed languages. Which is why Crystal is at
the top of my "want to learn" list. Ruby inspired syntax and statically typed?
Yes please. The speed is just a bonus for me.

~~~
slx26
I consider speed to be extremely important, because it enables me to use the
language in many more practical scenarios. And that's a joy. Writing in most
other imperative languages after having learned Ruby feels so painful to me.

------
innocentoldguy
I've been using Crystal on a mobile checkout application to watch for and
parse incoming pricing files. I've been extremely happy with it so far. It is
fast, the type system is nice, and I really enjoy the Ruby-like syntax and
ease of development. I've also been happy with the developers and the
community. The community is supportive and the developers are making good
progress on the language and are quite responsive to community feedback.

If you like the idea of a fast, compiled, statically-typed, Ruby-like
programming language, you can support Crystal development here (NOTE: I'm not
affiliated with the Crystal project in any way. I'm just a happy consumer):
[https://crystal-lang.org/sponsors/](https://crystal-lang.org/sponsors/)

------
squarefoot
I played with Ruby like 15 years ago and loved it, but surely speed wasn't
exactly a selling point, so I welcome this project. One question though for
the gurus out there: they say the compiler is written in Crystal; is it good
practice to do it that soon? To me it could slow down development, if a subtle
error occurs it could make harder to nail it to a bug in the compiler or in
the language.

~~~
ModernMech
Bootstrapping your compiler is a vanity project for languages. It's cool to
show you can do it, but pretty pointless in a practical sense unless your
language is targeted at building compilers.

~~~
cjhanks
Additionally, writing a compiler really helps a team find their edge cases
much faster. Without a major software undertaking for an immature language,
most of those bugs would be found (and likely not reported) by users.

But yeah, there's a little vanity too.

~~~
ModernMech
Sure writing a compiler can help there, but like I said, there are probably
better ways to test that taking into account the design goals of the language.
If you find that writing compilers is a pain in your language, but no one in
your community is using your language to write compilers, are you going to
invest resources in making your language better at writing compilers, or are
you going to work on things important to your community?

~~~
cjhanks
Yeah, that's a good point. In the sense, RubyOnRails was a great blessing to
the language.

------
mberning
I have written a few small apps in it and so far I like it. I hope it gets
traction and we see broad support for it dev tools. Would be cool to have
debugger support in rubymine or idea for example.

------
MR4D
Looks like a nice effort. As a fan of Python over Ruby, I would love to see
something like this for Python fans, but efforts like this give me hope that
one day it will happen.

~~~
Aardappel
Strongly typed language with Python-esque syntax:
[http://strlen.com/lobster/](http://strlen.com/lobster/)

------
luckydude
One of the few languages that I've seen in years that I liked right away.
Checks a lot of my boxes, I like the inferred types and I like static typing.
Nice job!

------
phaedryx
It is also a potential compile-to-webassembly language.

------
jaequery
Crystal looks really cool but if speed is what its after, i think it misses
the target for most people.

because for most apps, you will be bottlenecked by the database server. it is
the slowest hanging fruit on the tech stack, be it postgres , mysql, or mongo.
so unless you are working on number crunching tasks that do not involve any db
queries, i fail to see the benefit of a language like Crystal.

i wait for the day until the day Crystal becomes a 100% drop in replacement
ready for Ruby apps.

until then, Sinatra is more than fast enough for most things.

~~~
WJW
How small is the lightest sinatra app though, when deployed in a container? We
lately had some experience with dockerizing a moderately complex ruby app and
it was pretty shocking how large they get compared to simple statically linked
binaries.

~~~
jaequery
im not sure what you are asking for in terms of lightness but its incredibly
light in both concept and execution.

i mean it doesnt get any lighter than this.

require ‘sinatra’

get ‘/‘ do

    
    
      “hello”
    

end

you should check out
[https://github.com/jaequery/jasis](https://github.com/jaequery/jasis)

its a dockerized Sinatra app with all the bells and whistles and see how light
it is yourself.

~~~
AYBABTME
Sure but no useful app can be described by this "Hello HTTP" example. I've
seen the same as parent: Ruby services require a lot more memory in their
steady state than say, their Go service counterpart, for a same complexity.

~~~
jaequery
you must be referring to Rails. sure they can be pretty big, as they are what
you call a monolithic framework.

thats why i recommend Sinatra for performance conscious devs, as its a fast
and minimal framework. and you get to load only what you need. check the
github.com/jaequery/jasis github project and peek at the Gemfile / boot.rb to
see all that it loads for a full fledged mvc app. its pretty explicit and lean
if you ask me.

if are talking about server resource then you probably referring to the web
server. for which we have ‘puma’ and it is also incredibly light and fast.
much lighter than a php stack running Apache and mod_php for sure.

but i see you compared to Go to which we have no comparison Go will run
circles around Ruby. but Go is not really a well suited environment for web
applications yet so ill just leave it at that.

