Live data from Hacker News

The Crystal Programming Language

crystal-lang.org

131–140 of 180 posts

Re: The Crystal Programming Language

#131
post #124

I'm a go user right now, but I really want to ditch it because I'm in total disarray with the way the go language is managed and the deafness of the go team. Been looking at D,Nim and Crystal. - D is neat but I'm not interested at all in unsafe stuffs and don't want to have to debug programs or 3rd party libs that relies on that, I want a safe language. - Nim looks really good, although some features like (foo_bar =…

Have you looked at the new generation languages on the JVM such as Kotlin or Ceylon?

Re: The Crystal Programming Language

#132

I'm looking for something beautiful like Ruby but fast like Go. Do you think Crystal fits this bill? Also, are there packages/libs/gems for Crystal? What are they called? What do I google for? One of the major reasons why I dumped Go is that it's just too verbose and makes me write too much boilerplate code. I want to sort a collection and I have to write the same algorithm every single time for every single type. It…

You're looking for Scala. The "good parts".

Still looking for them ;)

Re: The Crystal Programming Language

#133
post #35

Earlier quoted context omitted.

How do you model a "zero or one" relationship without null? Maybe your answer is "with Optional" (or Option, or Maybe). We just choose to use union types and have "Nil | T" (Nil or T) be the same as "Option(T)" in other languages.

Yes, Maybe (Optional) is the way to go. The difference is, with nil you basically make every type optional allowing it to have nil as a value.

It's ONE way to go. There are others.

Sum types supported in the language such as in Ceylon is another one.

And yet another one is safe dereferencing operators (?.) such as in Kotlin.

Re: The Crystal Programming Language

#134

Earlier quoted context omitted.

An ambiguous syntax is not elegant to program with. Is this a variable reference? Is it a method call? I dunno!

Wait - are we talking C/C++ here? where a function call, a variable declaration, an expression cast all look identical?

You are probably talking about C++, not C, unless those look identical to you:

    foo();
    int foo;
    (int)foo;

Re: The Crystal Programming Language

#135
post #124

I'm a go user right now, but I really want to ditch it because I'm in total disarray with the way the go language is managed and the deafness of the go team. Been looking at D,Nim and Crystal. - D is neat but I'm not interested at all in unsafe stuffs and don't want to have to debug programs or 3rd party libs that relies on that, I want a safe language. - Nim looks really good, although some features like (foo_bar =…

I am assuming your requirements are statically typed with GC, no separate VM, and lightweight runtime. One language I have been watching with a keen eye lately is Pony[1] though the docs are not quite complete.

1 - http://ponylang.org/

Re: The Crystal Programming Language

#136

I'm looking for something beautiful like Ruby but fast like Go. Do you think Crystal fits this bill? Also, are there packages/libs/gems for Crystal? What are they called? What do I google for? One of the major reasons why I dumped Go is that it's just too verbose and makes me write too much boilerplate code. I want to sort a collection and I have to write the same algorithm every single time for every single type. It…

> I'm looking for something beautiful like Ruby but fast like Go. Have you tried InfraRuby? InfraRuby is a compiler and runtime for statically typed Ruby: http://infraruby.com/blog/why-infraruby

What makes InfraRuby better than Crystal (or vis-versa)?

Re: The Crystal Programming Language

#137

Earlier quoted context omitted.

> I'm looking for something beautiful like Ruby but fast like Go. Have you tried InfraRuby? InfraRuby is a compiler and runtime for statically typed Ruby: http://infraruby.com/blog/why-infraruby

What makes InfraRuby better than Crystal (or vis-versa)?

InfraRuby code runs in Ruby interpreters.

Re: The Crystal Programming Language

#139
post #35

Earlier quoted context omitted.

Yes, Maybe (Optional) is the way to go. The difference is, with nil you basically make every type optional allowing it to have nil as a value.

Well, in Crystal Nil is a separate type that can be combined with others. But, say, a String is always a String, it doesn't implicitly have the Nil type. Same goes with every other type. Maybe you are thinking of Java/C#, where reference types can also be null, but this is not true in Crystal. It's also in a way similar (but not quite) to Swift, where optional types are different than types that can't be null.

It's a nice approach, I like it. There is a difference between Option[T] and (T | Nil) that's worth mentioning, however.

Option[T]'s are composable. For example, let's say we have a "get" method to get the value for a given key, whose type looks like:

    get :: String -> (T | Nil)
If we were using Option[T]'s, it would look like:

    get :: String -> Option[T]
So let's say we have a map, and want to lookup a key (syntax is made-up):

    let m: Map[String,(Int | Nil)] = make_some_map()
    let result: (Int | Nil) = m.get("some-key")
If result is nil, was the value of the key nil, or was the key not in the map?

With Option[T]:

    let m: Map[String,Option[Int]] = make_some_map()
    let result: Option[Option[Int]] = m.get("some-key")
Here result will either be None, in which case the key wasn't in the map, or Some(None), which means the value of the key was None.

So there is an observable and potentially useful difference between (T | Nil) and Option[T].

Re: The Crystal Programming Language

#140

Earlier quoted context omitted.

InfraRuby code runs in Ruby interpreters.

Cool. I assume that makes interop with Ruby easier?

Yes! Ruby language features supported by InfraRuby have the same behavior as Ruby interpreters.

InfraRuby projects are created with rake tasks to run your code with either the InfraRuby runtime or Ruby interpreters. You could implement a file format or protocol in InfraRuby, and use that code in a Ruby project too. You could use Ruby interpreters for development and the InfraRuby runtime for production.

And if you decide that InfraRuby is not for you then you can take your code with you!

Post reply on HN