Settings

Theme

A new year resolution to have Crystal reach the 1.0 milestone in 2017

crystal-lang.org

130 points by spalladino2 9 years ago · 78 comments

Reader

andyfleming 9 years ago

I think Crystal is a very practical language to work in for web. It doesn't have the polish of Go (yet), but it feels more approachable to me. Rust has its place with low-level systems work, but Crystal gives you something that is reasonable to write and still compiles to a binary. In turn, it performs well and is easy to distribute, deploy, and containerize as well.

  • RX14 9 years ago

    I think crystal has several advantages over go, first of which is the type inferrence. In crystal, you never specify types in method bodies. You don't have to specify types in method arguments either. Type unions are really expressive, and handing nil is as easy as `raise/return unless nillable_variable`.

    Second of which is `yield`, ruby's extremely powerful way of passing code to functions. In crystal, functions which take blocks are actually inlined, meaning that abstractions such as `3.times {}` or `5.upto(20, step: 5) { |i| ... }` have zero cost. For example, take a look at how simple the HTTP server example is on the crystal homepage. Very useful for building DSLs.

    Macros are another powerful (but hopefully not overused) tool for building clean programs. Crystal macros receive AST nodes but return source code as text. This text is then compiled and placed inside the program. This may sound like it would have the disadvantages of C macros, but as they're more integrated into the language, the compiler can insert the generated AST of the compiled macro into the original AST in a clean way. Using "dumb" text templating has several advantages: it's really easy to use because you're essentially just writing crystal code, and it's powerful as you get access to the AST. It also has the advantage that it's actually quite hard to make large scale modifications to a method body, preventing a lot of the silly macro uses.

    • obl 9 years ago

      Text templating can't possibly be better than (quasi)quoting.

      > you're essentially just writing crystal code

      even more so in a quasiquote, since you don't have to worry about adding extraneous parenthesis "just in case" etc.

      Having structured input is already way better than full token-level solutions like C, but why not go all the way ?

    • chrisseaton 9 years ago

      Ruby implementations with a JIT can also inline blocks, of course.

      • RX14 9 years ago

        Of course they can, however I was describing the advantages of crystal as opposed to go.

        Crystal vs Ruby don't really compete in the same way Crystal and Go do, it's very much a dynamic vs static typing split. Crystal is in general a bit more cleaned up but Ruby's community is much larger.

      • gravypod 9 years ago

        That still comes at a cost. The macro/lazyeval approch is usually seen as "zero cost" because the JIT engine usually only spends time inlining if it's a hot block.

  • dingdingdang 9 years ago

    I agree with this sentiment, Crystal, for the better, lacks Go's obsession with odd tooling conventions (see vendoring saga) while retaining the ease of use when it comes to actual programming and cross compilation capability.

  • lmm 9 years ago

    If I'm already using, say, OCaml, why would I want to switch to Crystal? (assuming that multicore takes the same amount of time to arrive in each). Whenever I've read about Crystal it sounds like a broadly sensible language, but it doesn't sound like it brings anything new to the table - in which case I'll favour the more mature language with the bigger library/tool ecosystem.

    • yxhuvud 9 years ago

      Ruby itself never brought anything new to the table, just a really well polished collection of ideas taken from other languages. Crystal is mostly the same, marrying Ruby stdlib with go channels and compilation to native code.

      • j_s 9 years ago

        Thanks for the summary; helpful as I've not checked out Crystal at all yet. Maybe they can steal it as their everywhere blurb.

    • RX14 9 years ago

      Most of the popular languages over the last 20 years haven't brought anything new to the table, they've just had the right mix of pre-existing features (I use features in a very broad sense to mean any reason why a developer would use it) at the right time.

    • galfarragem 9 years ago

      > it doesn't sound like it brings anything new to the table

      A fast and typed Ruby, isn't it enough? ;)

      • eropple 9 years ago

        It's not a Ruby. It doesn't even pretend to be a Ruby. I mean, to be a Ruby, this needs to work:

            a = Object.new
            list_of_modules.each { |mod| a.extend(mod) }
        
        Ruby cannot be separated from its dynamism and to claim it can is misleading.
      • lmm 9 years ago

        OCaml (well, actually Scala in my case, but I can understand why people wouldn't want to have to use the JVM) is already that, as far as I can see. What is it that Crystal offers that OCaml doesn't?

      • pimeys 9 years ago

        Is this the same with Crystal, as shown in Ruby:

          irb(main):001:0> "".methods.size
          => 170
        
          irb(main):002:0> 0.methods.size
          => 133
        
        If it is, I mean, I don't see it being so fast.
        • yxhuvud 9 years ago

          What on earth has the size of the list of methods to do with performance?

        • _uhtu 9 years ago

          The number of methods in the standard library really doesn't impact performance in a compiled language since you can tree shake the stuff that isn't used. And even if you don't tree shake having lots of methods isn't really a noticable performance loss in compile to binary languages since you don't need to spin up a VM

    • throwaway7645 9 years ago

      I think tho might be easy. OCaml might have OO,but it is meant to be used as FP. The ecosystem isn't honestly that impressive and isn't winning over people from Ruby or Python and isn't going to catch on more than it already has. If Crystal catches even 1/4 of Ruby's base it will be huge. OCaml is hard to get into btw (big language). Crystal looks easy.

    • nickpsecurity 9 years ago

      If you write a FOSS project, more people will help you if it's Scala or Crystal over Ocaml. My guess at a little over 1,000 stars for Ocaml but 7,000 for Crystal. There's that. ;)

      For psychological reasons, things that build on what's familiar get increased adoption. Trend started with C syntax that I can tell.

