Live data from Hacker News

Crystal 1.0 – What to expect

crystal-lang.org

181–190 of 351 posts

Re: Crystal 1.0 – What to expect

#181

Earlier quoted context omitted.

> How comes and they don't allow you to optionally provide types in your function/class signatures Perhaps you mean something else, but this is from the book Programming Crystal: > Returning Values > A method returns the value of its last expression, so there’s no need to explicitly return that or declare its type. However, if you want to document or directly control that return type, you can explicitly specify the t…

I think it's great that you can declare types optionally, but I think they are allowed for a different reason: documentation and explicitness. I would like Crystal compiler to take into account such definitions and speed up somehow. I know I am talking without experience, I just feel that coming from Ruby to Rust, declaring types on function definitions is not that much of a hassle.

I don't know if declaring all the types would speed up compilation, but what I do know is that they matter to the code itself. For instance, you can use them to overload methods:

    # version 1:
    def add(x : Int, y : Int)
      x + y
    end

    # version 2:
    def add(x : Number, y : Number)
      x + y
    end

    # version 3:
    def add(x : Number, y : String)
      x.to_s + y # convert a number to a string with to_s method
    end

    # version 4:
    def add(x, y)
      x + y
    end

    # new methods:
    # version 5:
    def add(x : Number, y : Bool)
      y ? x : 0
    end

    # version 6:
    def add(x : String, y : String)
      if x.to_i? && y.to_i?
        add x.to_i, y.to_i # calls version 1
      else
        x + y
      end
    end

    add(2, 3)                # => 5
    add(1.0, 3.14)           # => 4.14
    add("Hello ", "Crystal") # => "Hello Crystal"
    add(42, " times")        # => "42 times"
    add 5, true              # => 5
    add 13, false            # => 0
    add("12", "13")          # => 25
(also from the book)

> I just feel that coming from Ruby to Rust, declaring types on function definitions is not that much of a hassle.

I'm another one who doesn't understand why declaring types is seen as a hassle, but then I went from C# to Ruby so perhaps I was already used to it. Happy to bring a little back!

Re: Crystal 1.0 – What to expect

#182

Earlier quoted context omitted.

Kotlin mostly requires JVM, Crystal does not. With Kotlin native, Kotlin js and most importantly Graal native this is plain wrong.

That is like a hack. You are basically dumping a JIT image to file. That means all sorts of caveats apply such as be real careful about how you use reflection. Also there is no ABI so you cannot use anything like a native DLL. Native compilation while possible is clearly second class on the JVM platform. For Crystal it is first class.

Crystal is also not great for dlls or .so files as the event loop and gc probably wouldn't work well in that scenario.

Re: Crystal 1.0 – What to expect

#183

Earlier quoted context omitted.

C# is tied to .net, and the cross-platform story on that framework is...complicated Java is tied to JVM Swift is tied to MacOS. Of course, with the exception of JVM, they are all nominally "cross-platform" in the OS sense of the word. But I haven't seen any substantial Linux/Mac .Net codebases yet, same with Swift on Windows

C# ? Not complicated at all. In fact it's currently one of the most cross platform language/runtime in existence after .NET Core appeared, and now more than ever with .NET 5.0. I even managed to AOT compile code and run it without a trace of .NET. Just amazing.

C# is a really good language, but I had nothing but problems trying to develop with it on Linux exclusively. MonoDevelop doesn't support Linux anymore since a bunch of proprietary components were added to it (and this isn't even mentioned on its homepage), so you have to use a community fork. That didn't bode well for me. The fork didn't have packages for my distro and I couldn't get it to compile for two hours. VS Code wasn't much different, given I couldn't seem how to get OmniSharp working for my project. Eventually I found the only thing that worked half the time was Rider, which actually allows you to manage NuGet packages but costs $139. And still, I often had to load and unload projects or even create new projects entirely just to get it to find the new assemblies I added.

It left a bad taste, but maybe that was because I wasn't using a distro like Ubuntu.

Re: Crystal 1.0 – What to expect

#184

