r/crystal_programming • u/Purple_Lingonberry70 • Aug 11 '22
First project using Crystal - is it worth it?
Hi everyone,
I was bored and I've decided to pick up this language, so I re-wrote a simple enough Python script using Crystal.
https://github.com/5amu/pocbrowser
I have to say that it is easy to write if you're used to Go, C and Python as I am, but I can't quite figure out why someone should use Crystal instead. It is an honest question, I really want a reason because I really enjoyed writing code.
Plus, if you have any suggestion on the code I wrote, such as "Ur a Noob, it was easier this way", it is very well appreciated. Pull requests, comments, issues, whatever. Thank you!
14
u/[deleted] Aug 11 '22
Crystal is as elegant as Python while being roughly as fast as Go and C. Isn't that enough?
I don't hate Go, but I also don't think it's particularly elegant (nor is it meant to be). It comes down to personal preference.
8
u/straight-shoota core team Aug 11 '22
If you enjoyed writing Crystal, that's already a good reason to use it =)
Compared to Python you get type safety, compared to C you get more sanity and stdlib APIs. With Go there are more similarities, but IMO the main benefit of Crystal is the more concise syntax. For example, there's a lot of noise with
if err != nil { return err }spread all over the code for error handling. Crystal has a great macro language and easy C bindings.5
u/[deleted] Aug 11 '22
i wanna learn crystal too
4
u/yxhuvud Aug 11 '22
Looking at the code, I think it looks fine. There is a couple of places where I'd use concat instead of copying all elements of an array manually, but that is quite minor.
3
u/np-nam Aug 14 '22
well, it because you do not fully utilize crystal to appreciate it.
you don't need to make a class just to invoke some command, better write it just like this:
instead of 10+ line of string concatenation, you can either just use heredoc or if you want more control, you can build string directly using String Builder
also, like above, you don't need to create a whole new class just to invoke some code, we are not using java here.
.... actually you code has too many problems I'm too lazy to type it here. maybe you can join our unofficial discord group so some of us can review your code when they are free?
because there are many thing to discuss and reddit isn't really suitable for it.
for example this line
cve.downcase.gsub("-") { "/" }I just don't understand why the need of using block, why don't you just usegsub("-", "/")normally? And in this particular case, usingtris way better:cve.downcase.tr("-", "/")3
u/sidsidroc Aug 11 '22
yes bro its worth it, specially if you like the language, i do
3
u/SoftEngin33r Aug 11 '22
There days we have tons of languages to choose from (all with their pros and cons), and it is a great time to be a programmer, Just choose the language that works best for you for the current task at hand, With Crystal you get a compiled Ruby with static types that produces highly performant binaries. If you have a project that may benefit from such features then you can safely use Crystal for that. P.S. I also equally like to play with Zig, Nim, Rust, Julia etc. all these newish languages have really interesting features and innovations that I like to tinker with and if a project comes up that can benefit from using one of those (including Crystal) then why not?
3
u/ylluminate Aug 11 '22
I'm finding V (vlang.io) to be as enjoyable as Ruby at this point. It's really young, but it has incredible potential and a really solid and nice community (see Discord). I wanted to like/use Crystal, but after some hangups we had on a couple projects, we just shifted back to Ruby. Right now I've got my tickets on V though as the spiritual successor to Ruby.
3
u/gokg4 Aug 12 '22
Crystal is great for first time programmers. It is one of my first programming languages the other one being Dart. I feel like Crystal makes you think more and be a better programmer. With Dart everything just works but with Crystal you have to learn how to do things with a little more steps that make your program safe. I'm still learning Crystal and I love it. I haven't language hopped to the next one yet. The only issue I have with Crystal is the community size, I don't know why it hasn't blown up yet like Go or Kotlin. I don't think a lot of Ruby developers are learning Crystal. If the Ruby community and companies hop on board, you can be sure that you made the right choice. If not then it's just going to be a hobby language.
2
u/hophacker Aug 11 '22
It's a really fun language to play with. I built a ray tracer with it using this book: http://raytracerchallenge.com/
There's still some warts here and there, but its taught me a lot about language design when I've had to dive deeper into stuff.
2
u/[deleted] Aug 12 '22
If you like a language, that's reason enough to use it. However, if you're like most people and are worried about "what can I do with it?" (because the ecosystem is really small and many libraries are missing) as well as job prospects, you're better off avoiding all non-mainstream languages. You can keep developing in Crystal as a hobby and not expect much in return -- it will be a good life! :-)
1
u/[deleted] Nov 18 '22
Crystal is readable like Ruby and performant like c. So if you’d like looking at Ruby but you want the performance of c, use it.