
Crystal: the programming language - robin_reala
http://crystal-lang.org/
======
programminggeek
There are a couple of features I'd love Crystal to have, but I might be in the
minority. One, immutability by default, or rather, make immutability more the
rule than the exception. Two, type checked named parameters/keyword arguments.
Yes they are verbose, but they make it much more clear what the code is doing
upon 2nd, 3rd,..... 100th reading than something like MyObject.method(a, b, 1,
zurb, foobar, false, -1, "bob"), where the order is important and the
variables don't ned to be well named.

Swift, Kotlin, and Scala seem to be the only significant languages to get both
features pretty close to what I'd want. Otherwise, I don't see much in the
language space that scratches that itch.

Those three languages seem to be the closest to getting "the future" right
when it comes to the "next generation" of languages - functional, object
oriented, type checked and compiled languages with a bit of dynamic
checking/inference for programmer convenience. Other languages seem to be too
much in other particular directions to get the benefit of different styles
where it makes sense.

I had high hopes for Mirah, but it hasn't really evolved the way I'd hoped.

I don't know if my notion for a language is the right direction for Crystal,
but I'd love it if someone came along and made my "perfect language" for me.
It'd be one less thing to build myself.

~~~
Igglyboo
Curious, I've been hearing a lot lately about functional languages and
immutability and wasn't quite sure how it worked. I agree with it in premise
but it seems like all these immutable data structures introduce massive
overhead.

What is going on behind the scenes when I modify a single value in an array
with 10k members? Surely it's not going to create an entirely new array.

~~~
programminggeek
It might do that wildly inefficient thing...

Or, you might do something where you have a list of pointers, and you point at
a different value instead of mutating an existing value.

I haven't dug into the details of how immutable data structures can be made to
work efficiently, but part of the charm is that in many cases you don't mutate
the array at all. What I mean is, there are certain behaviors around mutation
that programmers do because they can.

When you take away the ability to mutate data, you design differently and
without side effects. All of a sudden testing becomes easier, faster, cheaper
for large parts of your codebase. You have simpler solutions that are
potentially easier to reason about because the complex (and sometimes elegant)
solutions aren't so readily available.

A few talks that are around this style of thinking:

[https://www.destroyallsoftware.com/talks/boundaries](https://www.destroyallsoftware.com/talks/boundaries)

[https://www.youtube.com/watch?v=WpkDN78P884](https://www.youtube.com/watch?v=WpkDN78P884)

[https://www.youtube.com/watch?v=tq5SQ4W3gRI](https://www.youtube.com/watch?v=tq5SQ4W3gRI)

[http://www.infoq.com/presentations/Simple-Made-
Easy](http://www.infoq.com/presentations/Simple-Made-Easy)

Boundaries are good, values are good, simple things that work together are
good. The more we can take the good parts and form them together into a
cohesive language/framework/platform, the better our software will be.

------
Mithaldu
I may be perceiving this wrong, but it appears to me that in more recently
newly created languages lexical scoping and explicit variable declaration are
conspicuously absent. In the face of these features' positive effects on
software quality and maintainability, i have to suspect that their lack is
usually a conscious decision.

However, probably due to my inexperience in creating programming languages, i
cannot think of reasons for this kind of decisions.

What could these be?

~~~
chrisseaton
I can't think of any recently-designed languages that do not have lexical
scoping - can you?

I'm not sure I can think of any languages at all that have dynamic scoping
since the early lisps.

~~~
marktangotango
Perl my/our/local is the most unusual scoping I know of[1]. But still lexical,
except maybe local which is more like an alias?

[1]
[http://www.perlmonks.org/?node_id=66677](http://www.perlmonks.org/?node_id=66677)

~~~
tripa
my is lexical, our is global, local is dynamic.

~~~
tripa
I'll premptively add a bit of precision before a pedant comes along: my is
lexical all the way; our defines a lexical binding over a global variable, and
local defines a dynamic binding (of lexical extent) over a global.

~~~
AnimalMuppet
Are you sure the pedant hasn't already arrived? ;-)

------
vortico
I am excited to see new programming languages like this. I can name 100 duck
typed, interpreted, GC'd languages, but only half a dozen native compilers for
modern languages. Native binaries are much easier to deploy on consumer's
desktops than bytecode or source code requiring >50MB VMs, and the code tends
to be much more rigid and rigorous with a statically typed language like this.

I haven't downloaded the compiler yet, but here are a few things I like after
reading the documentation.

\- The C bindings are nice and simple in Crystal, with full support for
structures and data types,

\- "Globally named" symbols are a really great idea, especially in native
binary when compiled to Int32's,

\- OOP support seems polished with full support for encapsulation,

\- Basic control structures and scope are also polished and familiar, while
leaving beind the nasty parts from Ruby (i.e. `for do` vs `for`, Matz's regret
for `do ... while`, etc)

\- --hierarchy. Why haven't I seen a compiler support this by now?

A final point: "Everything is an object" and C-like efficiency seems
paradoxical, but I'll look more into this. Objects may be abstracted by the
compiler, but once compiled behave like any ole' statically typed system.

~~~
cremno
>Matz's regret for `do ... while`

Huh? Do you mean [http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-
core/...](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/6745)?
It's still there: [http://crystal-
lang.org/docs/syntax_and_semantics/while.html](http://crystal-
lang.org/docs/syntax_and_semantics/while.html)

Edit: Ah, the behavior of the while modifier is different in Crystal.

~~~
vortico
I was referring to the veil of deprecation over `do end while` by Matz's
comment that you've linked, but as long as Crystal endorses it, is it fine
with me.

~~~
asterite
We actually started by copying ruby's syntax and semantic, including the `do
end while`. But a long time ago we started to diverge from it. We are also not
sure about this "feature" and we still have time to remove it from the
language :-) . It's true that a simple `while ... break if ... end` is enough.

Edit: I also misunderstood the comment. In Crystal `exp while cond` and `begin
exp end while cond` are the same.

------
agentultra
The example sieve does a bit of extra work. You can start at

    
    
        candidate**2
    

instead of

    
    
        candidate*2
    

since the composite `2` has already been removed in a previous iteration.

Nice work.

------
elwell
Already has GitHub color coding?

[https://github.com/manastech/crystal](https://github.com/manastech/crystal)

~~~
gjtorikian
The first lexer was added over a year ago:
[https://github.com/github/linguist/pull/678](https://github.com/github/linguist/pull/678)

------
weatherlight
Are there any bench marks comparing it to ruby, c or even mruby?

~~~
asterite
Yes. There are some here:

[https://github.com/kostya/benchmarks](https://github.com/kostya/benchmarks)

Here's another one:

[https://github.com/nsf/pnoise](https://github.com/nsf/pnoise)

And then in the samples directory (
[https://github.com/manastech/crystal/tree/master/samples](https://github.com/manastech/crystal/tree/master/samples)
) there are some more but without time results (but you can try them
yourself).

------
mholmes680
Groovy : Java :: Crystal : C ?

~~~
vorg
Although Groovy 2 brought type inference it isn't used much, so Groovy's main
use case is as a dynamically typed language as was originally intended by its
creator.

------
kiraken
Don't we already have more than enough programming languages? I looked through
the intro and this language introduces nothing new. Your time would have been
better wasted on building a framework for an already established language.
Sorry for putting you down, consider it tough love

~~~
cgh
It has the syntax of a dynamic language, type inference, interfaces with C
easily and compiles to native code. Is there a long list of languages with
those features that I'm unaware of? Nimrod springs to mind.

~~~
Pxtl
Sounds very similar to Go, though.