Crystal has been my language for my passion project ( https://gitlab.com/maxpert/crlocator ). I can tell you the speed and magical ruby syntax is unbelievably good (not for everyone’s taste). I just wish a better IDE support now. Since I’ve used Kotlin I’ve been spoiled by the IDE. But I assume it should be relatively straightforward because it’s all static typed.

[deleted]

Re: Crystal 1.0 – What to expect

#185
I've used Crystal before, I liked a lot except the compilation time. I am excited to try it again, download Crystal + Lucky framework, but seems shards are not updated to 1.0 yet. I'll wait a few weeks before trying again.

Re: Crystal 1.0 – What to expect

#186
post #39

Earlier quoted context omitted.

It has a Nil type, not a Nil Value. So a function might return an Int or a Nil, but if you then try to, say, invoke a function expecting an Int on a Nil, it predictably blows up. An Int cannot be Nil itself.

To expand on that, Crystal's Nil goes hand-in-hand with its union types. So, if you want to allow a function's argument to be either an integer or nil, then the parameter type is "Int | Nil". It's not entirely unlike how algebraic data types with a "None" case work in the ML family of languages.

I think it would be more straightforward to say expressions (/bindings/return types etc) can be null, but not implicitly so, and must be checked for a value before attempting to use the value. Or as a sibling comment said, in TypeScript terms, `strictNullChecks`.

Re: Crystal 1.0 – What to expect

#187

Earlier quoted context omitted.

Ah! I hadn't thought of those, though I think because 3 out of 4 are tied to a specific platform

I think you mean 1 out of 4? Swift is the only one on that list that really feels tied to any particular platform. C# has been extremely portable for years now thanks to .NET Core. Even SQL Server runs on Linux these days, if you really just enjoy spending money. Java has always had a strong focus on portability, of course. Nim... I don't know much about. Doesn't it compile to C? I don't think it intentionally has an…

> C# has been extremely portable for years now thanks to .NET Core. Even SQL Server runs on Linux these days, if you really just enjoy spending money.

My experience with C# and .NET Core on ARM Linux is that it comes with a lot of crashes and segfaults. On x86-64 Linux it works well, though.

Re: Crystal 1.0 – What to expect

#188

Earlier quoted context omitted.

Why Kotlin when you got Swift is an equally valid point. People like choice and for a lot of us, running on the JVM is a non starter. Try creating a small command line tool for a JVM language. You need to distribute a virtual machine with it. You got the overhead of firing up a VM or JIT just for a short lived session. Also JVM gobbles memory. You would not want a system made up of lots of tiny command line tools all…

kotlin/native doesnt require jvm swift support for windows is non-existent

> swift support for windows is non-existent

I was prepared to suggest WSL, but apparently Swift support for Windows is existent[1].

1: https://swift.org/blog/swift-on-windows/

Re: Crystal 1.0 – What to expect

#189

It feels like Crystal it took all the best things from the languages I love, and put them together into one, beautiful language: - Elegance of Ruby - Statically type checked + global type inference - No Nulls - Go-like concurrency - Easy C ffi - High performance I really hope the Crystal succeeds and the language goes mainstream - this release is a huge step forward towards that. Congrats to the Crystal team for reac…

Very well said. Elegance of ruby I think is very important for ruby developers who need a performant typed language.

Why would rubyists need elegance in a different language for perf? Do what everyone else does, and write a C extension.

Re: Crystal 1.0 – What to expect

#190

It feels like Crystal it took all the best things from the languages I love, and put them together into one, beautiful language: - Elegance of Ruby - Statically type checked + global type inference - No Nulls - Go-like concurrency - Easy C ffi - High performance I really hope the Crystal succeeds and the language goes mainstream - this release is a huge step forward towards that. Congrats to the Crystal team for reac…

Fast compilation times are one of the best things from the languages I love. I’d really love to see OCaml get true parallelism, green threads, and a decent HTTP server story. Then, I don’t think I’d look anywhere else.

Are you saying Crystal has fast compile times or that it doesn't? You seem to be saying that it does, that that is one of the things you love about it but others below are saying it is slow.
Post reply on HN