camus2 9 years ago

Well I hope you succeed. Competition is good and in the "Go" space, there's need to be more competition to demonstrate the technical flaws of Go, or just give an option for those who want to quit an obnoxious and patronizing community. You should really be set on the type system and concurrency by now.

  • pjmlp 9 years ago

    There is no need to demonstrate anything.

    Go is a good enough replacement for C, for user space applications.

    With some improvements, even for more lower level tasks.

    As for the flaws, anyone that had the pleasure to work with the Algol and Wirth family of languages is well aware of them.

    • the_duke 9 years ago

      Go is really more of a Java than a C replacement.

      • FreezerburnV 9 years ago

        This sentiment is actually very interesting to me. I had (/have?) the same kind of sentiment toward Go, but when I spent time playing with it recently I realized just how close to C it actually is. Enough so that when someone says it's a C replacement, I can actually see where they're coming from/somewhat agree with them. And the reason for that is that Go actually seems to follow a lot of C conventions pretty darn closely, and not provide as high level of an interface as Java does. You're much more likely to work in raw "arrays" (aka: slices) in Go than you are in Java, it doesn't have generics, "classes" are structs that are defined very similarly to structs in C, error codes as return values, etc. The main differences that are adding to C as far as I'm currently aware are interfaces, the ability to add a "method" to a type (which is effectively the same as calling a function with a type as the first argument, except in the case of interfaces), and the garbage collector. All of which, to me, feel like a kind of evolution on C. A different path instead of C++ in a way. While people would argue that having a GC ruins what C is good at, it can also be viewed as a version of C that's much more memory safe, while still allowing you to dip into very low level if you need to.

        ...there's probably some other stuff I could say, and probably more coherently, but it's early (for me) and I kind of just wanted to get that thought out there. I hope it's at least a bit thought-provoking, or something. If not, well, my apologies for rambling at you ;)

        • nickpsecurity 9 years ago

          The language was designed by an expert on Wirth-style languages plus the two inventors of C. They wanted to create minimal, useful language based on old techniques with only features they could all agree on. Pike used Oberon-2 back in the day, knowing its advantages. The C inventors naturally wanted it more like C. The result is a merger of these. The concurrency stuff was an exception that came from Limbo language Pike worked on.

          The Wirth languages were categorized by a focus on absolute simplicity and safety with just enough complexity to make building large programs easier. They constantly added or removed features in various language revisions in a search of balance. His main metric was compile time: anything that took too long was kicked out. The result was these languages were easy to learn, compiled fast (100kloc a sec on good machine), rarely crashed, and ran reasonable speed. They had GC's but also allowed manual management. They were objectively better than C language because people could produce correct programs more quickly with same effort put in due to design.

          http://www.projectoberon.com/

          Modula-3, designed at DEC, was probably the best of that line given it's like a safer, simpler C++ with a subset closer to C. Here it is:

          https://en.wikipedia.org/wiki/Modula-3

          Used in SPIN operating system that let you live-load code into the kernel for acceleration safely due to type-safe linking on top of memory-safe interfaces. Quite a few commercial deployments. Didn't take off since C was too popular & programmers only went with C-like alternatives. Lots of vulnerabilities and crashes happened.

          Another alternative was Delphi, which succeeded for a while. Way more productive and crash-resilient than using VC++. It fell away due to C/C++ popularity but Free Pascal community still maintains a variant of it. Their compiler targets a ton of platforms which was common for Pascal.

          http://www.freepascal.org/

          • groovy2shoes 9 years ago

            > The language was designed by an expert on Wirth-style languages plus the two inventors of C.

            Did Dennis Ritchie have a hand in creating Go? I must have missed that.

            While Ken Thompson's earlier B language no doubt had an influence on C, Dennis Ritchie is widely regarded as the creator of C, which is really rather different from B, borrowing more heavily from BCPL and Algol-68. As an early (and heavy) user of C (perhaps the earliest, besides Ritchie himself), I'm willing to concede that he had enough input on C's design to be called a co-designer or co-creator. But which other "inventor of C" played a role in the creation of Go?

            I also find it hard to label Rob Pike as an expert in any kind of language design. An expert in windowing systems and concurrency, perhaps, but language design? Hell, no. Even his earlier design, Newsqueak, was more of an experiment in concurrency than in language design—and it notably was a collaboration with Luca Cardelli, an expert in ML and OOP who also worked on Modula-3, and whose influence can be seen in Modula-3's several very ML-like constructs. Articles like this one[1] by Pike only serve to reinforce my thoughts that he, though a rather smart guy otherwise, is really rather ignorant about language design and about the role of types in programming in general.

            > The Wirth languages ... had GC's but also allowed manual management.

            None of Wirth's languages had GC until Oberon, as far as I'm aware. And spiritual successors by other groups, like Object Pascal and Ada, never really picked up on GC, either (Ada had GC as an optional part of the standard, but was removed in the latest standard because it was so rarely provided by implementations). As far as I can tell, Modula-3 is the only other "Wirth-style" language to provide GC.

            Modula-3 was indeed a great language, and I think it's a real shame that it didn't get picked up more widely. At a time, it had several really solid implementations, and the language's definition is very short while still providing a plethora of useful features for programmers. The silver lining is that it was, at least, a very influential language, despite its limited adoption.

            Oberon, on the other hand, was a very spartan language that offered little in terms of features, and it exhibited that Wirth really didn't grok OOP at the time he designed it (which, if I recall correctly, is something he later admitted, though I'm having trouble finding a citation at the moment). Some of Oberon's issues were fixed in later versions of the language, but some of its issues were also "doubled down" in later versions, as well.

            > Another alternative was Delphi, which succeeded for a while. Way more productive and crash-resilient than using VC++.

            Delphi was indeed a real alternative for a while, and while you're right that it was more productive than VC++, that's not saying much. Later versions of Delphi grew to C++ levels of size, complexity, and hairiness, and that's reflected in Free Pascal's implementation, as well. It's something that I've lamented on more than one occasion because I remember how great it was and feel as though it could still be great with a bit of streamlining.

            [1]: https://commandcenter.blogspot.com/2012/06/less-is-exponenti...

            • pjmlp 9 years ago

              > As far as I can tell, Modula-3 is the only other "Wirth-style" language to provide GC.

              Besides Oberon, there was Oberon-2, Active Oberon, Component Pascal, Zonnon, Modula-2+, Modula-3.

              All of them with roots actually on the Xerox PARC workstation that used Mesa/Cedar.

              • groovy2shoes 9 years ago

                Ah, cool. I wasn't thinking of Oberon-2 or Active Oberon as separate languages when I made that statement. I didn't know Modula-2+ had GC, and was unfamiliar with Component Pascal or Zonnon. Thanks!

                • nickpsecurity 9 years ago

                  Well, he kept changing them enough to break compatibility & even how you express concepts at times. Oberon is both a language and a name for a whole family of languages that represent his people's life-long experimentation with simple, language design.

                  Unlike Cardelli, his weren't ultra-practical but they did try with a commercialized one called Component Pascal. It got significant adoption for a Wirth language along with IDE. As usual, the BNF grammar is pretty small despite its expressive power. It kind of came and went far as adoption but people are still apparently posting to the forum in 2016.

                  https://en.wikipedia.org/wiki/Component_Pascal

                  http://blackboxframework.org/index.php?cID=home,en-us

            • nickpsecurity 9 years ago

              "Did Dennis Ritchie have a hand in creating Go? I must have missed that."

              Oops. You got me on my bad memory there. I misremembered Griesemer. The C language was originally just B modified with structs to try to port UNIX from assembly. Also, the limited keywords & "programmer is in control" philosophy came straight out of B. The details are in this nice Vimeo that traces its development going through papers they presented:

              https://vimeo.com/132192250

              "An expert in windowing systems and concurrency"

              Even if we drop "language" expert, my comment had him bringing in concurrency mainly. I didn't know Cardelli started with Newsqueak, though. Makes sense given stuff as good as Modula-3 rarely comes from a vacuum.

              "Articles like this one[1] by Pike only serve to reinforce my thoughts that he, though a rather smart guy otherwise, is really rather ignorant about language design and about the role of types in programming in general."

              Well, see, it's been given a test. The Concurrent Pascal, Ravenscar, and Eiffel SCOOP approaches to concurrency were all very effective for what they're designed for. I've been sitting on the bench on Go watching it from afar to see what Pike's method does. So far, I see a lot of people griping about concurrency errors that didn't happen in SCOOP. Meanwhile, Rust has improved on things in a new way. Your characterization of him as an experimenter more than an expert may be right.

              "None of Wirth's languages had GC until Oberon, as far as I'm aware. "

              All of his languages except the first two that he started with. They made a lot of languages. It's kind of a strength and weakness of theirs as doubling down on a great one might have accomplished more. Might given Cardelli did without much direct impact.

              "Oberon, on the other hand, was a very spartan language that offered little in terms of features"

              So was early C. It's why I bring up Modula-2 or Oberon in comparisons as nobody is writing or deploying Modula-3 or Ada on a PDP-11. I'm not a fan of Oberon except for bootstrapping better languages or for minimalist hardware. Even then I'm more PreScheme.

              "Later versions of Delphi grew to C++ levels of size, complexity, and hairiness"

              Snowballs rolling into avalanches. Common ill in tech although I think it's human nature or economics more than anything. It takes a cathedral model that prioritizes just right amount of complexity to avoid. I just subseted languages like embedded people do to avoid the shit. Until I had to debug a 3rd party library. (shakes head)

        • pjmlp 9 years ago

          Research Oberon and Modula-3, just as two possible examples.

          You can go even further back into history of computing and check the Mesa/Cedar workstation at Xerox Parc.

        • geodel 9 years ago

          Maybe it makes sense. It is replacement of Java because convenient GC, decent runtime and networking/http/ssl/xml/json libs comes standard. This is where is Java is mostly used as backend server side stuff.

          It is replacement of C as in low memory usage, decent level of control over memory layout, no overengineered abstractions, no classes, no generics, no exceptions, fewer concepts to grasp etc. It does not need VMs and generates executables to directly run on machines.

      • pjmlp 9 years ago

        Not to those of us that enjoyed using OSes like Oberon.

    • mapcars 9 years ago

      >Go is a good enough replacement for C, for user space applications.

      Are you sure you are not describing Rust?

      • nickpsecurity 9 years ago

        Go is based on Oberon: a family of simple, safe languages that were used to write OS's. Started with Modula-2 in Lilith project. At one point, the machines ran ETH University. By Oberon, they got a GC but could also do unsafe manipulations for hardware interfaces or performance. Forced you to put it all in modules declared SYSTEM ("unsafe").

        The neat thing about the OS was that it and its compiler were simple enough for students to understand that they regularly ported or improved it a few months at a time. It's also one of the most, well-documented OS's in existence.

        http://www.projectoberon.com/

        That Go is basically a modified Oberon means Go, currently or with some modification, could be used for low-level, systems code up to operating systems. Even with a GC since the Oberon OS's are written in GC language. Most recent, graphical one is A2 Bluebottle if you want to look it up.

        • groovy2shoes 9 years ago

          Since when is Go "based on Oberon"? Pike himself claims that it was "based on C", with obvious influence from his own work on Squeak and Newsqueak.

          • nickpsecurity 9 years ago

            The last history people here gave me had him describing the joy of programming in the safe, fast Oberon-2. And wanting to re-create that with the new language. Resulting language is very Wirth-like in style, esp simplicity, compile speed focus, and safety. Modified with C syntax, concurrency from Limbo, and I dont recall what else. Clearly way closer to Oberon-2 or Modula's than to BCPL like C copied/extended.

          • pjmlp 9 years ago

            The method definition syntax, package model and unsafe package are taken from Oberon-2.

            You missed that Robert Griesemer is also part of the Go team.

            • groovy2shoes 9 years ago

              I didn't miss that at all. According to Pike, it was actually Griesemer's idea to start with C.

              • pjmlp 9 years ago

                Wasn't aware of it.

                In any case, my view is a bit different, I see Go as a mix of an AOT version of Limbo mixed with bits of Oberon-2.

                • groovy2shoes 9 years ago

                  I definitely "feel" the Limbo influence, but I've not worked with Oberon-2 (only the original Oberon, and only a bit), so I didn't pick up on it. I do "feel" the C influence as well, though.

      • pjmlp 9 years ago

        No, please research Oberon and read the Project Oberon book.

    • camus2 9 years ago

      > As for the flaws, anyone that had the pleasure to work with the Algol and Wirth family of languages is well aware of them.

      I just don't want to have to deal with a bunch of second guessing judgmental jerks anymore. Nobody in the Crystal community is going to go after me for something "not idiomatic" I published.

      • pjmlp 9 years ago

        Go is not on my top 10 languages that I would use, but still I see some value on it being used.

        What I meant with that remark was that those languages already had fast toolchains and were more expressive.

        So in this regard I also appreciate Crystal, specially since RubyMotion decided to focus on mobile.

      • geodel 9 years ago

        Ok, for my purpose I would be far less interest in programing language which has no idioms, no critical feedback, that is basically a mutual admiration society.

