9 ms·
The Crystal Programming Language
- nTalle 4y agoI used Crystal every day for 2 years. It is for me one of the best languages. Fun and powerful but there are some big problems, I switched to Elixir. Among the problems : - A too long compilation. For 2 projects, the compilation in dev env takes more than 30 seconds for each compil, the developer experience is dead at this cadence. - IDE integration: auto-completion, go to def, API docs, etc works when it wants (almost never). - The community is too small which results in a lack of docs, examples, help. I spent days searching in Github projects, just to see examples of basic things. - Instead of focusing on a main framework that makes everyone agree, everyone makes their own framework, their own libs (including me). The result is a lot of time and energy spent on duplicate packages and frameworks that are not necessarily maintained. I continue to follow the evolution from afar, one day it may be possible to integrate Crystal in WASM, acceptable compile times, maybe a productive main framework :)
- didip 4y agoWhat is the edge it gives when compared to Rust, Zig, and Nim?
- bovermyer 4y agoCrystal's performant enough, but its key differentiating feature is its Ruby-like syntax. It's easy to write, and comparable in performance to Go and similar. Rust, Zig, and Nim are solving different problems.
- db65edfc7996 4y agoNim and Crystal feel like they are in exactly the same space? GC, fast, single executable compilation without runtime (I would also throw Go into this list).
- cultofmetatron 4y agothere is a runtime. its just baked into the final executable. you can't have garbage collection without one.
- yxhuvud 4y agoEverything has a runtime nowadays. Even C, even if it isn't all that large (including for example the memory structures necessary to keep malloc and free working).
- woodruffw 4y agoI think that’s too expansive of a definition of “runtime.” The context required by C and Rust programs is generally internal, meaning that interacting with the dynamic allocator doesn’t require the programmer to be aware of the implementation’s invariants. This is in contrast to a managed language like Java, where using a managed object from C via JNI requires coordination with the runtime (which in turn preserves the invariants).
- yxhuvud 4y agoBut you have to know that as well for C - there are for example several Linux system calls you really should not call manually because that would fuck up the internal state in LibC. Yes, the runtime is really small, comparatively speaking, but it is still a runtime.
- woodruffw 4y agoWhich system calls are you thinking of? The only ones that I can think of would be brk(2) and sbrk(2), but any recent libc should be resilient to calls to those. That being said, I'll grant that the distinction between "tiny runtime" and "no runtime" isn't useful and that C can be said to have a runtime insofar as most systems provide a `crt0` or equivalent.
- auxym 4y ago
- mumblemumble 4y agoProbably the biggest differentiator compared to those three is that it's object-oriented. Rust, Zig and Nim are all procedural.
- pjmlp 4y agoRust definitly supports COM style OOP, and Nim does have OOP support.
- frou_dh 4y agoIf a language has a string type then it has an edge over Zig.
- sph 4y agoControversial in this forum, but its GC. In some applications memory allocation is not that important, so it's nice not having to think about it at all. I've gone deep into Rust recently, but Crystal might still eat Python's lunch, a language I've fallen out of love with.
- kinjba11 4y agoRust doesn't have a garbage collector, meaning you have a steep learning curve around the borrow checker. Zig aims to be a C replacement, with manual memory management as well. Nim is very close to Crystal. Some parts that might lead you to prefer Crystal however: - Nim compiles to C code, meaning Nim is coupled to what C can do. I find compiling to C to be distasteful, C is not meant to be a compilation target. We should be getting away from C, IMO. Nim is limited to what C can achieve, and the design of the language trends towards "here's how this translates to C" as a result. Compiling to C is also an extra layer of abstraction, as now for instance with debugging you have to go through the C layer. Crystal like Rust uses LLVM - Crystal also uses Ruby syntax, which many prefer. I have grown to dislike semantic whitespace such as how Python works, so this is a plus for me. - Crystal has a garbage collector, period, and leans into that. Whereas Rust, Zig, and Nim want to give you complete control over memory, Crystal is more focused on being a better high-level programming language, competing with the likes of JVM/NET/Go/Ruby. This focus is likely Crystal's main edge. The only other single-executable opinionated GCed language is Go. Crystal's type system is much better than Go's. If Crystal can reduce compile times and capture some of Go's pragmatic aura, it will see more success.
- ArrayBoundCheck 4y agoI clicked on 7+ pages. I still can not find how to use an array
- mumblemumble 4y agohttps://crystal-lang.org/api/1.5.0/Array.html https://crystal-lang.org/api/1.5.0/Array.html
- fshr 4y agoBud, there's a search box at the top of the docs... https://crystal-lang.org/reference/1.5/syntax_and_semantics/literals/array.html https://crystal-lang.org/reference/1.5/syntax_and_semantics/...
- jim_kreggis 4y ago
- siproprio 4y agoNow, all we need for crystal to succeed is numpy, scipy, something pandas-like, and of course matplotlib (not plots, matplotlib). By the way, how are we on data-science friendly IDEs? Debugging? Automatic thorough documentation generator? Tooling in general? Is the time to first plot fast? Where I work, we desperately need a fast python.
- mumblemumble 4y agoI've tried a few times now to do data science in a statically typed language, and I just haven't enjoyed the developer experience. In general I tend to think the advantages of dynamic typing are overblown, but this is one problem domain where it seems to be indispensable. ML and data engineering is a different story, of course. Also, I wouldn't be surprised if something clever could be done with a structural type system.
- siproprio 4y agoWhat languages have you tried, and what in them did not work? What’s wrong with casting variables to mutate their type?
- wudangmonk 4y agoStatic typing is like salt, sprinkle a little bit and it enhances and gives flavor to your food. Too much of it and it completely ruins the dish.
- bartmika 4y agoOut of all the programming languages coming out these days, Crystal is the one I am watching out for. I've never programmed with Ruby, but I have programmed with Python in the past so I really value the focus on programmer friendly syntax that Python taught me. Currently a Golang a programmer and I love the performance plus binary executables! From my experience so far Crystal feels like a performant language with the wonderful feel of Python. Definitely check this language out if this is the first time you're hearing about it.
- reil_convnet 4y agoJust curious whether you have checked out Nim. I love it coming from Python, curious to know what Crystal offers apart from Nim for Python users.
- bb1234 4y agoI used Crystal to create a web application a 2-3 years ago. It is running great without any problems. There are not that many users (only about 300-400) at any time. Anyhow, I did not touch the application in the last two years, and did not use Crystal in the last two years for anything else. I used Rust to write some simple personal CLI apps, which was fun but also hard. For some reason, couple of days back I returned to Crystal for a CLI app that I am making. I will say this: Crystal is a lot of fun to program in, easy to use and performant all at the same time. I cannot explain the reasons objectively, but it is really a joy to use Crystal. I think I will be using it from now on. I just wish it had a bigger community and as a result more libraries.
- axelthegerman 4y agoProbably because of the Ruby inspired syntax which just brings joy. Hopefully the ecosystem can grow and partially catch up as well
- jjtheblunt 4y agoi've seen that said so many times, and fail to understand why Ruby syntax brings joy. Personally, I thought the muddled Proc, block, and lambda situation a mess, coming from Scheme 30 years ago to Ruby 20 years ago.
- threatofrain 4y agoRuby was among the first languages I learned, back when there was the possibility of Ruby being a general purpose language and not just Rails. My joy was the result of being able to guess syntax and be right. Nowadays I value reading documentation and IDE level support, so guessing syntax is no longer a joy.
- gsinclair 4y agoI guess those things are a compromise. Being able to use that concept easily is a joy. The implementation prioritises developer convenience over syntactic purity. It’s a shame we can’t have both, but I accept the trade-off.
- wing328hk 4y agoIf you want to generate a Crystal SDK for REST APIs, please give OpenAPI Generator [1] a try. Here are 3 simple steps to do so: https://forum.crystal-lang.org/t/crystal-api-client-generator/2843 https://forum.crystal-lang.org/t/crystal-api-client-generato.... Hopefully this will save you some time in manually creating the API clients in Crystal. [1] https://openapi-generator.tech/ https://openapi-generator.tech/
- deleted 4y ago[deleted]
- compumike 4y agoIf you'd like to try out Crystal without installing anything locally, I've created a tiny Docker container with a Crystal project template: https://github.com/compumike/crystal-docker-quickstart https://github.com/compumike/crystal-docker-quickstart For example, you may do: git clone https://github.com/compumike/crystal-docker-quickstart.git my_app cd my_app ./d_dev # docker container spins up in a few seconds... within the container's bash shell, try: make spec make && out/my_app # outside container, you may edit src/main.cr, save it, and then again within container: make && out/my_app Good luck and enjoy! :) I've written about Crystal before and am using it in production... see https://news.ycombinator.com/item?id=32216786 https://news.ycombinator.com/item?id=32216786 and https://news.ycombinator.com/item?id=32081943 https://news.ycombinator.com/item?id=32081943
- robertlagrant 4y agoI'm definitely Python in Python vs Ruby, but that is a nice-looking syntax.
- juanse 4y agoI really like that Crystal keep silently improving and improving. As other said, it just needs a push and a few more important libraries. Really wishing that finally takes off.
- nine_k 4y agoWindows is still not exactly supported. The language is nice though. It seems like it would benefit from a bit more publicity.
- jasinjames 4y agoLooks interesting! I'm always open to a statically type checked language. This isn't about the language, but I was surprised to see that Nikola motors is a sponsor. Wasn't that company a fraudulent Hydrogen Fuel vehicle startup[1]? I wonder what the story is there- I find it hard to imagine anyone would be doing much software engineering at the company in the first place, even if it *were* working on the technologies they claimed to. [1] https://www.youtube.com/watch?v=88fWUZhYb04 https://www.youtube.com/watch?v=88fWUZhYb04
- eric4smith 4y agoBrah chill out. Just because the Pr0n industry overwhelmingly uses PHP does not mean People should not use PHP. Bad people use good tools too.
- straight-shoota 4y agoNikola had some trouble in the past, but it's actually doing remarkably well. They have electric trucks on the streets right now, with Crystal on board. Read more at https://manas.tech/blog/2020/02/11/nikola-motor-company/ https://manas.tech/blog/2020/02/11/nikola-motor-company/
- rvz 4y agoYeah, and Meta uses Rust and contributed to a mass atrocity in Myanmar and is facing a $100BN+ lawsuit. Does that mean we should all stop using Rust because Meta is not only using it but also sponsoring the Rust Foundation as well? I think you know the answer.
- freediver 4y agoHuge props for the Crystal lang team. Crystal powers 90% of the Kagi search backend (reminder being Python). Highlights are great performance and concurency handling. Biggest downsides at this moment are compilation speed (does not take advantage of multi CPU cores) and debugging tools. Overall our experience has been fantastic (we adopted it while still in beta) and the pace the language is developing is great.
- widdershins 4y agoAh, that's interesting information. I've been a (paid) user of Kagi these last few weeks and I'm really enjoying its snappiness. Of course, no ads or trackers must help - when I look at the Network tab in developer tools the comparison with a google search is stark. ~4 requests vs. google's ~50.
- californical 4y agoWow! I’ve been paying for Kagi for as long as it’s been possible to, love the project & the search results are truly so much better than I’ve gotten from Big G for most queries. Never would’ve expected it to be using Crystal though! That’s really neat. Are there open source bits? I’d love to see some enterprise-level Crystal examples
- freediver 4y agoWe have plans for open sourcing our compontets, including a blog post from our lead dev about how we use Crystal, but never seem to find the time - always some bigger fish to fry.
- eric4smith 4y agoPoints for the syntax and speed. However it really needs a bit of “wow” factor to take off. We’ve used it here and there in dribs and drabs but don’t see a reason to use it in a new project when there is Elixir and/or Rust. Elixir brings the easy to use concurrency almost automatically. This and other features make it almost unbeatable for web and backend stuff. Rust is just as fast as crystal. Albeit harder to grok. Python was literally saved by the numerical libraries. Or there would not be real reason to keep using it. I keep one weather eye open on crystal to see how it’s doing but have seen no real reason to start a new project with it as yet. For me the syntax is not reason enough as yet. Elixir is maybe easier and functional to boot. Being object oriented in 2022 is not a good reason either. I’m an old rubyist and I wish Crystal the best. I’ve been following it since it was a gleam in the eye, But … why? And for what??
- mgarciaisaia 4y ago(Manas.Tech employee here) Back when I joined Manas.Tech and learnt about Crystal, THE wow factor for me was the way `if` constraints optional types when you check it: https://crystal-lang.org/reference/1.5/syntax_and_semantics/if_varis_a.html https://crystal-lang.org/reference/1.5/syntax_and_semantics/... That provides you the flexibility of having union types (variable may be `Thing1` or `Thing2`) for generic purposes, AND type-safetiness (is that a word?) when dealing with specific paths of your program that apply differently to some of the subtypes of the variable. I think Swift and Kotlin support (some of?) that now. It was really new for me back in the day (around 2014?). But that's from a coding point of view - not that much about niches, as you talk about.
- chaosprint 4y agoCan this work with WASM?
- haarts 4y agoThis is a work in progress. Version 1.4 included minimal support for WASM (we are currently at version 1.5): https://crystal-lang.org/2022/04/06/1.4.0-released.html https://crystal-lang.org/2022/04/06/1.4.0-released.html. I expect full WASM support in the near future.
- insane_dreamer 4y agoGreat to see this coming along. A potentially great successor to Ruby for those who prefer OO over functional (Elixir). I use Python for work because of the math/sci libraries and ecosystem, but would otherwise use a Ruby-inspired language.
- revskill 4y agoLet's migrate RoR to CoR
- nurettin 4y agoThat could be possible considering much of the language seems compatible. However, Crystal has incompatible accessor syntax for some reason. And concurrency is handled differently unless rails uses fibers everywhere. At this point they are way too different to just get away with syntax find/replace, it would require structural changes as well.
- straight-shoota 4y agoHere you go: * https://github.com/spider-gazelle/spider-gazelle https://github.com/spider-gazelle/spider-gazelle * https://luckyframework.org/ https://luckyframework.org/
- zw963 4y agoThe most similar project so far is lucky. https://github.com/luckyframework/lucky https://github.com/luckyframework/lucky Development by folks come from thoughtbot.
- TwentytwoSeven 4y ago
- u89012 4y agoI'm a Ruby guy and I tried Crystal for about 2 years and absolutely loved it but then had to give up for the following reasons: 1. Too slow to compile (the whole program + the entire stdlib is built everytime you build!). No incremental compilation available. 2. No language server (apparently it's just impossible due to the way the language works). Tbh, I'd be happy with just "Go to definition" but alas, no-can-do! 3. Obscure error messages (macros are to blame here) 4. Weak HTTP server implementation -- making things such as a fetching POST params or uploads incredibly frustrating. Once read the request body cannot be read again. 5. Weak/non-existent Windows support 6. No multicore support 7. Obviously small community 8. Nil handling takes a bit getting used to (coming from Ruby) 9. Error messages are hard to read with overloaded methods wherein just the types are used without any indication of what doesn't match Overall, if the above changes, I'd switch to it in a heartbeat!
- daptaq 4y ago> 2. No language server (apparently it's just impossible due to the way the language works). Tbh, I'd be happy with just "Go to definition" but alas, no-can-do! Emacs' dumb-jump appears to have some basic support for go to definition: https://github.com/jacktasia/dumb-jump/blob/master/dumb-jump.el#L701 https://github.com/jacktasia/dumb-jump/blob/master/dumb-jump... But out of curiosity, what is the issue from a technical point of view?
- straight-shoota 4y agoThe technical challenge is that a Crystal program needs to be inspected as a whole. Simplified, changes in location A can have effects on some completely unrelated location B. That makes it hard to cache intermediary results and a semantic analysis needs to cover the entire program (including the standard library), not just the files that were changed since the last time. This applies to the responsiveness and memory consumption of the language server as well as the regular compilation process. So this is an important topic, and we're working on improvements. It's a complex topic, but there are some ideas.
- 4y ago
- dj_mc_merlin 4y agoI always plug this when given the chance: https://github.com/ffwff/lilith https://github.com/ffwff/lilith Full multi tasking, POSIX compliant yadda-yadda actual OS written in Crystal. The author was also apparently in high school at the time.
- straight-shoota 4y agoCrystal is reaching its 10th anniversary (of the first commit). To celebrate that there is going to be a live event next Monday: https://forum.crystal-lang.org/t/10-years-of-crystal-celebratory-ama/4874 https://forum.crystal-lang.org/t/10-years-of-crystal-celebra... We're exploring the history and future of the language with past and current core contributors as well as industry guests.
- jbirer 4y agoFor someone like me who never managed to make himself enjoy the Python syntax, Crystal seems like a great choice, and I realize I just forgot about it recently. If there's enough libraries available I might just dive in.