TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Crystal: Fast as C, Slick as Ruby

544 pointsby yranadivealmost 9 years ago

31 comments

anpalmost 9 years ago
From this post, Crystal appears to have some of the things many people have been lusting after in Rust: sophisticated metaprogramming, fewer sigils, a bigger standard library, fibers&#x2F;coroutines&#x2F;whatever-they&#x27;re-called-now.<p>But it still has a GC :(. Rust has completely spoiled me with making it easy to minimize dynamic memory allocation and copies, and to know (almost always) deterministically when something will go away.<p>EDIT: I should also say that if you want to bash on Rust&#x27;s lack of these things, 3 out of the 4 items I cited have solutions being actively worked on (either at planning, RFC, or implementation phase). I don&#x27;t think Rust&#x27;s sigils are going away any time soon, but I have no idea how you&#x27;d do that and preserve semantics anyway.
评论 #12225057 未加载
评论 #12223781 未加载
评论 #12224650 未加载
评论 #12223724 未加载
评论 #12224886 未加载
评论 #12226544 未加载
评论 #12230744 未加载
评论 #12223779 未加载
评论 #12225693 未加载
评论 #12227093 未加载
评论 #12225764 未加载
评论 #12223671 未加载
Athasalmost 9 years ago
The claim is &quot;fast as C&quot;, so I was surprised that the performance comparison was with Ruby, not with C. On my machine, the Ruby Fibonacci program executes in 47.5s, while a corresponding C program executes in 0.88s - that&#x27;s a factor 54 difference, while the article reports a factor 35 for Crystal. That&#x27;s good, but what causes the difference? This benchmark is pretty much all function call overhead, so I doubt it&#x27;s representative of real performance-sensitive code.<p>The Crystal website itself makes a more modest claim than &quot;fast as C&quot; under its language goals: &quot;Compile to efficient native code&quot;, which it clearly does.
评论 #12223835 未加载
评论 #12223602 未加载
评论 #12226581 未加载
评论 #12225926 未加载
评论 #12224550 未加载
clessgalmost 9 years ago
Looks very nice. I hope it gains momentum.<p>For now, if you want a fast language with the beauty and productivity of Ruby, check out Elixir [0] and its web framework, Phoenix [1]. I&#x27;ve been using Phoenix for a year, and it&#x27;s the first framework that I&#x27;ve actually liked <i>more</i> over time. And I&#x27;ve been a web developer for a decade. With its recent 1.0 release, Phoenix is gaining a lot of momentum.<p>If you want some idea of the performance differences between Phoenix and Rails, see [2] and [3].<p>[0] <a href="http:&#x2F;&#x2F;elixir-lang.org&#x2F;" rel="nofollow">http:&#x2F;&#x2F;elixir-lang.org&#x2F;</a><p>[1] <a href="http:&#x2F;&#x2F;www.phoenixframework.org&#x2F;" rel="nofollow">http:&#x2F;&#x2F;www.phoenixframework.org&#x2F;</a><p>[2] <a href="https:&#x2F;&#x2F;github.com&#x2F;mroth&#x2F;phoenix-showdown&#x2F;blob&#x2F;master&#x2F;RESULTS_v3.md" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;mroth&#x2F;phoenix-showdown&#x2F;blob&#x2F;master&#x2F;RESULT...</a><p>[3] <a href="http:&#x2F;&#x2F;www.phoenixframework.org&#x2F;blog&#x2F;the-road-to-2-million-websocket-connections" rel="nofollow">http:&#x2F;&#x2F;www.phoenixframework.org&#x2F;blog&#x2F;the-road-to-2-million-w...</a>
评论 #12223614 未加载
评论 #12223623 未加载
评论 #12225855 未加载
评论 #12223604 未加载
评论 #12224286 未加载
评论 #12224481 未加载
评论 #12225941 未加载
评论 #12225698 未加载
Svenskungankaalmost 9 years ago
I&#x27;d like to put out there that Crystal is absolutely awesome. The language itself is Crystal clear, but the language documentation and API documentation - oh my!<p>I had never worked with compiled languages before I tried Crystal, but had always had a huge interest in getting into that. When I wanted to learn the compiled ecosystem I looked at languages like Go and Rust, but the learning curve for those was a bit overwhelming for a newbie. A while later I found Crystal, and much thanks to the simple syntax of the language I learned a ton of new things about compiled languages very quickly. The absolutely best part of the language is that it is written in plain Crystal, and I&#x27;ve been looking at their own implementations for various things a lot - something I&#x27;ve never done before, having worked mostly with Node, Lua and PHP before.<p>Nowadays I can delve into Go documentation, packages are clear to me and I just understand how things should and should not be implemented to achieve a good efficiency and performance level. The Little Go Book makes sense, the I&#x2F;O package is simple and this is probably all thanks to the syntax of Crystal, the amazing language &amp; standard library documentation but most importantly the source of Crystal being written in Crystal.<p>I&#x27;m currently working on building a business using Go, because I absolutely need Windows target support - something which Crystal does not yet have. But the second it gets that, I&#x27;m moving back. Don&#x27;t get me wrong, Go is really great and nice to work with - but Crystal is my mentor. Please note that I have not worked with Ruby before, so the whole language was new to me.<p>To summarize; even if you only wish to learn, Crystal is in my personal opinion the best choice to go with.
评论 #12223745 未加载
评论 #12223910 未加载
评论 #12224043 未加载
评论 #12225226 未加载
boyteralmost 9 years ago
The Fibonacci comparison is a poor example of performance gains because Ruby is using large number data types to ensure the correct result. This is according to the crystal language website itself.<p>&quot;However, Crystal might give incorrect results, while Ruby makes sure to always give the correct result.&quot;<p><a href="https:&#x2F;&#x2F;crystal-lang.org&#x2F;2016&#x2F;07&#x2F;15&#x2F;fibonacci-benchmark.html" rel="nofollow">https:&#x2F;&#x2F;crystal-lang.org&#x2F;2016&#x2F;07&#x2F;15&#x2F;fibonacci-benchmark.html</a>
评论 #12223689 未加载
评论 #12223810 未加载
willlllalmost 9 years ago
I recently gave a quick 10 minute talk on Crystal if anyone wants a video introduction <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=oC9IknG40po" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=oC9IknG40po</a>
评论 #12224472 未加载
erezalmost 9 years ago
First thing I look for whenever I run across another &quot;C competitor&quot; is to look which language it is implemented in. Usually that&#x27;s C, or C++, but this time, it does look like Crystal is implemented in Crystal, which is, to me, a very good indication that this is a &quot;real&quot; system language.<p>I believe Rust is also implemented in Rust and Go, after a few years of being implemented in C has now a compiler written in Go.
评论 #12226937 未加载
评论 #12224108 未加载
评论 #12224104 未加载
transfirealmost 9 years ago
I&#x27;ve done some coding Crystal when I have Ruby scripts I really need to run faster. I generally see about a 5x performance over Ruby.<p>It certainly is great to be able to jump right into Crystal coming from Ruby. It isn&#x27;t very hard to convert most Ruby code to Crystal -- you just have to go through and &quot;typify&quot; everything. A few methods have different names and of course some don&#x27;t exist but most of it is there.<p>My one grip with Crystal however, and why I haven&#x27;t adopted it more generally, is that much of the &quot;Lisp-like&quot; features of Ruby are all but lost. Crystal makes up for some of this with macros, but it doesn&#x27;t quite cut it. For example, you can&#x27;t splat an array into a lambda in Crystal. Arguments have to be tuples which are compile-time bound. Little things like this feel very limiting to an experienced Ruby developer.
评论 #12223971 未加载
mshenfieldalmost 9 years ago
Crystal doesn&#x27;t support a REPL yet because inferred static typing complicates incremental compilation.<p>Blog: <a href="https:&#x2F;&#x2F;crystal-lang.org&#x2F;2014&#x2F;12&#x2F;06&#x2F;another-language.html" rel="nofollow">https:&#x2F;&#x2F;crystal-lang.org&#x2F;2014&#x2F;12&#x2F;06&#x2F;another-language.html</a> Github Issue: <a href="https:&#x2F;&#x2F;github.com&#x2F;crystal-lang&#x2F;crystal&#x2F;issues&#x2F;681" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;crystal-lang&#x2F;crystal&#x2F;issues&#x2F;681</a>
评论 #12227070 未加载
评论 #12224328 未加载
评论 #12226834 未加载
westoquealmost 9 years ago
Was wondering how many companies actually use Crystal in production.<p>I was interested in Crystal but the lack of apps using it in production and proof of concept on the field is making me doubt its usefulness.
评论 #12223697 未加载
评论 #12231031 未加载
gtramontalmost 9 years ago
And it already got a port of Sidekiq: <a href="https:&#x2F;&#x2F;github.com&#x2F;mperham&#x2F;sidekiq.cr" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;mperham&#x2F;sidekiq.cr</a>
评论 #12226993 未加载
sdogruyolalmost 9 years ago
For anyone interested in building web applications with Crystal i recently gave a talk about Kemal at PolyConf <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=KJB-nAoRSr8" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=KJB-nAoRSr8</a>
z3t4almost 9 years ago
scoped includes are a deal breaker for me when looking at new programming languages.<p>ex: non-scoped (everything in foo is added to the global scope)<p><pre><code> inport foo { bar.do() } </code></pre> ex: scoped (everything in foo is added to the local scope, and assigned a name-space)<p><pre><code> { bar = inport foo bar.do() } </code></pre> I find it much easier to manage programs where there are no &quot;hidden&quot; global variables. It&#x27;s especially hard when the included files also can include files, witch all adds to the global scope.
评论 #12225731 未加载
AstroChimpHamalmost 9 years ago
So, this is like Ruby&#x27;s answer to cython?
评论 #12224326 未加载
评论 #12224368 未加载
jherikoalmost 9 years ago
cool.<p>can you make it faster than C though please? (seriously) i think it might even happen by accident in some cases already though. the places where C can be beaten for performance are, in my experience, from design choices in the C standards, users not understanding or leveraging those things for performance and the architecture of the compilation-unit&#x2F;link process.<p>things like the struct layout rules - instead of the compiler organising things to be optimal it follows those rules for memory layout, or the calling conventions - you often have to use funky extensions to get efficient function calls.<p>other things are the lack of ability to hint the compiler that e.g. mathematical structures underly types that can be leveraged for optimisation. that const or functional purity can be trusted... etc.
评论 #12226256 未加载
apialmost 9 years ago
Why couldn&#x27;t Swift be this?
评论 #12227537 未加载
catnaroekalmost 9 years ago
The really important questions in any modern language:<p>(0) Does Crystal have a lot of undefined behavior like C?<p>(1) Does understanding Crystal programs require a lot of trial and error just like in Ruby?<p>(2) How good a job does Crystal do at preventing me from shooting myself in the foot?<p>A language isn&#x27;t to be judged just by the amazing programs you can write in it. (Turing-completeness and I&#x2F;O facilities have that covered.) Far more important are the totally stupid programs that you <i>can&#x27;t</i> write in it.
评论 #12223632 未加载
评论 #12223546 未加载
评论 #12223502 未加载
评论 #12223654 未加载
smallbagalmost 9 years ago
Can someone comments the differences between Nim (old mimrod) and Crystal? Which one do you prefer and why. Thanks.
评论 #12230705 未加载
评论 #12227033 未加载
continuationalalmost 9 years ago
I think the macro system looks really interesting. The main ideas seem to be that meta programming can be done anywhere and that everything is quoted by default in macros. What are thes kind of macros called, and where do they come from?
kimshibalalmost 9 years ago
crystal on rails. i want this.
评论 #12224256 未加载
评论 #12230777 未加载
评论 #12225743 未加载
jalopyalmost 9 years ago
Great stuff. I love Ruby. Any idea when this will be production worthy, or at least stable enough to trust on internal projects? Will the language change much going forward?
评论 #12224551 未加载
happywolfalmost 9 years ago
What advantages Crystal has compared to other more modern languages that aim to compete with C? For example D and Rust.
评论 #12223726 未加载
评论 #12223859 未加载
评论 #12223597 未加载
VT_Drewalmost 9 years ago
Neat, I will check this out. Although, if I am honest I really wish there was &quot;Crystal for python&quot;.
评论 #12238045 未加载
ksecalmost 9 years ago
For anyone familiar with Crystal, are there any plan to add pattern matching into Crystal?
评论 #12237979 未加载
wtbobalmost 9 years ago
&gt; Have you ever dreamed of a programming language as beautiful as Ruby but as fast as C?<p>Yeah, I discovered Common Lisp back in 2006 and have been using it ever since …<p>I discovered Go back in 2009 and have been using it ever since, too.<p>What does Crystal get me that these two don&#x27;t?
评论 #12225751 未加载
kusmialmost 9 years ago
Does it have any benefit in particular over lua&#x2F;luaJIT?
评论 #12225943 未加载
评论 #12225740 未加载
ksecalmost 9 years ago
Someday, someone should write a Ruby VM in Crystal.
libmanalmost 9 years ago
Crystal isn&#x27;t fit to carry Nim&#x27;s jockstrap as far as I&#x27;m concerned. Ruby&#x27;s syntax is verbose and illogical compared to Python&#x27;s. Plus Crystal has a much more restrictive license.
welderalmost 9 years ago
Stopped reading when I saw the `end` keyword... the most annoying part of Ruby.<p>Edit: I&#x27;m getting hella downvoted but I&#x27;m leaving this here. Ruby fanboys can&#x27;t silence me!!! ;)
评论 #12224612 未加载
评论 #12226759 未加载
评论 #12223920 未加载
评论 #12224688 未加载
jhoechtlalmost 9 years ago
I seldom whine about blog posts but his one clearly justifies as click-bait. Not because of it&#x27;s otherwise good content. But if it takes me a Google search instead of having within the very first sentences a link to the obvious target,<p><a href="https:&#x2F;&#x2F;crystal-lang.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;crystal-lang.org&#x2F;</a><p>there is something f~*#ing wrong with the article.
quotemstralmost 9 years ago
If you require the use of a GC, you can never be as &quot;fast as C&quot; in the general case, since there will always be specific cases where manual memory management will do something more efficient than what an automatic GC would have done --- just like a car with an automatic transmission can never be quite as efficient as a car with a manual transmission used competently.<p>If you want to talk about efficient GCed languages, you have many choices, most of which have more tooling and mindshare advantages than you language has tooling advantages.<p>Really, GCed languages are commodities these days. A lot of people have put a lot of work into the fundamental building blocks, and now people are just combining them in various ways.