15 ms·
Why Crystal Is My Next Language
- rishav_sharan 8y agoFor those who are interested in Crystal, these are some of the major features currently in dev: 1. Windows support 2. Parallelism 3. New Immix GC Crystal is going to be an insane language in a year's time.
- deleted 8y ago[deleted]
- jpgvm 8y agoAnother language worth considering is Kotlin. You get the JVM ecosystem with a modern syntax. It's a higher investment then Nim/Crystal but also has higher payoff due to existing libraries and peak performance of the JVM.
- iLemming 8y agoKotlin is a language that was created simply to lock you in using Jetbrains products. If you like JVM - Clojure is a perfect fit.
- jpgvm 8y agoI'm not going to list all the ways Kotlin is superior to Clojure for real development but suffice to say the two aren't really comparable when you have a team of programmers with heterogenous backgrounds. However I do want to note that Kotlin having great IDEA integration is not lock-in. You can (and I sometimes do) code Kotlin + gradle with a pretty vanilla vim setup. Clojure has one big advantage and it's also it's biggest weakness. It's a Lisp. I love Lisp's but I would never want to use one in a professional setting.
- lispm 8y agoYou can use Lisp in professional settings. Lisp has been used successfully in teams from 2 to 100 people with source-code bases of upto 10 million lines. The usual things apply: a good team, a good development environment, tests, documentatiom, etc.
- moomin 8y agoFrom a recovering OO developer: one of the things I find funniest now is that OO is constantly treated as a plus in these “why I picked” posts, while I’ve long concluded that the cost of this easy polymorphism is way too high.
- rbosinger 8y agoI would love to see Crystal take off but it seems like some decent funding/backing and then some time to settle from there will be needed. I seriously hope that can happen; but, who knows.
- _RedPanda 8y ago>CPython 3.6.5 128.172 Am I reading this correct? it took CPython 128 seconds for a simple Fibonacci test? Can anybody explain to me why this is so slow?
- icebraining 8y agoFunction calls in CPython are not very fast, and the test makes over 850 million calls.
- sdogruyol 8y agoCrystal is a Ruby inspired compiled language, allowing it to run blazingly fast with a very low memory footprint. It uses LLVM for emitting native code, thus making use of all the optimisations built into the toolchain. Website: https://crystal-lang.org/ https://crystal-lang.org/ Github: https://github.com/crystal-lang/crystal https://github.com/crystal-lang/crystal
- nepeckman 8y agoI feel like the author dismissed Nim pretty unfairly. Github stars and issues are one signal for a project status, but its hardly conclusive. Nim's development has been pretty consistent and is approaching 1.0. Ultimately, a lot of language choice is subjective, but I think anyone looking for a language in the fast-but-expressive category should at least try Nim.
- gtycomb 8y agoI agree. I am taken by surprise at the all-round strong performance of Nim. Python-like syntax, a pleasing type system, efficient compilation and packaging. I am waiting to hear more on this. As I understand it they are a small team too and their implementation is truly worth following up.
- rishav_sharan 8y agoI came to Crystal from Nim. I really like Nim. But I feel that the language maintainers do not have an idea on how to grow the ecosystem. Even after all these years, Nim doesn't have any good web framework. Jester, is the only one I know of has no website of its own and is very lacking in documentation.
- dom96 8y agoHi, one of the Nim core devs here. Any ideas how we can fix that? Crystal has a surprising amount of web frameworks with great marketing behind them. Could that just be because it's a Ruby-like language, and Rubyists are far more interested in web frameworks? That's my theory, but I could be totally wrong. I'd love to know how we could improve here. Perhaps it's because I created a web framework that is good enough (jester) early on and so nobody feels like stepping in with their own implementation. A website for jester would be great and it is on my to-do list, but so are many more things.
- brokencode 8y agoPersonally, the first thing I look at when I look into a new server side language is how it does in benchmarks conpared to other similar languages (such as the TechEmpower benchmarks). I know that those types of benchmarks are flawed in a lot of ways, but performance is probably the only objective way to evaluate a language, and I’m much more likely to learn about a language if it looks like it’s fast. From what I’ve seen for Jester/Nim, it’s not really benchmarked a lot, and it doesn’t seem particularly fast where it is benchmarked. This could perhaps be fixed by better implementations for the benchmarks or some optimization in Jester itself. I think a strong story for performance would go a long way towards improving awareness of Nim. Crystal does very well in such tests, and I think that is one of the most appealing parts of the language. In fact, I evaluated both Nim and Crystal for server side development a while back, and quickly dismissed Nim because it didn’t seem to be all that fast. I eventually dismissed Crystal too because of the compile times and syntax, but I put a lot more time into it.
- briandear 8y agoAs a Rubyist, I was about to jump on the Crystal train, but then server-side Swift started getting really good. Crystal is awesome, but I feel it’s not solving any problem particularly better than Swift. With Swift being compilable even on a Raspberry Pi and of course Linux and Mac, it seems like Crystal is now a solution in search of a problem. Definitely a great language, but probably destined to be relatively niche in production contexts simply because the community is so small and it’s loosely competing against the rapidly maturing Swift world.
- jrs95 8y agoIs server-side Swift really that good now? I’m in the market for a new statically typed language, and it was looking like Java still might be my best option...and I’m really not a huge fan of that.
- nicholasjon 8y agoWhat about Kotlin? (Or were you thinking of avoiding all JVM languages?) We're very happy using it to power our server-side services.
- buremba 8y agoGive Kotlin a shot. It has Swift-like syntax and feature-set, you can also call Java libraries from Kotlin since it's all in JVM.
- Scarbutt 8y agoBesides the JVM and its langs, others with big communities are golang and typescript.
- riku_iki 8y agoThere is also MS stack with C#.
- WoodenChair 8y agoI think whether it's "good" is still to be determined as it evolves. There are three "maturing" Web frameworks that are fairly popular within the Server-side Swift community: Kitura, Perfect, and most popularly Vapor. There are others too. Based on my cursory explorations, I would checkout Vapor first.
- banachtarski 8y agoThe results he got for C and C++ make no sense and I question what optimization flag was actually used if any. From the looks of it, he uses "-O" which is equivalent to "-O1" which is really not the flag you want (this optimizes for both time and code size). *edit: with O2 I get a dramatic improvement and the C and C++ versions compile to essentially the same disassembly. Using O1 is definitely not going to produce an apples to apples comparison.
- fgimian 8y agoThanks so much for your comment. I had actually tried -O3 during my tests and didn't notice a huge difference in this particular example. fots ~ $ gcc -O -o fib fib.c fots ~ $ time ./fib 433494437 real 0m0.749s user 0m0.743s sys 0m0.003s fots ~ $ gcc -O3 -o fib fib.c fots ~ $ time ./fib 433494437 real 0m0.747s user 0m0.742s sys 0m0.003s fots ~ $ gcc -O2 -o fib fib.c fots ~ $ time ./fib 433494437 real 0m0.741s user 0m0.737s sys 0m0.003s Clearly this is just a little mathematical algorithm and more real-world problems would likely produce a more dramatic difference. What sort of differences did you see on your end?
- lallysingh 8y agoHow much optimization do you expect a loop with a simple addition to have? It doesn't seem a representative workload for an optimizer.
- rdc12 8y agoExcept it is not a loop[1], but a non-tail recursive function (with dual calls), if the compiler can optimise that to a loop that is actually impressive. Most likely function call overhead (and in the slower cases, interpreter overhead) is probably what is being measured in the best case. [1] In that it won't be a jump and check style loop.
- mbel 8y ago> Most likely function call overhead Quite likely: https://godbolt.org/g/xGkCyA https://godbolt.org/g/xGkCyA although it really depends on the compiler (gcc is smarter here). He also seems to be benchmarking printing more than anything else (hence the difference between C and C++). Without versions of the compilers and explained methods of measurement, the results posted on the blog are more anecdotal knowledge than any kind of benchmark.
- ryanx435 8y agoWhy is Fibonacci the standard performance test? I want to know how it runs on complex objects with complex computations. Also this entire article seems to be content marketing for crystal. And, oh, btw, crystal isn't windows compatible.
- fgimian 8y agoFor what it's worth, I have zero association with Crystal, but just happen feel that it appeals to me the most. You can see this on my GitHub too, all projects up until a week ago were Python. And I chose Fibonacci as a fun little test which I even stated in the post. It should be obvious that this is not an overall indicator of performance for all use cases. For many of us, Windows isn't our target platform so the Windows compatibility isn't a deal breaker. I understand that this is a big problem for many though and there is evidence that the Crystal team are on it; see https://github.com/crystal-lang/crystal/issues/5430 https://github.com/crystal-lang/crystal/issues/5430. Please don't take the post too seriously, it's not intended to be and clearly everyone will have different preferences and tastes as is the case with anything in life.
- deleted 8y ago[deleted]
- jjtheblunt 8y agoIf it runs in Ubuntu it runs in WSL, yes?
- emmelaich 8y agoYes, Fibonacci is a poor benchmark. It blows up the stack* and doesn't exercise much else. (In a typical naive implementation in a procedural style as demonstrated here)
- cyberferret 8y agoI've been dabbling with Crystal a bit lately, and have been impressed with it, especially the speed and low memory footprint. Still only developing small utility app with it at the moment [0] but eventually might look at creating production API servers with it. [0] - http://devan.blaze.com.au/blog/2017/10/28/racing-along-building-a-telemetry-system-using-crystal-rethinkdb http://devan.blaze.com.au/blog/2017/10/28/racing-along-build...
- freedomben 8y agoIt's just me, but I view the lack of OO features in Elixir as a really good thing. You still have structs and some other OOish type stuff, but the emphasis on composition and modularity has really made Elixir programs a joy to read and understand. The lack of a single binary isn't a fully fair criticism. While technically it is true, it doesn't describe the shipping experience. You will need Erlang installed on the target machine, but using escript you basically ship a "single binary/file" and it includes everything it needs to run. It's quite elegant, and erlang is super easy to install on basically all *nix systems.
- juhatl 8y agoI might've misunderstood what you referred to in this particular case, but you generally don't need to even have Erlang installed on the target machine to ship Elixir (and/or Erlang) applications. Tools like Distillery make it easy (a boolean config value) to include the ERTS with your deployment, leaving you with a single .tar.gz to move to your target environment. The only caveat here is that the build machine and target machine architectures must match.
- freedomben 8y agoVery interesting, thanks! I'll definitely be looking into Distillery a little closer.
- fgimian 8y agoYep, many of my colleagues at work use Elixir in fact and they say the same. Ultimately, I started with C++ ... a long time ago (2001) ... and from day one I learned coding using an object-oriented approach. A lot of this comes down to the fact that one has to really commit to a functional mindset and go all-in like my friends at work have. This wasn't a commitment that I was personally ready to make, especially since all the programming I do at work is in Python and OO-based, and I have limited time to code outside work :) I think that if I was coding a project full-time at work in a functional language, I'd be more inclined to use this paradigm in my own projects. Without a doubt Elixir is a great GREAT choice and has such a mature ecosystem and tried and tested underpinning that I can understand why anyone would choose it for a project that will run in production. The guys at work have been very happy with it so far, and the language is beautiful and easy to read.
- enraged_camel 8y agoI used to like OO, but ever since I got a taste of functional programming with Elixir, I haven’t looked back. It’s a very elegant language and an absolute joy to program in.
- MuffinFlavored 8y agoWhat are your thoughts on Go/Rust? Node.js? Node.js with Typescript?
- dnautics 8y agoTyping is kind of a pain in the butt, it does buy you I would say 20% but when your paradigm is "code the happy path, let it fail if there's a screwup, you'll find it and fix it in another release, it won't bring down the server, the world will still be there", runtime typing errors aren't horrible. Dialyzer for erlang/elixir is quite nice and brings the delta even lower, if you must need type analysis. Go's type system is atrocious, try multiplying a time interval by an user-input integer. You can't do it. That aside, Go is a fairly good programming language, and I especially like using it for CLIs since there's cross platform guarantee.
- barrongineer 8y agoI dunno, to me it makes perfect sense that you would need to convert it to a duration. time.Second * time.Duration(userInputInt)
- dnautics 8y agothe units on that would be time squared. As a scientist, this makes my brain explode. https://en.wikipedia.org/wiki/Dimensional_analysis https://en.wikipedia.org/wiki/Dimensional_analysis For the record, at least two languages, F# (which is statically typed) and Julia (which is strongly typed) do this 100% correctly
- ifightcrime 8y agoI’m confused. How does mypy make python slower? I thought it was “compile time” and doesn’t affect runtime.
- fgimian 8y agoYou're right, this was a mistake on my part. I'll correct this in the post. I have used mypy further since the post was written and it is indeed quite helpful, particularly in --strict mode.
- deathanatos 8y agoI'm not sure what to make of that statement either. It is like saying running a linter on your code makes it slower. It just doesn't make any sense. If the author argued that annotations made the code slower… maybe. CPython exposes them on, e.g., __annotations__, so, conceivably that would slow down function creation and consume more memory, but my guess would be it would be such a tiny difference that would be vastly outweighed by the benefits of having annotations.
- vinceguidry 8y agoI'm often curious as to what people are doing that makes them really think they need to venture outside their chosen scripting language. I use Ruby thinking I'll 'drop to Rust/Crystal' whenever I need to do something "serious", but that need never seems to manifest. Whatever I code in Ruby seems to just do the job and I can solve perf issues with asynchronous constructs like a jobs server, or something like caching. At this point I'm really starting to wonder if Ruby really is the One True Language and everyone's going to be using it in 100 years. Like how PG thought Arc would be the hundred-year language. Does static typing really offer that much more over dynamic? I'm not at all convinced that it does, when you get right down to it. Once Ruby gets a built-in typing system, we'll get to answer that question. I do believe that Ruby will eventually solve its perf problem and once it does, its pleasing syntax and semantics will just draw everyone back to it the same way it did the first time.
- nlh 8y agoI hear you, and I too love Ruby, and I too have yet to actually need the performance benefits of Crystal. But man, you don't realize how awesome static typing is until you actually start using it. There are whole classes of bugs that just get nixed before the program even runs. It makes you think more about how to structure things, how you're passing arguments, how you use variables, etc. Now maybe you're really really really good w/ Ruby and you don't make those mistakes anymore, but for an "advanced beginner" like myself, it's really helpful.
- vidarh 8y agoI came to Ruby from 20 years of working in statically typed languages, and I think it largely boils down to how you're used to working. E.g. you need test either way, and properly written tests reveal most of the same typing issues static typing does. I'd enjoy static typing if I didn't have to sacrifice the flexibility of Ruby, but so far I've yet to see a system with good-enough type inference to make up for the extra ceremony. I hope that will eventually change, but what I've seen of Crystal is not it.
- 8y ago
- bhuga 8y agoCrystal looks great in many ways, but it's hard to go all-in with a new language that lacks parallel processing. Go, Elixir, and Rust all have great concurrency stories, and their adoption has a lot to do with that. It is a gorgeous language, though, with a very easy to read syntax. I'd love using it if it had something like goroutines, which would look great with its block syntax. Good luck to the team working on it; I hope it's a contender.
- hamandcheese 8y agoDo you need truly parallel processing? Crystal already has a great concurrency model, it’s just not parallel yet.
- fgimian 8y agoYep, this is true. I'm hopeful that this will come soon :)
- yxhuvud 8y agoThis seems a bit confused. You complain about parallelism, but then raise other languages for their concurrency stories. Concurrency is not dependent on parallelism and indeed Crystal do have a nice concurrency story with fibers and channels that perform pretty well.
- kodablah 8y agoIt's like a language was picked first and then the blog written backwards to come to the conclusion. So there's some languages in bullets and subjective pieces that are reasons not to use them. I can do that with Crystal too...it doesn't even support one of the most popular OS's natively. I mean, the author says C++ is a better language than Go, that Google is the ultimate reason for success, and that Go takes us back to C. That doesn't even make any sense. "doesn't seem to click to me...generally didn't feel...feel the language is rough" etc. How about just use the best language for the problem, instead of choosing the language before the project. As I've mentioned on many of these language-comparison posts (more like tweets) these days, just ignore them and remain wise to your problem space. They are very juvenile.
- hasahmed 8y agoWhile your grievances are valid, I feel like you're missing the point. Or perhaps you think of programming than he does. It is certainly true that in a situation where all you want to do is get a task done, then what you should really think about is the best tool for completing the task (sometimes its a spreadsheet but programmers will often go for a little python instead). But in the case where your just programming for the sake of programming. Where programming is the ends and the problem you're solving is the means, this is where the nit-picky language comparisons blogs I think start to happen and I think its great.
- fgimian 8y agoYou make a fair point and I totally respect your opinion. I was ultimately looking for a versatile language that I could use for my personal projects outside of work and thus I was indeed trying to find a single language that could do everything I wanted. Up until this point, that language has been Python. Go is clearly sufficient for many very successful and amazing projects (many of which I use daily, like Hugo, Terraform, Docker .etc), so developers can still produce excellent tools with its limitations. But in saying that, the language is not for me, and that's okay; if it works for someone else, then that's okay too. Go does lack various features that many developers want, including me. Fun fact, the blog post was generated by Hugo ... which is written in Go :) With regards to Nim, yes, my experience with Nim is limited and I am still hoping to learn it further and do a more thorough evaluation. Hopefully I'll spend a good amount of time with Nim in the future to give it more of a fair go.
- fiatjaf 8y agoWe support Crystal at http://fiatjaf.alhur.es/module-linker/#/crystal http://fiatjaf.alhur.es/module-linker/#/crystal!
- fgimian 8y agoHey guys, thanks for reading my blog post and posting it on Hacker News. :) It was just an informal brain dump for me and nothing too serious, so please don't take anything to heart. And indeed, I have only spent a limited amount of time with the other languages on my list. I still intend to keep a close eye on them all as time goes on. I'll try to respond to various comments :) Update: Hacker News is rate limiting me, sorry folks. I'll try again to post some replies in a little while.
- rbosinger 8y agoThanks for posting! The crowd can get harsh and maybe not everyone realizes that making it onto the HN front page briefly != "This is proven research and you should all listen to me right now". Blogging can be about learning and brain dumping and, IMO, you should carry on doing so.
- fgimian 8y agoThanks a lot for the encouragement, it means a lot :) It is tough to read criticism but it's always a good opportunity to learn. The comment about mypy for example was correct and I'm pretty sure I'll be trying it out on my next Python project. I've updated the blog post with minor amendments and corrections based on the feedback here. Indeed this was my first time on HN (which took me by surprise) :)
- ilurkedhere 8y agoThanks. Next time I write a Fibonacci function, this will surely be a great resource.
- emmelaich 8y agoMaybe it's because I learned Ruby after Perl and Python (and C and C++ for that matter), but I find it too quirky. e.g. These three expressions have three different values: 1 + 2 + 3 + 4 (1 + 2 + 3 + 4) 1 + 2 + 3 + 4 3, 7 and 10 respectively. Because newline is equivalent to semicolon and Ruby allows void expressions. I just tested Crystal and it does the same.
- vidarh 8y agoNewline is not equivalent to semicolon (or your last example would fail), but Ruby treats a newline as terminating an expression if in a production in the grammar where terminating the expression is valid. In terms of "void", Ruby has no such thing - every expression has a value, though that value can be nil (and somewhat confusingly "( )" is an expression that evaluates to nil). So your first example is two expressions, and evaluates to 7 when the whole thing is evaluated, not 3 - if you evaluate it in irb etc. you might see 3 because the first expressions is itself complete, and so will cause output. Your second example is a list of the expressions "1 + 2" and "3+4", which evaluates to 7, because as for the first example, the last expression evaluated is what will be returned outside of a read-eval loop like in irb. The last example is a single expression because "1 + 2 +" is a syntax error on its own. I can understand you find it quirky, but you generally only need to consider that if you want to break up an expression you need to ensure it does not stand on its own.
- emmelaich 8y agoOK, newline is not equivalent to semicolon but I could be forgiven for inferring that from the documentation. e.g. "an expression is terminated with a newline or semicolon" (https://www.cs.auckland.ac.nz/references/ruby/doc_bundle/Manual/man-1.4/syntax.html#program https://www.cs.auckland.ac.nz/references/ruby/doc_bundle/Man...) Re "void" I'm referring to rubocop warnings like "Operator + used in void context." Here's another oddity; irb behaves differently for some expressions. not_defined = "#{not_defined}" => "" :-/ Anyway, the parens things bothers me the most. In most (all?) other languages, putting parens around a multiline expression would make it one atomic expression.
- daniel-levin 8y agoI think this thread has no shortage of criticisms, but too many are uninformed. The blog post doesn't mention these important things: Package management (from [0]): "Crystal libraries are packed as Shards, and distributed via Git without needing a centralised repository. Built in commands allow dependencies to be easily specified through a YAML file and fetched from their respective repositories." Concurrency (from [0]): "Crystal uses green threads, called fibers, to achieve concurrency. Fibers communicate with each other using channels, as in Go or Clojure, without having to turn to shared memory or locks." [0] https://crystal-lang.org/ https://crystal-lang.org/
- INTPenis 8y agoIs this the language of 2018? Will this join the ranks of Julia, Rust, Go and the others? I'm skeptical because the last few years I've seen these trends come and go on HN. They do nothing but scatter my focus. I've learned to ignore them now though.
- stealthmodeclan 8y agoWhen i chose a programming language, here is what i look for: 1. Amount of things I've to learn to completely utilized 100% features of the language. 2. Availability of well supported packages for stuff like elastic search, stripe, postgres etc... 3. Ease of making a function asynchronous. I love how go routines make it trivial and hated pythons way. 4. IDE and debugger: I am using goland now, and it is magical. GO has provided me everything, finally i can focus on building my product.
- st1ck 8y agoI'd suggest giving a try to data types + type classes as opposed to OOP. E.g. Haskell and Rust. Or OCaml, F# or Scala for combination of OOP + functional style.
- mromanuk 8y agoRunning the same algorithm in my system, C/C++ with -O3 are almost equivalent, and Crystal too: Clang C++ 1.069s C++ 4.2.1 1.075s Crystal 1.082s But using a different algorithm (non–recursive) in C++ (http://rextester.com/discussion/OGIF47151/fibonacci http://rextester.com/discussion/OGIF47151/fibonacci) you can achieve C++ 4.2.1 0.005s someone should port it to Crystal :)