5 ms·
I'd love to hear stories about actual Crystal use. Of all the languages I've seen emerge in recent years, it was the one I was most conceptually fond of. It's
by wheels 4y ago
I'd love to hear stories about actual Crystal use.
Of all the languages I've seen emerge in recent years, it was the one I was most conceptually fond of.
It's basically (progressively-) statically typed Ruby, but fast (compiled). I enjoy writing Ruby, but I hate maintaining it.
- nerdponx 4y agoI enjoyed poking around at Crystal, but its library ecosystem seems heavily oriented towards web development (understandably, because its creators are a web dev consultancy), and I don't do much web development for my hobby programming. Also, I found that its static analysis tooling (eg LSP server) was really slow. Compiling small programs was also rather slow, and it generated large binaries. I also had some difficulty understanding the documentation related to importing and including modules and classes; it seemed written from a perspective assuming that the reader already knows Ruby, which I do not. At the time, I was also curious about Common Lisp and Nim, so I spent a bunch of time learning the former, and have lately been writing small personal scripts/tools using the latter. My experience using Python for backend web development has been mixed. If I had to do work like that professionally in the future, I would be happy to do it in a language like Crystal. It seems a lot more comfortable to me than Go, less intimidating than a JVM language (Kotlin?), and less "weird" than Common Lisp or a functional language like OCaml. It doesn't seem like a bad choice for a company willing to invest in engineers while they learn the language, and maybe invest in writing some of their own libraries while the ecosystem is still young. I felt like I was able to get productive fairly quickly. I think an interesting project would be to write a fairly simple web server (maybe some basic REST CRUD thing using idiomatic code) in several languages and frameworks, and compare their performance, ease of getting started, and complexity of the code. I had started working on this myself at one point, and it seems like it could be worthwhile to pick up again, especially now that all of the language ecosystems I had in mind have matured a little bit.
- mhenders 4y agoRegarding different languages and frameworks, I found this informative: https://www.youtube.com/watch?v=FQPlEnKav48 https://www.youtube.com/watch?v=FQPlEnKav48
- nerdponx 4y agoThis is great. It's a shame that so much good programming content is locked away in videos on proprietary platforms.
- socialdemocrat 4y agoI used to be a huge Ruby fan but I got to say Julia had proven to be a much nicer language than Python or Ruby ever was. It gives stronger typing so it feels a bit more like a statically typed language in terms of safeguarding you, but without getting in the way. Lot of the power of LISP without the odd syntax. Problem is the community is not web focused so you may not find enough choice in web libraries to your taste.
- nerdponx 4y agoI am a data scientist, so I've always been interested in Julia and have had fun messing around with it, even if I can never find an excuse to use it at work. Have you been using Julia for a "general purpose" programming? It seemed very domain specific to me, more like an upgrade from R and Matlab then something you would write a web server with.
- hipster_robot 4y ago> static analysis tooling (eg LSP server) was really slow. Compiling small programs was also rather slow, and it generated large binaries. Compile times have taken a nose dive in the last couple versions, but I’m not sure about the binary size. I’ve never looked honestly.
- hamandcheese 4y ago> I enjoy writing Ruby, but I hate maintaining it. Sorbet helps immensely in this regard (though it does perhaps make writing ruby a bit less joyful). The Sorbet language server works great (at least with VSCode) - I have pretty reliable go-to-definition and intellisense. I would imagine that if crystal had a decent language server the experience would be even better than Ruby+Sorbet.
- wheels 4y agoRefactoring tools are nice (I guess; I've honestly only used them in Java; I'm mostly an Emacs person), but my main gripes with Ruby maintenance are harder to fix with type annotations: - In duck-typed languages you have to write a lot of tests to do verify things that the compiler does for you in statically typed languages. That neuters much of the benefit of the concision of such languages. Crystal shoots for the best of both worlds. (Static type checking, but usually without explicit signatures.) My main refactoring tool in statically typed languages is the compiler: if I break something, it'll tell me. - Monkey-patching, open classes, etc. I do it too. Pretty much every Ruby-ist does. But it makes it damn near impossible to track down bugs sometimes, because even finding out what file the relevant code is in isn't trivial. Again, Crystal seems to mostly side-step that pitfall. - Speed. I don't even attempt to write fast code in Ruby (though I have written a few C++ extensions for Ruby in a pinch). But if I could get near-to systems-language level performance out of something that was almost Ruby, that'd be pretty amazeballs.
- pmontra 4y ago> In duck-typed languages you have to write a lot of tests to do verify things that the compiler does for you in statically typed languages Would you give some examples? I think I'm testing only functionality but maybe I'm not realizing that I'm testing the types of arguments.
- wheels 4y agoSure. Ruby: def foo(a) raise ArgumentError unless [ :bar, :baz, :quux ].include?(a) return 1 end def test_foo assert_raise(ArgumentError) { foo(1) } assert_raise(ArgumentError) { foo(:moo) } assert_instance_of(foo(:bar), Integer) end In C++ I'd write: enum class Value { Bar, Baz, Quux }; int foo(Value a) { return 1; } In a strongly typed language you don't need to do any of the input validation. I'm not sure that I'd do that level of granularity of tests in an application, but I spend a lot of times writing libraries, where it's pretty important. You also have to call all code paths with your tests in Ruby because otherwise you won't hit errors. Just basic, "this thing runs, the methods it calls exist, it returns a value, and it's of this type" is all guaranteed in a strongly typed language and doesn't need to be explicitly tested.
- freediver 4y agoThe backend for Kagi Search is powered by Crystal.
- noaheverett 4y agoWe use it in production for our products at https://ark.fm https://ark.fm and are actively working to move all of our Rails apps over to Crystal which ironically this framework looks great and may be a good choice for us. (Thank you to the author!) Our email service runs an image proxy (to hide your IP from email trackers) with probably about 30-50 lines of code in Crystal that's been in production for multiple years and it just works. Current project (in the cloud hosting space) that will heavily use Crystal for backend management and WASM which was recently introduced into Crystal and is a game changer for our use-case. Also wrote a command-line tool with it and it feels like I'm cheating at how easy it is to do so. Coming from the Ruby/Rails world where you have to cap deploy/bundle etc to push to a production server and hoping nothing breaks on dependancies makes Crystal's single binary deploy a breath of fresh air...not to mention the performance. We run our own hardware so being able to (eventually once we've moved over fully to Crystal) run the same workloads on LESS hardware with electric prices spiking is financially attractive. As you can tell I'm a fan boy. I'm betting heavily on Crystal and going all in with our stack. Did I mention it is fast?
- shafyy 4y agoKagi (the search engine) is built on Crystal.
- fdr 4y agoThe Crunchy Bridge CLI is written in crystal: https://github.com/CrunchyData/bridge-cli/ https://github.com/CrunchyData/bridge-cli/. The program that monitors databases is likewise a crystal program. There are a few other crystal programs rolling around. My biggest grievance with Crystal is the lack of incremental compilation. I understand why it's difficult to achieve given the language model, and some of the conveniences of that model. I've been watching the Crystal Interpreter with interest, it would be pretty cool if it could speed up my `M-x crystal-spec-line` interactions, along with all the other usual benefits of an interpreter. On the other hand, there's a lot to like about Crystal: it has a convenient yet powerful type system, good error messages, good support for invoking C subroutines in libraries, and generates efficient object code in a straightforward manner.
- compumike 4y agoMy side project https://totalrealreturns.com/ https://totalrealreturns.com/ is now about 5k lines of Crystal. There are some rough edges: in particular I think it could use a better templating solution (a port of HAML would be ideal!), and there are some failure modes with the Redis connection pool that have required workarounds. This includes unit tests: the built-in spec framework is great and much like rspec. https://crystal-lang.org/reference/1.6/guides/testing.html https://crystal-lang.org/reference/1.6/guides/testing.html I'm now starting to use Crystal for internal backend infrastructure and microservices. For anyone who wants to kick the tires on Crystal, I built a crystal-docker-quickstart project template: https://github.com/compumike/crystal-docker-quickstart https://github.com/compumike/crystal-docker-quickstart works without having to install anything locally. (Assuming you have docker.) You can have your own, home-built "Hello world" static binary in under a minute: git clone https://github.com/compumike/crystal-docker-quickstart.git my_app && cd my_app && ./d_dev # in the shell that appears: make && out/my_app Then just edit src/main.cr and you're off and running :)
- paulgb 4y agoThat is one fast-loading page, especially for (what looks to be) dynamic data! Are you doing anything special or just using a good CDN?
- compumike 4y agoThanks :) No CDN actually -- it's just a side project served straight from a single VPS at the moment. You're probably just seeing the speed of response caching (which I've written in Crystal too, using Redis and local disk as storage backends). If you request a new ticker symbol that isn't already cached, or specify custom date ranges, it will recompute or even have to fetch data from upstream data provider, and those requests will take a bit longer. Also, the whole site is currently served up as a single HTTP request, except for a few external JS and CSS files (Bootstrap, uPlot) which are served from public CDNs.
- victor106 4y agoNice!!! What are some advantages of Crystal over other languages like Go, Java.C#, Rust?
- rdevsrex 4y agoThe only time I used Crystal for work was for creating zip files from a virtual file system in the database that fetched the real file files from S3. It was pretty easy to write, but I kept on having some issues with the part of the standard library that handled the zipping. As Crystal is kinda a small community, I didn't get a lot of feedback from the forums. So I just took a day to rewrite in Go, and its zip library worked great. I'm sure I could have got it working with Crystal if I had more time. I haven't done anything else, but it was fun writing it.
- phil294 4y agoI have recently learned to use it to create an AutoHotkey for Linux implementation (https://github.com/phil294/AHK_X11 https://github.com/phil294/AHK_X11), and it's been a delightful experience. If you like programming in Go and Ruby syntax, this will be your go to language. Other than that, it bears but few surprises, which I would consider a good thing. Its major downside is its compilation time and poor IDE support. Also, you should not be afraid to search through Crystal's GitHub issues or dig into the well designed stdlib's source for more exotic use cases. However, the latter is as easily accessible as is your own code, and the community around Crystal seems quite friendly and welcoming. Contrary to sibling comments, I find it well suited for programs outside of web development as well. And most of all, it's fast.
- hota_mazi 4y ago> I enjoy writing Ruby, but I hate maintaining it. This is the curse of all dynamically typed languages: they make the developer's life easier at the expense of the future maintainer of the code. Because there are no type annotations, writing code is a lot easier than reading it. Which is the exact opposite of what we want.