ksec 9 years ago

Looking forward to 1.0, and cant wait to see an implementation of Ruby in Crystal, going full circle.

It will still be CRuby, but the "C" is Crystal.

alehander42 9 years ago

Windows support is very important for all kinds of apps and libraries

  • galfarragem 9 years ago

    I didn't 'play' yet with Crystal exactly for that reason: lack of Windows support.

    edit: Windows 7

    • RX14 9 years ago

      If you just want to play with it, and have windows 10, it runs fine in the Linux emulator thingy.

      • throwaway7645 9 years ago

        Having a hacky workaround isn't the same thing as first class support. Bash on Windows 10 is in my mind similar to resorting to Cygwin. No thanks. I despise Windows, but if you have an overbearing IT dept, that's your only option.

        Edit* Just saw where you said "play"

      • devmunchies 9 years ago

        or use docker for windows

    • andyfleming 9 years ago

      Check out the docs, online "playground", and/or test it on a linux VM or droplet!

nailer 9 years ago

How does Crystal handle concurrency?

singularity2001 9 years ago

As stated elsewhere Crystal could become a big success if either * they compile to WebAssembly * they become official 'native ruby' (similar to cython) * they reduce compliation time to under half a minute (to become a template for other languages)

  • RX14 9 years ago

    Compiling to web assembly should actually be quite easy, given llvm's support. The hard part will be porting the standard library to the environment wasm provides.

    We're already well past the point where we could become "native ruby" and I'm glad of that. Ruby has quite a few warts, and I'm glad most of them haven't been copied by crystal.

    Compilation times are already well under a minute for the whole of the crystal compiler itself. It was actually improved quite a bit on Linux in the latest crystal release.

