14 ms·
Crystal Language
- singularity2001 11y agoAwesome! Did you consider synchronizing your syntax with Mirah / typed ruby? Also what's your opinion on the Vala/Gini toolchain?
- kibwen 11y agoCrystal looks like a neat language, and it's fun to see how many entrants there are in the modern renaissance of scripting languages that compile to native code. I wish there was some more documentation about it though... for example, does the bullet point "Never have to specify the type of a variable or method argument" from the home page imply gradual typing as per Dart and TypeScript, or is it something else entirely?
- asterite 11y agoIt has global type inference, there's nothing dynamic in the language. You can specify type restrictions to allow overloading methods, for example, or doing multiple dispatch. But in the general case you don't specify types (except for generic type arguments) and the compiler figures out everything.
- kibwen 11y agoI'm curious how possible it is in practice to write large software that relies exclusively on global type inference. Does the compiler itself go without ever explicitly specifying a type?
- asterite 11y agoYes, you can browse the source code if you want, check it out and compile the compiler. It has between 30k and 60k lines of code (because you have to consider it also includes the standard library) and on a Macbook Pro 2015 it takes less than 10 seconds to compile (in non-release mode). We'll have to wait until we get project that's larger than the compiler, but we believe there's still room for performance improvements.
- logicchains 11y agoIt seems to have a fair slew of type-system features, so how does it manage to compile so fast, compared to for instance the Rust compiler, which doesn't do global type inference?
- kibwen 11y agoThe current slowness of the Rust compiler is largely due to putting more developer attention into improving the runtime speed of fully-optimized binaries. Hence, regardless of which mode it's in, the compiler does a lot of unnecessary work that a debug-mode binary doesn't need or benefit from. There's also simply a ton of low-hanging fruit lying around: we're only two weeks out from 1.0 and the nightly compiler is already reportedly 30% faster for code compiling in the wild. There's another 10% compilation speed reduction coming from work around optimizing linking. There's also work towards parallel codegen coming along nicely (https://github.com/rust-lang/rust/pull/26018 https://github.com/rust-lang/rust/pull/26018) which reports a 30% reduction in compilation time. In the longer run there are plans for incremental compilation which should drastically reduce the amount of work that gets unnecessarily repeated with each compilation cycle (https://github.com/rust-lang/rfcs/pull/594 https://github.com/rust-lang/rfcs/pull/594). In the even longer run there are plans to fully parallelize the compiler phases and also to pre-optimize code before it gets to LLVM in order to reduce the sheer quantity of IR that we shovel into it. TL;DR: Crystal manages much faster compilation than Rust because Rust's compiler developers may have deprioritized optimizing the compiler for a bit too long. :)
- bjeanes 11y agoThanks for linking to those RFCs. The planned or in-progress work for Rust compilation speed is very exciting. I can't wait to reap the benefits!
- asterite 11y agoIt's because we spent some time thinking the algorithms and optimizing them, and whenever we make changes to the compiler we make sure the times remain pretty much the same (it's hard because the compiler's size grows so the times inevitably grow, at least for the compiler). And from time to time we profile and optimize further, we like speed. I believe with time Rust can achieve a similar performance, maybe even better because they will be able to do incremental compilation (maybe, I'm not sure how will they do that with parameterized types). There's also the thing that most of the things in Crystal are lazy: if you don't invoke a method there are no type checks to be done for it. This means that you only pay for what you use (in terms of compile speed) but also what you don't use doesn't end up being in the resulting executable.
- reagency 11y agoGHC does global type inference, and has very sophisticated types.
- kibwen 11y agoMy point was specifically in regard to the feasibility of omitting the types in all cases. I see types often in Haskell code, likely because the community regards that as a best practice (in contrast to Crystal).
- tel 11y agoBest practice and it's required to make certain more advanced type features work. It's the same with Crystal. Their generics require type annotations.
- Vulume 11y agoIn Haskell types are used a lot as documentation and to make static guarantees about the program logic, not just runtime safety. If you're only worrying about illegal operations you practically don't need signatures.
- agrafix 11y ago...and is a slow compiler compared to for example Go :-(
- dmbaturin 11y agoOCaml has separate compilation, a REPL, and it's very fast. None of those things is incompatible with global type inference (although particular type systems can be).
- seanmcdirmid 11y agoDoesn't OCaml require everything to be defined before used though?
- Vulume 11y ago
- seanmcdirmid 11y agoWhat algorithm are you using? How do you deal with subtyping and paramatricity?
- tel 11y agoThey have a couple posts on their inference algorithm, but I confess I haven't read them.
- asterite 11y agoThe algorithm isn't very easy to explain in a few words. We don't use any well-known algorithm. It has some bits of the cartesian-product algorithm, but just tiny bits. There's some info here: http://crystal-lang.org/2013/09/23/type-inference-part-1.html http://crystal-lang.org/2013/09/23/type-inference-part-1.htm... http://crystal-lang.org/2014/04/27/type-inference-rules.html http://crystal-lang.org/2014/04/27/type-inference-rules.html About subtyping and paramtricity, I'm not sure what's that, but the compiler just keeps track of all the types and forms unions, except in one case which is this one (a union of references with a base type): http://crystal-lang.org/docs/syntax_and_semantics/virtual_and_abstract_types.html http://crystal-lang.org/docs/syntax_and_semantics/virtual_an...
- seanmcdirmid 11y agoIf you are using Agesen-style CPA, then it is more of a global analysis (type recovery) then type inference. I would be a bit worried about scaling, but if you've put 50kloc through it, maybe you've figured it out? I'm working on my own type-less type inference system that I'll share more about soon.
- dmbaturin 11y agoDo you have a (more or less) formal description of the type system?
- _RPM 11y agoHow long did it take to become self hosting? I checked the first tag on GitHub and it was still implemented in Crystal. Did you originally implement it in C or another language?
- rajahafify 11y agoFrom what I understand in another post of their's, Crystal used to be written in ruby, before they successfully compiled it using Crystal.
- asterite 11y agoIt took about one year. We originally implemented the compiler in Ruby and because of its similarity with Crystal (or the other way around ;-)) porting it to Crystal was pretty easy in the end. There's this tag: https://github.com/manastech/crystal/releases/tag/ruby https://github.com/manastech/crystal/releases/tag/ruby You can read about the bootstrapping moment here: http://crystal-lang.org/2013/11/14/good-bye-ruby-thursday.html http://crystal-lang.org/2013/11/14/good-bye-ruby-thursday.ht...
- earleybird 11y agooriginally Ruby http://crystal-lang.org/2013/11/14/good-bye-ruby-thursday.html http://crystal-lang.org/2013/11/14/good-bye-ruby-thursday.ht...
- deleted 11y ago[deleted]
- deleted 11y ago[deleted]
- trengrj 11y agoI've been looking at the benchmarks https://github.com/kostya/benchmarks https://github.com/kostya/benchmarks and am pleasantly surprised about the speed. It definitely smokes Ruby, but also is usually faster than Go. I know that all benchmarks are relative but Crystal seems a great language from a performance viewpoint.
- ezdiy 11y agoIndeed it's becoming quite promising (using crystal already for few pet scripts which were too slow even for rubinius). Where it's most lacking at the moment is gc - it uses stop-world off the shelf boehmgc which is ok but not exactly great for memory heavy tasks.
- kephra 11y agoimho, starting a new language with Boehm GC is a very bad design choice. It means, that one just allocates memory, and does not care for managing it. Even worse, it prevent linking any library, e.g. a 2nd thread running Lua+C, that cares for its own memory, because Boehm GC runs over the complete memory, not only the one the language has to manage. You basically need 3 types of memory: First for the objects in your language, 2nd for foreign light weight objects, where you only know a pointer, and 3rd for foreign heavy weight objects, that gets their memory from your GC. > it uses stop-world A fully concurrent GC is impossible, if variables are mutable. Regardless how tricky your GC delays the problem, there will come a point, where it has to stop all threads to collect the edge cases. This creates the GC dilemma, because currently only number of cores and amount of memory becomes cheaper, while single core performance stayed same for nearly 15 years.
- asterite 11y agoIn the beginning Crystal didn't free memory. We needed a GC and Boehm was a super easy way to get that. It worked out of the box with very little effort. Eventually we can write our own GC or use another one. It's only a matter of time. But right now there are more important things, we think: finishing the language rules, stabilizing things, fixing bugs, completing the standard library and writing documentation. Nothing is set in stone in a language, things can always evolve and improve.
- rtpg 11y agohttp://crystal-lang.org/2013/07/13/null-pointer-exception.html http://crystal-lang.org/2013/07/13/null-pointer-exception.ht... The Null pointer analysis is great, hope this stuff pollinates some of the more mainstream languages
- raindev 11y agoI don't see a reasons for null to exist in a new language in 2015.
- asterite 11y agoHow do you model a "zero or one" relationship without null? Maybe your answer is "with Optional" (or Option, or Maybe). We just choose to use union types and have "Nil | T" (Nil or T) be the same as "Option(T)" in other languages.
- raindev 11y agoYes, Maybe (Optional) is the way to go. The difference is, with nil you basically make every type optional allowing it to have nil as a value.
- asterite 11y agoWell, in Crystal Nil is a separate type that can be combined with others. But, say, a String is always a String, it doesn't implicitly have the Nil type. Same goes with every other type. Maybe you are thinking of Java/C#, where reference types can also be null, but this is not true in Crystal. It's also in a way similar (but not quite) to Swift, where optional types are different than types that can't be null.
- vanderZwan 11y agoDo you have a technical write-up of how Crystal does that? Or otherwise some links/papers that explain the principle in a language accessible for someone who is basically self-taught and lacks a formal CompSci education?
- MCRed 11y agoI love that we're getting new languages lately, but almost all of them seem to be ignore the significant new requirement of our age: parallelism & concurrency. Specifically, you need lightweight processes and no-shared-memroy architecture. While the number of cores on a machine is remaining relatively low, the number of machines in a system are going up. Erlang got this right and build a lot of infrastructure around it (OTP) and while you can't replicate that infrastructure quickly you can get the fundamentals right. Simply getting this wrong rules out a lot of languages from consideration (because why learn a new language that is going to be obsolete, or only chosen by people who don't understand how to build systems?) It's a lot easier to get this in when you're new and can make major changes to the language. Once you start to solidify it would break things- this is why Go's fake concurrency is a tragedy and a huge missed opportunity.
- rifung 11y agoI largely agree with what you are saying, but doesn't it only apply to languages that will be used in back end systems? If you are just making a phone app or something, it doesn't seem like parallelism is nearly as important.
- oconnor0 11y agoPhones are getting more and more cores. It won't be long before languages for mobile need to solve the same issues - parallelism and concurrency.
- deleted 11y ago[deleted]
- asterite 11y agoYou are right, it wouldn't be wise to create a new language without having concurrency in mind. Starting from the last version there's spawn (lightweight processes) and channels for communications, similar to Go (although it's in a very experimental stage right now). We aren't sure immutability everywhere is the solution for everything, some algorithms and programs are much more efficient with mutable data. I think Go is quite popular and have an amazing concurrency support. It's true, you have to make sure to communicate using channels and not via shared memory, but if you follow that rule than you won't have problems, and you can get pretty efficient programs.
- zeeone 11y agoJust curious, why Crystal? It looks just like Ruby. What problem(s) are you addressing with Crystal?
- umhan35 11y agoIt's a compiled language.
- asterite 11y agoWe like the way Ruby lets you quickly prototype things, but its performance isn't very good (it's just good) and it also lacks static type checks (for example "undefined method '...' for Nil" is a very common runtime error). So, we are trying to create a language with all the nice aspects of Ruby but with static checks and better performance. Of course that comes at a price: no dynamic aspects (no eval, no instance_eval, no methods or classes created at runtime, no methods redefined at runtime, etc.). But we try to compensate those with macros and compile-time reflection. One thing that is definitely not one of our goals is to replace Ruby: every tool has its place.
- Sodel 11y agoI recommend adding something about static type checking to the list at the top of Crystal's homepage. I saw "never have to specify the type of...", and believed it was another dynamically typed language. I actually didn't know it had static type checking until I had closed the tab, and glanced at this comment you posted here. (I know, I didn't read very far in the linked page.) That aside, it looks neat! :)
- AKifer 11y agoAt first look, I like it. Would be great if we can build a ruby-to-crystal bridge so all the ruby goodness can run on top of it without requiring programmers to learn a whole new language. No GIL, faster than ruby but syntactically close enough, the dream.
- ezdiy 11y agoCurrent channels implementation uses fibers, ie everything runs on single thread and only stack is switched. There is no GIL. If you want true multithreading, simply use pthreads like you would in C. Just make sure to mark gc roots of new thread stacks (gc is thread aware). But this also comes with a lot of headaches as you're now responsible to synchronize everything and manage mutexes by hand.
- sergiotapia 11y agoI'm looking for something beautiful like Ruby but fast like Go. Do you think Crystal fits this bill? Also, are there packages/libs/gems for Crystal? What are they called? What do I google for? One of the major reasons why I dumped Go is that it's just too verbose and makes me write too much boilerplate code. I want to sort a collection and I have to write the same algorithm every single time for every single type. It's just boring and my time could be better spent elsewhere. I appreciate the feedback HN!
- seunosewa 11y agoYou're looking for Scala. The "good parts".
- zak_mc_kracken 11y agoStill looking for them ;)
- Dewie3 11y agoYou're sounding like a broken record by now, Cedric.
- robertodelori 11y agoWhat's your desired use case? I have same problem, same concerns and I think that Nim look promising (at least for me). I was giving Go a try, but nah - there just wasn't magic between us ;)
- singularity2001 11y agoCrystalGems would be really a boon!!
- anonyfox 11y agohttp://elixir-lang.org http://elixir-lang.org may be even faster than go. web apps respond in microseconds.
- agluszak 11y agoWow! Ruby was the first programming language I learnt and I still love it. Crystal is going to add features I've always missed: static typing and compilation. Thank you guys, it will be awesome!
- sir_akshay 11y agoYou missed compilation?
- singularity2001 11y agoHe probably meant the results of compilation: superfast binaries ;)
- espadrine 11y agoIn that case, what he missed was AOT optimization :) Many Lisps have had compilation to binaries. But having a binary doesn't imply being faster than an interpreted language. Theoretically, a JIT optimization can end up with faster code than an AOT optimizer can produce, thanks to runtime profiling. In fact, I'd be interested in seeing benchmarks, which Crystal is probably not ready to share, but may have conducted: https://github.com/manastech/crystal/blob/master/samples/fannkuch-redux.cr https://github.com/manastech/crystal/blob/master/samples/fan... Edit: this[0] seems to indicate that the optimizations are in the same ballpark as Go and D, which is really impressive. [0]: https://github.com/kostya/benchmarks https://github.com/kostya/benchmarks
- masklinn 11y ago> Edit: this[0] seems to indicate that the optimizations are in the same ballpark as Go and D, which is really impressive. not sure about D, but Go is known to have very little in the way of optimisation, that's a big factor in its speedy compilation.
- keypusher 11y agoPython is to Nim as Ruby is to Crystal.
- singularity2001 11y agoMore like Crystal could become to Ruby what RPython is to python
- masklinn 11y agoThat makes no sense. RPython is not a general-purpose development language, it's a strict subset of Python for writing VMs. From what I understand Crystal aims to be a general-purpose statically-typed native-compiled language with a syntax similar to Ruby in much the way Nim aims to be a general-purpose statically-typed native-compiled language with a syntax similar to Python. Neither Nim nor Crystal exist solely to write VMs and auto-implement JITs, and programs in neither is expected to run unmodified on a VM for the inspiration language.
- singularity2001 11y agoNow someone convince Matz to reimplement Ruby in crystal, add optional typing to CRuby, and you have won big time.
- atmosx 11y agoActually, that's already happening[1]. Also note that there is a library for "ruby contracts[2]" (which I didn't try yet, but I'm very eager to do so) which could give the same result as a statically typed language. [1] https://www.omniref.com/blog/blog/2014/11/17/matz-at-rubyconf-2014-will-ruby-3-dot-0-be-statically-typed/ https://www.omniref.com/blog/blog/2014/11/17/matz-at-rubycon... [2] http://egonschiele.github.io/contracts.ruby/ http://egonschiele.github.io/contracts.ruby/.
- masklinn 11y agoExcept for the parts where you've lost spent years reimplementing an implementation-defined language and you've lost the existing C API so most any C extension which doesn't use Fiddle (or similar FFI mechanisms) is incompatible.
- davexunit 11y agoI don't understand why Ruby's syntax is seen as so elegant. It's ambiguous and a nightmare to parse. http://programmingisterrible.com/post/42432568185/how-to-parse-ruby http://programmingisterrible.com/post/42432568185/how-to-par...
- john2x 11y agoYeah, the Ruby-like syntax of Elixir made me stop looking into it more. I remember reading an article (or was that a chapter in a book), which basically said something like "ok, these parentheses are optional, but only for this case. For other cases, parentheses are required." Which is a shame, since the tooling built for it is the most amazing I've ever seen. I know syntax shouldn't matter, but personally I think consistency is very important.
- Reefersleep 11y agoI think syntax matters a lot - if it incurs development costs through inconsistencies, for example. I'm going to a meetup in a couple of days where Elixir and Phoenix will be presented, I think I'll keep your comment in mind and maybe ask about inconsistencies in the syntax, as I wasn't aware of this. What I know of the syntax relation to Ruby is that it is only superficial - the semantics are very different.
- Lrigikithumer 11y agoElegant to program with. Not write a parser for.
- davexunit 11y agoAn ambiguous syntax is not elegant to program with. Is this a variable reference? Is it a method call? I dunno!
- JoeAltmaier 11y agoWait - are we talking C/C++ here? where a function call, a variable declaration, an expression cast all look identical?
- Nob-suz 11y agoI made a Crystal Language Web/Git information collection pages. https://github.com/nob-suz/crystal/wiki/1.-Read-First-%28general%29 https://github.com/nob-suz/crystal/wiki/1.-Read-First-%28gen... See Wiki 1. to 9. If you enjoy your first try for Crystal Language, it's nice.
- westoque 11y agoNow. I just can't wait till Rails or something similar gets ported to Crystal.
- aikah 11y agoI'm a go user right now, but I really want to ditch it because I'm in total disarray with the way the go language is managed and the deafness of the go team. Been looking at D,Nim and Crystal. - D is neat but I'm not interested at all in unsafe stuffs and don't want to have to debug programs or 3rd party libs that relies on that, I want a safe language. - Nim looks really good, although some features like (foo_bar = FooBar ) are just disgusting - While Crystal is new and libs is non existent, it feels like a good candidate for the long run. I hope it will have the same concurrency capabilities as go. Good luck with the language.
- p0nce 11y agoD has a memory safe subset (@safe). You could argue that Rust 3rd party libs rely on unsafe blocks.
- kibwen 11y agoThe person you're replying to wasn't even talking about Rust. You'd also be vastly overestimating the amount of Rust libs that need unsafe code. For example, Rust's most mature web framework, the one powering crates.io, doesn't use unsafe code at all: https://github.com/iron/iron https://github.com/iron/iron
- steveklabnik 11y agoCrates.io uses Conduit, not iron.
- kibwen 11y agoAh, so it does. :) Fortunately Conduit doesn't use any unsafe either.
- zak_mc_kracken 11y agoHave you looked at the new generation languages on the JVM such as Kotlin or Ceylon?
- 11y ago
- zero_iq 11y agoWow, I started designing a language called Crystal in the 90s, which a) looks similar to this, and b) I'm pretty sure I even bought the domain crystal-lang.org at one point, but I never did anything with it! I had a very similar logo too :)
- elcct 11y agoPlease don't be inspired by Ruby, please... aaaah god dammit!