Live data from Hacker News

Building a Command-Line Application with Crystal

jclem.net

11–20 of 35 posts

Re: Building a Command-Line Application with Crystal

#11
I've spent a number of years using ruby and I got super excited about the potential of Crystal about a year ago. The notion that I can use a Ruby-like syntax and ship a binary to deploy my web apps was killer. But, a year ago the language was a bit rough, and to some extent, it still is. The team behind it is open about their goals and it blows me away with how much changes on a daily basis for a team of their size. Hopefully, the crystal team can set out to complete what they set their sights on for 2017[1]. That would really round out the feature set for a 1.0 release.

I think what I like the most is the community is willing to help you out. Although, nowadays a strong community is what makes or breaks a language.

[1] https://crystal-lang.org/2016/12/29/crystal-new-year-resolut...

Re: Building a Command-Line Application with Crystal

#12
post #8

Hmm, seems like the author either does not know about JSON.mapping [0] or just chose not to use it. Honestly, the corresponding macro for YAML is the main reason I use Crystal for CLI apps since it comes with the stdlib. YAML is easy enough to write quickly that I don't have to do too much with option parsing. Plus you can just use your editor rather than the shell. [0] https://crystal-lang.org/api/master/JSON.html#m…

I do use it in this project, but most definitely in the wrong way. I had a little trouble seeing how I could use it for getting at nested values of varying types and still have some sane error handling. This post is very much about my first pass at this and my first experience with Crystal. Cleaning up the JSON parsing is the next item on my list when I have time.

Here's a quick gist that does what I think you want, modulo any specific error handling. https://gist.github.com/usernamefornow/14f972df9429146b46846...

edit: note that the cleanest way would probably to write your own converter so you could avoid the union type, but I didn't want to put that in and have to write a comment about it.

Re: Building a Command-Line Application with Crystal

#13
post #6

Earlier quoted context omitted.

CoC, bad compiler, bad type system, no formal proofing whatsoever, some of documentation reads like someone who knows English as a second or third or fourth language wrote it, in some cases it's just plain wrong. Elixir has already taken most of the ruby mindshare, the crystal team really isn't hacking it when it comes to presenting why crystal should be used instead of ruby except for speed. That its faster is the o…

Elixir is by far my favorite language out of the 6 I've seriously tried (Elixir, Ruby, JavaScript, Python, Java, Bash). I'm​ gonna dive into Go in near future.

I would honestly be very surprised if you said Bash was your favorite of the 6.

Re: Building a Command-Line Application with Crystal

#14
post #8

Earlier quoted context omitted.

I do use it in this project, but most definitely in the wrong way. I had a little trouble seeing how I could use it for getting at nested values of varying types and still have some sane error handling. This post is very much about my first pass at this and my first experience with Crystal. Cleaning up the JSON parsing is the next item on my list when I have time.

Here's a quick gist that does what I think you want, modulo any specific error handling. https://gist.github.com/usernamefornow/14f972df9429146b46846... edit: note that the cleanest way would probably to write your own converter so you could avoid the union type, but I didn't want to put that in and have to write a comment about it.

Makes sense, thanks. For some reason, I was set on parsing the "env" values into instances of the same class, regardless of what type they were in JSON, but it's not really necessary. I'll also look into writing custom converters, because I'll likely need that in the future.

Re: Building a Command-Line Application with Crystal

#15
post #4

Earlier quoted context omitted.

CoC, bad compiler, bad type system, no formal proofing whatsoever, some of documentation reads like someone who knows English as a second or third or fourth language wrote it, in some cases it's just plain wrong. Elixir has already taken most of the ruby mindshare, the crystal team really isn't hacking it when it comes to presenting why crystal should be used instead of ruby except for speed. That its faster is the o…

I've started to transition from Ruby to Crystal for my pet projects and haven't hit any serious issues so far. Since you seem to have much more experience than I do, would you mind elaborating a bit on the issues you found and why you think the compiler and type system are bad?

I wouldn't count on it, judging by his previous comments he seems to prefer drive-by snipes over discussions. The fact that he made so many claims about how bad Crystal is without even attempting to explain why doesn't really make him seem credible. And the icing on the cake gotta be how he nitpicks on very minor grammatical errors made by non-native english speakers which he also seems to be completely unaware of that they are. Even I - a Swedish person - fully understand every sentence I've read so far, and English is not my primary language either.

I wouldn't take this guy seriously until he brings forth some constructive criticism.

Re: Building a Command-Line Application with Crystal

#16

Earlier quoted context omitted.

CoC, bad compiler, bad type system, no formal proofing whatsoever, some of documentation reads like someone who knows English as a second or third or fourth language wrote it, in some cases it's just plain wrong. Elixir has already taken most of the ruby mindshare, the crystal team really isn't hacking it when it comes to presenting why crystal should be used instead of ruby except for speed. That its faster is the o…

> ... some of documentation reads like someone who knows English as a second or third or fourth language wrote it, ... Um, what's wrong with that? Not everyone gets to learn English as their first language, do their efforts deserve to be discarded just because of that? I mean, I could point out that your grammar ('some of documentation') invalidates your entire comment, but that's kinda silly.

> I could point out that your grammar ('some of documentation') invalidates your entire comment, but that's kinda silly.

He's not writing the hopefully high profile documentation for a project that people want to be used, ffs. No, it doesn't deserve to be discarded because of that, but it's clearly suboptimal.

Re: Building a Command-Line Application with Crystal

#18

Earlier quoted context omitted.

CoC, bad compiler, bad type system, no formal proofing whatsoever, some of documentation reads like someone who knows English as a second or third or fourth language wrote it, in some cases it's just plain wrong. Elixir has already taken most of the ruby mindshare, the crystal team really isn't hacking it when it comes to presenting why crystal should be used instead of ruby except for speed. That its faster is the o…

> ... some of documentation reads like someone who knows English as a second or third or fourth language wrote it, ... Um, what's wrong with that? Not everyone gets to learn English as their first language, do their efforts deserve to be discarded just because of that? I mean, I could point out that your grammar ('some of documentation') invalidates your entire comment, but that's kinda silly.

I absolutely do not share the opinion of person to whom you are replying, but to state that their comment is invalid due to a trivial typo is unnecessary, and has potential to be incendiary.

Re: Building a Command-Line Application with Crystal

#19
post #7

Anyone compare Nim to Crystal? Both are AOT languages with syntax inspired by dynamic languages (Python & Ruby). Nim transpiles to C and Crystal uses LLVM. I've been playing with Nim, but I have a feeling Crystal will catch on quicker.

i think nim has better compiler options (in particular, i don't know if it has already achieved go-like cross-compilation of static binaries, but if not it's further along that road than crystal is). https://nim-lang.org/docs/nimc.html meanwhile, crystal does not even support windows yet. https://github.com/crystal-lang/crystal/issues/26

Go-like cross-compilation only works with pure Go libraries that don't make use of either syscalls or cgo.

Re: Building a Command-Line Application with Crystal

#20

Dangit, doesn't work natively on windows without bash :( And I'm all windows lately. Guess I can try it on my mac but that's like over there. I do love the multi-platform-ness and single file of go, so it'll be cool to try this and get some ruby love.

It seems like porting Crystal to run on WIndows is work in progress: https://github.com/crystal-lang/crystal/pull/3582
Post reply on HN