12 ms·
Crystal in Production: Diploid
- sdogruyol 9y 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. I've been using Crystal for more than 2 years have some projects in production. Can't wait for 1.0 :)
- vasilakisfil 9y agoWe have been using kemal in small projects and we are super happy with it. In my company that I am working for we are evaluating crystal and elixir as the next language to start investing/developing (we are on Ruby/Rails now). 2 things that crystal is missing to clearly win this internal battle: * immaturity in terms of the ecosystem (libs, frameworks, best practices etc) which will be solved in 1-2 years * coming from Ruby I am wondering how powerful its metaprogramming capabilities are. In Ruby, using metaprogramming alcohol I can save tons of time by cutting off code and creating human friendly, clean interfaces that otherwise would require a lot of code. How powerful are macros compared to Ruby's meta capabilities where you can do pretty much anything? On the bright side (in regards with elixir comparison) it has great type system that would save us from tons of bugs, it's more speedy and transition from Ruby would be slightly easier.
- paulcsmith 9y agoI've been working on https://luckyframework.org https://luckyframework.org and I can say that meta programming is extremely powerful and much easier for me to use than either Ruby or Elixir. You can see a bit of what the macro system enables here: https://robots.thoughtbot.com/lucky-an-experimental-new-web-framework-by-thoughtbot https://robots.thoughtbot.com/lucky-an-experimental-new-web-... It generates a bunch of query methods and type specific querying. Without the macro system this would have been impossible.
- deleted 9y ago[deleted]
- vidarh 9y ago> You can see a bit of what the macro system enables here The first thing that struck me about this post is that it is a good illustration for why dynamic-typing people and static-typing people often butt heads: Most static typing we see is shallow like this, where the concern is to shove data into an unstructured object like a String, and the problem is something trivial. In this case, String? solves the immediate problem of whether or not the value is really nil, but it fails to consider other aspects: - Are you really intending to remove the country code from just US numbers? Or all North American ones? Quite possibly you're ok with stripping it from all North American ones rather than just US ones, but if not (e.g. because you later use the presence or absence of a country code to differentiate on billing), it does the wrong thing - Does the code otherwise enforce a format where "+" can not appear elsewhere? (because someone e.g. decided to use it as a non-standard separator) Does it ensure nobody has input country codes without a "+"? (I've lost count of the number of times I've seen just "1" or (1)). Does it ensure nobody has used spaces? ("+ 1"). What about the number after that - it does nothing to prevent the returned local number from having consistent formatting. Maybe this is all ok in the code you looked at and the data is guaranteed to only ever have "+1" and be nicely formatted when you strip it. But it is a really bad way of selling static typing as a feature of the framework, as my first reaction is "but it gives me nothing, as there are all kinds of other checks I also need to do". Which means either modelling the type of the data much more precisely - which I can do with or without static typing - and/or building a test suite that includes testing any places where data can get put into that table in the first place. In both cases the kind of problems above tends to fall away with little to no effort. I'm all for typing used for data validation, but an example showing what more precise modelling would look like would be a lot more convincing. E.g. I detest Haskell syntax, but one of the strengths of static typing as Haskell developers tends to apply it, is that there tends to be a lot more focus on the power that comes from more precisely modelling the data.
- paulcsmith 9y agoTL;DR I totally agree. This can be done with Crystal and Lucky but I wanted to keep the example simple. I totally agree with your sentiment and you have a lot of great points. This post was not meant to get too deep into things right off the bat, so it left off a lot of this stuff. In this case the phone number always has a country code with +1 because we have a validation that ensures it won't make it into the database without it. We also only accept US country codes in the validation. I get your point though that just having a `String` doesn't really guarantee that those validations took place, luckily, LuckyRecord has the idea of custom types that can define their own casting and validation behavior. So we could have done this: ``` field phone : UnitedStatesPhoneNumber? ``` And it would validate that the string param is a valid US number before saving. It would also do that for queries and you could add whatever other type specific methods you want to it. so you could do ``` def formatted_fax_number phone.try { |number| number.without_country_code } end ``` But like I said, I think this is fitting for a whole separate post, rather than an intro style post :D
- wiremine 9y agoWould love to hear your take on the good and bad parts of Crystal. Been toying around with it for a few small things, and been following the blog... would love to hear more input from users. :-)
- nurettin 9y agoWould love to have a nokogiri-level xpath or css3 selector capabilities. I'm up to my neck with projects, but this looks like a good start: https://github.com/jgehring/hcxselect/tree/83d3edaa8a6944d20c9835889ca7cf9a72f994ef https://github.com/jgehring/hcxselect/tree/83d3edaa8a6944d20...
- RX14 9y agoWe have libxml2 bound in the stdlib with xpath support, do you need more?
- ricardobeat 9y agoThis shard implements a CSS selector API on top of an html parser: https://github.com/kostya/modest https://github.com/kostya/modest
- RX14 9y agoIf only it was compatible with the existing XML interface...
- cel1ne 9y agoEverytime I read a HN comment claiming a language to be „blazingly“ fast, i wish they posted a link to statistically sound benchmarks, including vm-warmup, GC collection times, etc. Otherwise I just throw these adjectives away. I argue a new compiler/interpreter will always lose against the JVM, which has thousands of man hours of optimization built-in. The JVM in turn will always lose against a clever memory-conscious lowlevel-implementation in Rust or C or assembler. Please don‘t advertise speed without any studies or comparison to back up that claim.
- RX14 9y agoWe compile using LLVM, which has had many many man years put into it. Our GC is bdwgc, which while generic and conservative has also had a lot of optimization put into it and it works very well. We don't pretend to be a mature language with even so much as predictable performance characteristics but the "blazing fast" statement is there to indicate we're very much closer to C performance than even go is typically.
- pjmlp 9y agoEverytime I read such comment in HN, I smile and remember the days C programms on 8 bit micros and later MS-DOS, were made of 80% inline Assembly statements, because the compilers were quite lousy. Fran Allen is the opinion that the adoption of C delayed the field of compiler optimizations research back to pre-history (Coders at Work). It took 40 years of optimization research and clever use of UB defined in the standard, for C compilers to achieve the code quality generation they have nowadys.
- groovy2shoes 9y ago> Fran Allen is the opinion that the adoption of C delayed the field of compiler optimizations research back to pre-history (Coders at Work). Yes! The entire book is wonderful, but as a compiler writer myself, Fran's interview really stuck with me. The relevant passage, for the curious: ——— Seibel: When do you think was the last time that you programmed? Allen: Oh, it was quite a while ago. I kind of stopped when C came out. That was a big blow. We were making so much good progress on optimizations and transformations. We were getting rid of just one nice problem after another. When C came out, at one of the SIGPLAN compiler conferences, there was a debate between Steve Johnson from Bell Labs, who was supporting C, and one of our people, Bill Harrison, who was working on a project that I had at that time supporting automatic optimization. The nubbin of the debate was Steve's defense of not having to build optimizers anymore because the programmer would take care of it. That it was really a programmer's issue. The motivation for the design of C was three problems they couldn't solve in the high-level languages: One of them was interrupt handling. Another was scheduling resources, taking over the machine and scheduling a process that was in the queue. And a third one was allocating memory. And you couldn't do that from a high-level language. So that was the excuse for C. Seibel: Do you think C is a reasonable language if they had restricted its use to operating-system kernels? Allen: Oh, yeah. That would have been fine. And, in fact, you need to have something like that, something where experts can really fine-tune without big bottlenecks because those are key problems to solve. By 1960, we had a long list of amazing languages: Lisp, APL, Fortran, COBOL, Algol 60. These are higher-level than C. We have seriously regressed, since C developed. C has destroyed our ability to advance the state of the art in automatic optimization, automatic parallelization, automatic mapping of a high-level language to the machine. This is one of the reasons compilers are …[sic] basically not taught much anymore in the colleges and universities. Seibel: Surely there are still courses on building a compiler? Allen: Not in lots of schools. It's shocking. There are still conferences going on, and people doing good algorithms, good work, but the payoff for that is, in my opinion, quite minimal. Because languages like C totally overspecify the solution of problems. Those kinds of languages are what is destroying computer science as a study. ——— (pp. 501-502) I recommend that any programmer who hasn't read this book give it a read. In fact, I think I might give it another read this week :)
- WJW 9y agoCrystal is a super cool project and doing websockets with Kemal (Crystals Sinatra equivalent) was one of the easiest ways of hosting websockets I've encountered so far. That said, I'm eagerly waiting for true paralellism support since the use case we have in mind would greatly benefit from that. Some of the testing tools are also not quite as polished as Rspec (yet).
- cyberferret 9y agoActually, the two projects I am currently working on use Websockets, and for certain, Crystal is the fastest and easiest way to prototype a Websockets server, and then turn it into a production server in quick time.
- sdogruyol 9y agoHere's a great blog post about Kemal and Websockets :) http://kemalcr.com/blog/2016/11/13/benchmarking-and-scaling-websockets-handling-60000-concurrent-connections/ http://kemalcr.com/blog/2016/11/13/benchmarking-and-scaling-...
- sdogruyol 9y agoKemal: Fast, Effective, Simple web framework for Crystal Website: http://kemalcr.com/ http://kemalcr.com/ P.S: I'm the author of Kemal :)
- WJW 9y agoSo cool! I really enjoy working with Kemal. :) The State of Crystal at v0.21 article (https://crystal-lang.org/2017/02/24/state-of-crystal-at-0.21.html https://crystal-lang.org/2017/02/24/state-of-crystal-at-0.21...) stated that multithreading with work stealing was coming "soon" and that you already managed to run kemal in parallel. Can you share anything about the current state of that project?
- sdogruyol 9y agoEven though it's experimental I've successfully compiled Kemal with multi-thread support. The throughput was OK. It's promising and will definitely help CPU bound apps :) You can check the wiki for more info https://github.com/crystal-lang/crystal/wiki/Threads-support https://github.com/crystal-lang/crystal/wiki/Threads-support
- cyberferret 9y agoI've been using Crystal for only a few months, but impressed with its speed and low memory footprint. Starting to build some small services with it now, but using Kemal or the Amber framework, I can see some medium sized projects coming out of it soon. Was a cinch to swap over to it from Ruby. It is a little fussier with type definitions, but I guess that is to be understandable with a compiled system. The third party ecosystem is still a little thin on the ground, or immature, and I hope it will grow. The Crystal community has also been really friendly and responsive. The couple of questions I have asked on Reddit or SO have been answered quickly and with lots of useful info.
- piyushpr134 9y agoCrystal is one of the most exciting new languages out there. I have been using it for my one off tasks at Ola and it works pretty well. It is huge plus point that you have safety harness of statically typed languages and speed comparable to java and scala(unscientific benchmark here https://github.com/kostya/benchmarks https://github.com/kostya/benchmarks)
- humanrebar 9y ago> With Crystal, data scientists could have the ease-of-use of Python/Ruby combined with the performance of C. Big if true. Are there any benchmarks to back up this claim? There is some mention of experiments, but I'm not seeing any numbers or code.
- piyushpr134 9y agoOne is here https://github.com/kostya/benchmarks https://github.com/kostya/benchmarks
- mverzilli2 9y agohttps://manas.tech/blog/2015/10/30/linear-algebra-in-crystal-from-lapack.html https://manas.tech/blog/2015/10/30/linear-algebra-in-crystal...
- interfixus 9y agoI have dedicated this very weekend to digging into Crystal. Uncanny coincidence seeing it popping up here, today of all days. It is a tremendously nice looking language - and I say this as a pythonesque guy who never wrote one line of Ruby. The feeling I get from community and projects is that it's a very up-and-coming thing, about to take off in a major way. There is just too much enthusiasm and too many things done right for Crystal not to earn some solid share within a very foreseeable future.
- moocowtruck 9y agohave you checked out nim? if you're a pythonista you might find it more similar to what you're used to
- interfixus 9y agoI most certainly have. I'm working with Nim at the moment. I really, really like the tooling, the speed, the flexibility, and many aspects of the syntax. I really am getting to dislike the endless complexity - just such a goddamn huge language, with always yet another way to do something - and a lot of the implicit (or so it seems) stuff (I'm not comfortable exporting my procs by placing an asterisk somewhere, and even somewhere so illogical I can never remember where to put it), and not at ease with the weird variable naming and casing conventions. Don't even mention the arrays and the seqs... Taking Crystal for this weekend-spin to see if this is really the direction I should be going.
- jackmott 9y agowelcome to the language vision quest. may you find what you seek. you probably won't!
- dom96 9y agoHey, core developer of Nim here. Thank you for this awesome feedback. It's really great to see that you like so much about Nim. Of course, I am more concerned about the negatives and I would love to do something about them. In general it would be great if you could elaborate on your remarks. Some questions that I have: Are there other complexities in the language that you dislike? Is there something you think Nim would be better without? Some specific remarks and questions: > a lot of the implicit (or so it seems) stuff (I'm not comfortable exporting my procs by placing an asterisk somewhere, and even somewhere so illogical I can never remember where to put it) An easy rule to remember this is "the asterisk goes after the identifier", for example: proc life*() = echo 42 proc identity*[T](x: T): T = return x var ident* = "hello" type World* = object field*: int > not at ease with the weird variable naming and casing conventions What's weird about them? > Don't even mention the arrays and the seqs... Please elaborate on this as well. By the way, you might have done this already but in the future please consider sharing this kind of feedback with myself or somebody else on Nim's team directly (via IRC/Twitter/Gitter/email). It's easy to miss something like this on HN. Please let me know if there is something I could do to make giving feedback easier for everyone, I understand that some people may not feel comfortable coming into Nim's IRC channel and giving criticism that way. It's very valuable to us though, and we don't want it going missing.
- mooreds 9y agoAs mentioned in the article, library support in Crystal is growing but still far from complete. This GitHub repo might be a good place to start searching for useful shards: https://github.com/veelenga/awesome-crystal/blob/master/README.md https://github.com/veelenga/awesome-crystal/blob/master/READ...
- fridgamarator 9y agoalso http://crystalshards.xyz/ http://crystalshards.xyz/
- blunte 9y ago"...OOP. Moving from Ruby to Go sometimes feels like ignoring 20 years of progress made in language design." If OOP is so important to them, why did they bother including Elixir in their list of possibilities? Also, given their problem domain, I'm doubtful of the fit of OOP (vs functional). But regarding Crystal, it is nice to see a potential performant Ruby replacement.
- coldtea 9y ago>Also, given their problem domain, I'm doubtful of the fit of OOP (vs functional). But regarding Crystal, it is nice to see a potential performant Ruby replacement. Part of their problem domain was to easily port their code from Ruby, which would presumably be OOP.
- cyberferret 9y agoHere is another (sort of) real world app I wrote using Crystal and Kemal - a real time race telemetry display app for an F1 racing game [Blog post link] - 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...
- tambourine_man 9y agoHow is the compile time on larger projects?
- faaq 9y agoSee https://groups.google.com/forum/#!topic/crystal-lang/xG5MQXTOyj8 https://groups.google.com/forum/#!topic/crystal-lang/xG5MQXT... and https://github.com/crystal-lang/crystal/issues/4864 https://github.com/crystal-lang/crystal/issues/4864 Crystal is improving everyday :)
- maxpert 9y agoStill waiting for v1; Ruby being my fav in terms of syntax, Crystal is really going to lift my experience in terms of syntax. This interview describes low traffic usage, what I am looking for is high traffic usage scenario and how crystal’s GC behaves running for longer periods of time.
- Exuma 9y agoI'm also interested in this...
- faaq 9y agoCheck latest benchmark (not the best but shows good performance) https://www.techempower.com/benchmarks/previews/round15 https://www.techempower.com/benchmarks/previews/round15
- yxhuvud 9y agoThese benchmarks show raw throughput though, and not latency distribution. A well functioning GC should not be too bad in either, and the current solution in the GC area is very much stop the world, so I expect the latency tail to be pretty bad even if raw throughput is damned good.
- faitswulff 9y agoIs there an easy way to get interop working between crystal and ruby? It would be nice to be able to simply require a crystal module that calls out to a compiled binary in the middle of my Ruby code.
- deleted 9y ago[deleted]
- prh8 9y agoNot at the moment. About a year ago I did a proof of concept that replaced ActiveSupport's Inflector module with a fully working Crystal version, which was then compiled as a native extension. Since then, language changes have broken the way that I had things hooked up, although it was suboptimal anyways. There is another strategy using macros, which is much better. I wasn't familiar enough with macros when I first tried it, which is why it was a bit hacky. Crystal's core team has plans for a DSL to do this, so there will surely be something nice in the future. It's definitely feasible, and the performance was decent. If you're interested (just remember mine's broken with current Crystal), my work is https://github.com/phoffer/crystalized_ruby https://github.com/phoffer/crystalized_ruby and a macro approach is demonstrated at https://github.com/spalladino/crystal-ruby_exts https://github.com/spalladino/crystal-ruby_exts
- faaq 9y agoSee https://es.slideshare.net/AnnaKazakova/how-to-write-ruby-extensions-with-crystal https://es.slideshare.net/AnnaKazakova/how-to-write-ruby-ext...
- faitswulff 9y agoThis is the full talk, I assume: https://archive.fosdem.org/2016/schedule/event/ruby_extensions_crystal/ https://archive.fosdem.org/2016/schedule/event/ruby_extensio...
- vram22 9y agoCrystal looks interesting based on the comments in this thread by those using it. Anyone know why it seems to not be available for Windows (without WSL)? Does it have some POSIX dependencies?
- dingdingdang 9y agoYep, proper Windows support is a must for easy to use dev setup - Go is OK'ish in this sense but Crystal is currently really difficult to get running (either vm or Win10 Linux sub-system or Cygwin hack needed!)
- vram22 9y agoThanks. Still wondering what the reason is though - but based on what you said, it seems like POSIX-like APIs being needed may be the reason. Maybe for the concurrency features or other language / library features of Crystal. But then again, Go has concurrency features but works on Windows, and of course Windows has threads anyway, which are usable from C/C++ and other languages.
- RX14 9y agoIt's simply a lack of manpower to port to the windows APIs. There's a partial windows port, but it needs a lot of work before it's merged into master.
- faaq 9y agoHere is an installer waiting for Crystal support on Windows https://github.com/faustinoaq/crystal-windows-installer https://github.com/faustinoaq/crystal-windows-installer :)
- vram22 9y agoThanks.
- acangiano 9y agoBTW, with a bit of fidgeting, it's possible to get Visual Studio Code for Windows to use Crystal for WSL quite nicely. On the other hand, Crystal in a VM is faster.
- todd3834 9y agoI’ve always wondered why Crystal doesn’t get more attention.
- devmunchies 9y agoBecause it's not production ready yet. It's getting there.
- curtis 9y agoCrystal reminded me of Mirah [1], a Ruby-like programming language which is statically typed but relies heavily on type inference in order to compile efficiently to JVM bytecode, while retaining the appearance of being a dynamically typed language. (I've got no real point here other than to say I had a strong feeling of deja vu while reading about Crystal.) [1] https://en.wikipedia.org/wiki/Mirah_(programming_language) https://en.wikipedia.org/wiki/Mirah_(programming_language)
- nerdponx 9y agoWhy are people so interested in running things on the JVM? I'd much rather compile and ship binaries than force someone to install Java (or Ruby or Python).
- grzm 9y agoFor one, the JVM is available on multiple platforms. Rather than requiring a project to target each of these platforms individually, they can target a single platform—the JVM. There are plenty of people who dislike the JVM for any number of reasons (performance often being cited as one) and prefer to target specific platforms individually. Like many other things, it's a tradeoff, and people may arrive at different decisions depending on their priorities.
- ricardobeat 9y agoModern languages like Crystal target LLVM IR, which if, I'm not mistaken, supports even more platforms than the JVM.
- jerrre 9y agoBut it would need to be recompiled right?
- michaelmior 9y agoCorrect. But due to the separation of the front-end and back-end, the language developer doesn't have to do extra work to support different architectures.
- marcrosoft 9y ago> Features that we take for granted in Ruby or other languages, are not available in Go. Examples include operator overloading or keyword extensibility, as well as true OOP. These are literally the top reasons why I love Go. To each their own?
- dsign 9y agoIs there a place with the distribution of the number of developers per programming language? I have the feeling it has a very long tail.
- m3kw9 9y agoI thought this is a new type of drug
- eXpl0it3r 9y agoHaving no idea what Crystal is, my mind replaced it with crystal meth and it made the introduction text a lot more entertaining.
- faaq 9y agoCrystal is very good language, seems very promising Waiting for parallelism & Windows support +1
- quickthrower2 9y agoThat's a nice looking language. The inferred type system on an procedual / OO language with protection against nulls is something I had wished existed. I didn't know it had been done.
- thesmallestcat 9y agoHeard of Swift?
- deleted 9y ago[deleted]
- quickthrower2 9y agoI've heard of it but not investigated. So many programming languages. Is it general or tied to Apple?
- faaq 9y agogeneral
- singularity2001 9y agoI love crystal yet it puzzles me how the heroic developers can make rapid progress when each compilation of the compiler takes half a minute.
- lobster_johnson 9y agoI'm surprised Swift was outperformed by Ruby in their testing. I wonder what their benchmarking methodology was.
- hetman 9y agoI'd be curious to know what the compile times are like? Does ever compile run recompile the entire code base or is there some kind of incremental compilation?
- cutler 9y agoCrystal is currently no faster than Ruby when parsing a 19Mb Apache log file on OS X Sierra: fh = File.open("logs1.txt") fh.each_line {|x| puts x if (/\b\w{15}\b/.match x) } fh.close
- theodorton 9y agoI guess it depends, for one-off tasks you'll have to compile and run the Crystal code. I assume you ran the code above with `crystal run`. If you first compile the code with `crystal build --release` and run it, you should see a dramatic improvement over Ruby. On my machine, parsing a 374MB file took: - 25.63 using Ruby - 19.97 using Crystal (run w/o optimizations) - 19.01 using Crystal (compiled w/o optimizations) - 18.68 using Crystal (run w/ `--release` flag) - 11.54 using Crystal (compiled w/ `--release` flag)
- cutler 9y agoNo, it was compiled but without --release as I couldn't get it working on OS X Sierra.
- djur 9y agoThis isn't a benchmark that I'd expect to see a significant difference in. The majority of the CPU work is in the regular expression, and Ruby's regex engine is implemented in C.
- gtt 9y agoOn a related note, how well Crystal is suited for number-crunching?