gravypod 9 years ago

This was very good but...

"reach a point where breaking changes to the core of the language are down to a minimum"

I'm very afraid of the word minimum in this context. This is why "no one was ever fired for picking Java".

  • RX14 9 years ago

    I think that's a mistake in the article, we will follow semver after 1.0.0, and we definitely don't want a 2.0.0 less than two years after 1.0.0. I'm sure crystal will provide the same stability guarantees as go and rust.

    • gravypod 9 years ago

      My main concerns are development time and tooling. Crystal looks great and offers some great features that no other native-compiled languages really offer at this time (which is amazing) but I am the kind of person that needs first-class IDE support to take a look. I think crystal would be the perfect platform for some great software development.

      Aside from tooling I need a guarantee that my code, if following all of the best practices, should be compilable from now till the foreseeable future.

    • spalladino2OP 9 years ago

      The idea is to avoid falling into a Python 2 vs 3 situation, by being very careful in how we break compatibility when moving to the next major.

preordained 9 years ago

Wow. I like this. I already like Ruby, so I'm happy to see a language taking after and improving, adding more. This as opposed to "here's a bunch of new synataxes and conventions to keep straight!"

greyman 9 years ago

Can it be used (in the future) to implement cross-platform desktop apps?

  • coldtea 9 years ago

    Not any more than several other languages, because as usual, the show stopper is the lack of decent cross-platform desktop GUI libraries.

    There's QT, which is huge and unwieldily and not so good looking on OS X, GTK+ which is a mess on both Windows and OS X, wxWidgets (based on other libs), and a few fringe, and incomplete libs.

    For one-platform apps, though, or a single backend for multiple platform UI frontends, it will do just fine, provided we get bindings for Cocoa, Windows UI libs, GTK etc.

    • RX14 9 years ago

      But the problem here is not the suitability of languages themselves, the problem is the huge undertaking required to build a gui library which can compete with Qt, gtk etc.

      Crystal at the very least has good support for binding C so maybe this will be the language which finally produces a modern gui toolkit, but with the move towards web apps its becoming increasingly unlikely.

      • coldtea 9 years ago

        >But the problem here is not the suitability of languages themselves, the problem is the huge undertaking required to build a gui library which can compete with Qt, gtk etc.

        Well, the whole Cocoa/QT/WinForms scope might be huge, but we don't even have good minimal UI libs -- e.g. with just the few basic widgets: buttons, text fields, labels, radio buttons, checkboxes, kind of what HTML forms can do -- and only very limited functionality (e.g. no fancy text formatting in the labels or whatever).

        Tons of programs could be GUI-fied with just the above (sort of what Tk does, but decent looking).

        • RX14 9 years ago

          Libui, which was on hn a while ago, looks like the basic minimal cross-platform gui library to me. And that's already got bindings to crystal.. I think most developers are searching for something more.

          • coldtea 9 years ago

            Yep, something exactly like that, with good documentation, and bindings for multiple languages, can go a very long way for lots of apps.

      • gravypod 9 years ago

        It's a huge undertaking because it's an undefined specification. No one really knows what a cross-platform UI library should look like. How do you follow all of the native app standards automatically? How do you handle updates and distrabution?

    • throwaway7645 9 years ago

      Please take a look at the GUI they're designing for Red. It is stupidly powerful and just as easy to use to build everything from simple apps described below to much more complex graphics and works on Windows, OSX, and Linux. They still have a ways to go on several aspects of the language, but it looks really nice.

  • RX14 9 years ago

    Once it has windows support, it would be very possible to build something like ruby's shoes in crystal. In fact we already have libui bindings.

  • truantee 9 years ago

    Crystal binding to Sciter could be a good choice.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection