News for hackers. Stuff that matters.
Re:Crystal 1.0 – What to expect by ibraheemdev on Monday March 22, 2021 @02:57PM (#26545169)
It feels like Crystal it took all the best things from the languages I love, and put them together into one, beautiful language:

- Elegance of Ruby

- Statically type checked + global type inference

- No Nulls

- Go-like concurrency

- Easy C ffi

- High performance

I really hope the Crystal succeeds and the language goes mainstream - this release is a huge step forward towards that. Congrats to the Crystal team for reaching the 1.0 milestone!

Re:Crystal 1.0 – What to expect by Can_Not on Monday March 22, 2021 @09:47PM (#26550008)
Also, it produces binaries (probably similar to golang) which are a reasonable size considering there is a garbage collector. No giant interpretors or VMs required.

And macros.

Re:Crystal 1.0 – What to expect by rjzzleep on Tuesday March 23, 2021 @04:17AM (#26552376)
What is the compilation speed like?

EDIT: also forgot to ask if Crystal has a "killer app" yet? Ruby had Rails, Python had scipy/pandas(several others), Rust had servo etc.

Re:Crystal 1.0 – What to expect by Sathi on Tuesday March 23, 2021 @06:51AM (#26553442)
Yes, there are lucky and amber frameworks. Hopefully, one of them will make crystal more popular/mainstream.
Re:Crystal 1.0 – What to expect by unixhero on Tuesday March 23, 2021 @04:30AM (#26552462)
Why is that important given Moores law and fast developer workstations?

Everyone seems so preoccupied with compile speed for Crystal.

Re:Crystal 1.0 – What to expect by m12k on Tuesday March 23, 2021 @04:45AM (#26552558)
I think if you've been bitten by compilation times in e.g. Scala or C++, then compile speed is something you end up caring about. When it comes to modern static languages, it seem like there's a tradeoff where providing all the abstractions and ergonomics to make you not miss any functionality from dynamic languages will instead expand compilation times and make you miss the instant feedback of an interpreted language. Or give up on that and make the language much simpler and more limited, and you get fast compilation (e.g. Go). So I think people are looking for the holy grail of a language with both ease of use, extensive ergonomics and abstractions, while maintaining fast compilation times. So anytime a candidate comes along they ask about the parts of that equation that are not in the bullet list.
Re:Crystal 1.0 – What to expect by pjmlp on Tuesday March 23, 2021 @05:38AM (#26552894)
C++ compile speeds can be easily improved when using binary libraries, incremental compilation, incremental linking, and hopefully modules will help as well.

Energize C++ and VA C++ v4.0 showed the way of a Smalltalk like experience for C++, the tools just need to catch up with the past.

VC++ and C++ Builder are on the good path for it.

Re:Crystal 1.0 – What to expect by rad_gruchalski on Tuesday March 23, 2021 @12:06PM (#26556648)
Adding to that, sbt also supports incremental compilation with zinc.
Re:Crystal 1.0 – What to expect by andi999 on Tuesday March 23, 2021 @09:50AM (#26554945)
Don't forget pimpl.
Re:Crystal 1.0 – What to expect by reitanuki on Tuesday March 23, 2021 @04:36AM (#26552488)
Moore's law has stopped, and not every developer's workstation is 'fast'.
Re:Crystal 1.0 – What to expect by yberreby on Tuesday March 23, 2021 @04:35AM (#26552484)
Because high compilation times can be a major turnoff, and the single-threaded performance of a beefy developer workstation is not that much higher than that of a regular machine. You can't always throw more cores at a problem, and Moore's Law hasn't exactly been holding true lately.
Re:Crystal 1.0 – What to expect by andi999 on Tuesday March 23, 2021 @04:39AM (#26552515)
It is a huge difference if you can compile is less then a second (giving you almost repl functionality) or if you have to resort to nightly builds for large projects. Even 15 minute builds hamper development.
Re:Crystal 1.0 – What to expect by Cthulhu_ on Tuesday March 23, 2021 @04:45AM (#26552557)
Compile speed is part of Developer Experience, and one of the most important aspects thereof is the feedback cycle. I want to see the results of my code changes as fast as possible, and the performance of my hardware is rarely ever the bottleneck.
Re:Crystal 1.0 – What to expect by christophilus on Tuesday March 23, 2021 @08:00AM (#26553997)
Once you've gotten used to the speed of something like OCaml and Go, it's really hard to go back. Rust feels excruciating to me, even though I like the language.
Re:Crystal 1.0 – What to expect by dexterlagan on Tuesday March 23, 2021 @04:41AM (#26552525)
Two kinds of people: - people who routinely compile huge code bases; - people who compile an OS. C is still here because it compiles UNIX fast.
Re:Crystal 1.0 – What to expect by rjzzleep on Tuesday March 23, 2021 @04:52AM (#26552611)
Even there compile speeds make a difference. The linux kernel is quite slow to compile, but when you make changes it doesn't take that long because it generally just rebuilds a file or two fairly quickly because of the way dependencies and changes are handled. If every driver change would require 15 minutes to build it wouldn't be nearly as popular as a platform.

I don't know how opensolaris kernel builds are, but they're not nearly as simple to wrap your head around as the linux kernel. As a result the level of participation is quite low.

Of course this is more a build issue than it is a language issue in this case.

But yes as you said the compile speed on the linux kernel is partly because it's C and not C++

Re:Crystal 1.0 – What to expect by pantulis on Tuesday March 23, 2021 @04:32AM (#26552472)
The question is legit, though.
Re:Crystal 1.0 – What to expect by unixhero on Tuesday March 23, 2021 @04:34AM (#26552480)
Sure enough. Still wondering about why.
Re:Crystal 1.0 – What to expect by pantulis on Tuesday March 23, 2021 @04:58AM (#26552638)
Also, this observation: in terms of developer time, compiled languages (a la Crystal, Go, Rust...) the disadvantage of compile time should be offset by much faster local test runs and even CI builds.
Re:Crystal 1.0 – What to expect by atleta on Tuesday March 23, 2021 @10:27AM (#26555423)
You'll usually just run a few tests if you are working on a specific feature and only run more of them when you think you are done. So most of the time there will be too little difference to make up for the increased compilation time.

Also, you are comparing compiled languages to interpreted ones, but the GP talked about differences between compilation time (i.e. compiled languages). And others are also comparing it to e.g. go (compiled but quick to compile).

Re:Crystal 1.0 – What to expect by pantulis on Wednesday March 24, 2021 @06:10AM (#26565349)
You are totally right.
Re:Crystal 1.0 – What to expect by pantulis on Tuesday March 23, 2021 @04:58AM (#26552642)
For a sufficiently big codebase, that is.
Re:Crystal 1.0 – What to expect by exikyut on Tuesday March 23, 2021 @10:23AM (#26555366)
Well, I have ADHD. I've found the most effective approach (on top of treatment) that helps me retain focus is reexec-on-save, a la `while :; do tput clear; $thing; inotifywait -q -e moved_to .; done`. I usually have a dozen of those in old shell histories (^R FTW). (Ha, my laptop actually has exactly 12, and my other machine has 23 - although ignoredups is off...)

$thing might be `bash ./script.sh` (because my text editor's atomic rename doesn't understand execute bits >.>), `php script.php` or `gcc -O0 script.c && ./script`. (Also, as an aside I used to use `-e close_write $file` until I realized watching even giant directories is equivalently efficient to watching a file.)

Shell scripts (the small kind that run few subprocesses) are typically fast. Likewise, small C programs of <1000-2000 lines compile just about instantly on modern hardware; and where modern hardware isn't available and what I'm trying to do doesn't leverage too many libraries or whatnot, tcc has been able to swing the balance firmly in my favor in the past, which has been great.

But for better or worse, PHP is currently the language I use the most. Because it's faster than Python and Ruby.

A while back I wanted to do a bit of analysis on a dataset of information that was only published as a set of PDF documents... yayyy. But after timidly gunzipping the stream blocks and googling random bits of PDF's command language ("wat even is this"), I discovered to my complete surprise that it was trivial to interpret the text coordinate system and my first "haha let's see how bad this is" actually produced readable text on pretty much the first go. (To be pedantic, step #-1 was "draw little boxes where the text should be", step #0 was "how to x,y correctly" (with a side serving of "...those boxes look quite reasonably positioned..."), and step #1 was "replace boxes with texWHAT it worked?!")

With rendering basically... viable (in IIRC 300-500 LOC O.o), the next step was the boring stir-the-soup-for-144-hours bespoke state machine that cross-correlated text coordinates with field meanings ("okay, that's a heading, and the next text instruction draws the field value underneath. OK, assert that the heading is bold, the value is not, and they're both exactly the same (floating-point) Y position").

While that part took a while, it was mostly extremely easy, because I was pretty much linearly writing the script "from start to finish", ie just chipping away at the rock face of the task at hand until I processed an entire document, then the next document ("oh no"), then the next one ("ugh") and so forth ("wait, the edge cases are... decreasing? :D"). My workflow was pretty much founded entirely on the above-noted method where I would re-exec the script from scratch upon save.

Loading/gunzipping a given PDF and getting to the point where the little pipeline would crash would typically complete well before I had a chance to release the CTRL key after hitting CTRL+S. So while the process was objectively quite like stirring soup, it did not feel like that at all and I was able to kind of float a bit as my brain cohesively integrated the mental model of the architecture I was building without any distractions, pauses or forced context switches getting jammed in the mental encoding process like so many wrenches.

Soon 15 documents were handled correctly, then 20, then 30, then 100 ("oooh, if all the items on the page add up exactly right it pushes line 2 of the summary heading down to the second page! Hmmm... how on earth to special-case that without refactoring to look at more than 1 page at a time..."), and then I hit some sort of threshold and it suddenly just started ticking through PDFs like crazy without asserting. Which was both awesome and a Problem™: the thing ran at something like ~60 PDFs/sec, and while jumping to just after the last successfully-processed PDF on restart worked great when the code crashed constantly, now I was sitting spinning for tens of seconds, getting distracted as I anticipated the next crash. ADHD(R)(TM).

I wasn't surprised to learn from htop that the script was disk-bound; for some reason my ZFS mirror setup will happily read sequentially at 200MB/s, but thousands-of-tiny-files situations are... suffice to say apt unconditionally takes 60 seconds to install the smallest thing, unless the entire package db is in the FS cache. I'm not sure why. The PDFs were sharded sanely, but they were still in separate files. So I decided to pack them all into a giant blob, and since there weren't too many PDFs and they were numbered sequentially I used a simple offset-based index at the front of the blob where `fseek(data_start + (<PDF ID> * 4)); $o = fread(4); fseek($o);` would give me random seeking when I needed it, or I could just fseek() to data_start and start reading directly.

Reading the blob instead promptly pegged a single CPU core (yay!), and gave me IIRC ~150-200+ PDFs/sec. This was awesome. But I was still just a tiny bit curious, so after googling around for a profiler and having a small jawdrop moment about SPX (https://github.com/NoiseByNorthwest/php-spx), I had a tentative look at what was actually using the most CPU (via `SPX_ENABLED=1 php ./script.php`, which will automatically print a one-page profile trace to stdout at graceful exit or ^C).

Oh. The PDF stack machine interpreter is what's taking all the CPU time. That tiny 100 line function was the smallest in the whole script. lol

So, I moved that function to the preprocessor/packer, then (after some headscratching) serialized the array of tokenized commands/strings into the blob by prefixing commands with \xFF and strings with \xFF\xFE\xFF so I could explode() on \xFF and tell commands from strings by checking if the previous entry was \xFE (and just skip entries of '\xFE' when I found them) :D. Then I reran the preprocessor to regenerate the pack file.

  $ php convert_dlcache.php 
  Scanning...
  24/66060
  67,927 entries [4.27 sec]
  Sorting... 10013-343271 [1.61 sec]
  data_start=1373094
  * 67,920/67,927 99.99% 83/s 00:00 13:58 343259
Thankfully I've only needed to run the preprocessor rarely, like for example I only needed to run it twice today because it promptly truncated its pack file when I accidentally reran it after the first run (yay). Yes, it really does take ~14 minutes, and yes, there are just under 70,000 PDFs.

Then I reran the pipeline script.

  $ php conv2.php
  67,927/67,927 890/s 01:16 00:00 343271
  
  Complete
Oh. 900 PDFs/sec.

Uh, what happens if I... set up a simple pcntl_fork() + stream_socket_pair() multi-process worker system...?

  $ php conv2.php
  Reading... done
  4 workers, (16,982 x 3) + (16,981 x 1)
  62,162/67,927 1,800/s (469/s 166319, 444/s 237743, 442/s 302338, 444/s 340327) 00:34 00:03
  ^C
"Oh. Okay."

":D"

(The workers disappear from the output as they complete, so I ^C'd it just before they all exited, at 3 seconds left.)

So. 68,000 PDFs/sec on a not particularly amazing 3.3Ghz i3-3220 with 1600MHz RAM.

PHP 8's JIT is aweso--wait, is the JIT actually on?

Oh. It's off by default.

  $ php -dopcache.enable_cli=1 -dopcache.jit_buffer_size=32M conv2.php
  Reading... done
  4 workers, (16,982 x 3) + (16,981 x 1)
  58,206/67,927 2,537/s (669/s 163803, 623/s 230254, 619/s 300420, 627/s 338470) 00:22 00:03
*Blinks*

(In small voice) "I am processing/unit-testing 68k documents in 22 seconds. At over two and a half thousand PDFs a second."

I also noticed that

    PID USER      PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command
  31511 i336       20   0  276M 19864  5736 R 100.  0.2  0:18.25 php conv2.php
  31513 i336       20   0  276M 19856  5732 R 100.  0.2  0:18.35 php conv2.php
  31512 i336       20   0  276M 19728  5600 R 100.  0.2  0:18.32 php conv2.php
  31510 i336       20   0  276M 19764  5648 R 97.7  0.2  0:18.03 php conv2.php
  31509 i336       20   0  275M 34072 20036 S  0.7  0.4  0:00.19 php conv2.php
the workers are only using 20MB RAM each. This is with object deferencing going on, after I kinda started going crosseyed and properly moved my JBOGF (Just a Bunch of Globals and Functions) into a proper class (albeit a static one, since I'm still learning, and construction/deconstruction would probably slow things down too). I also note that with the JIT off, VIRT is 115M, RES is 16,312K and SHR is 2,412K for all workers, with the master taking 29M RES and 15M SHR.

--

Why'd I write all this?!

To make the point that a) live reexec on save is an awesome programming model when it can be applied, and b) PHP is my incredibly awkward gold standard reference, lol.

(In rerunning everything for this post I discovered the JIT and learned my script could go even faster!)

I've been keeping vague tabs on recent language developments from a bit of a distance for a while now, and am very interested to dig into Rust and Zig's incremental compilation capabilities at some point.

Based on what I'm hearing I don't know if I should just go dive in yet though - to be entirely honest, there are multiple realms of applications I simply cannot write in PHP - including things as simple as console CLIs, because the neccessary TTY I/O control (eg, turning TTY echo off and reading 1 char at a time) remain unavailable (see also: multiple years-old long-forgotten bugs/feature requests).

I don't really want to discover what's possible only to find myself between a rock and a hard place as my programs start to grow and I hit invisible quadratic brick walls that persist after I enable every "fastest possible" setting the language offers. That happened a few years ago when I tried to play around with FLTK in C++; once build times were around the 3-4 second mark (*with* -O0 and precompiled headers), regardless of the fact that I'd been working on the project for enough time I was invested in it, I just gave up.

Much more recently I installed .NET Core the other day to run and dissect a small F# program. Running `dotnet fsi` cold took 5 seconds to reach a REPL prompt (ouch), and while warmed-up reruns would only take 1 second, I found actually loading a ~300-line program would take a non-reducible ~4-5 seconds.

Everyone's different, and sometimes things people say can look crazy, or stupid, or "...how even...", but they can still be true for that person. For me, waiting 4 seconds for an interpreter/runtime/etc to reach a useful milestone such as "I can actually interact at all with it" is untenable. Yup. I go straight to "I've waited for this thing to do the thing 200 times today <cartoon punching fight cloud>" after the 3rd pause. I am utterly incompatible with the Old Guard "code's compiling!" way of doing things. It puts me straight into defensive not-in-my-comfort-zone mode.

Completely open-minded about Crystal, which I've heard repeatedly good things about. Yes, of course, I haven't tested it (yet), again because I don't want to go "wow this is awesome... except I don't have the patience for it :(".

The status quo noted above remains an actively unsolved problem; trying to figure out how many interesting things I can wedge into the "focusable space" defined by "how big I can make my program before the programming languge slows down" is getting boring.

Perhaps I'm just stuck here because I'm using older(ish) hardware, and once I finally figure out that problem I'll suddenly realize all of this deep analysis was unnecessary. heh

Re:Crystal 1.0 – What to expect by tlavoie on Tuesday March 23, 2021 @03:06PM (#26558965)
Thanks for your extensive write-up. PHP's definitely not my thing, but I appreciate your view of the process to iteratively dig (and dig, and dig...) into the details.

By the way, if you're looking for instant introspection, changes and carrying on, you should have a look at what you get with Common Lisp. You're able to redefine code on the fly, and continue from where things stopped. This blog post series goes into debugging, specifically with SBCL (one implementation), Emacs and an add-on called Slime.

https://malisper.me/category/debugging-common-lisp/

Re:Crystal 1.0 – What to expect by exikyut on Wednesday March 24, 2021 @10:34AM (#26567741)
For the sake of pedantic completeness: sigh, not "68,000 PDFs/sec" (that would be nice lol), more like "68,000 PDFs in 34 seconds". At the bit near "1600MHz RAM".
Re:Crystal 1.0 – What to expect by benbristow on Monday March 22, 2021 @03:57PM (#26545993)
> No Nulls

Does it not? It has 'nil', just like Ruby. Basically the same thing, the docs literally say it's 'similar to null in other languages'.

https://crystal-lang.org/reference/syntax_and_semantics/lite...

Re:Crystal 1.0 – What to expect by TylerE on Monday March 22, 2021 @03:59PM (#26546027)
It has a Nil type, not a Nil Value.

So a function might return an Int or a Nil, but if you then try to, say, invoke a function expecting an Int on a Nil, it predictably blows up. An Int cannot be Nil itself.

Re:Crystal 1.0 – What to expect by mumblemumble on Monday March 22, 2021 @04:16PM (#26546303)
To expand on that, Crystal's Nil goes hand-in-hand with its union types. So, if you want to allow a function's argument to be either an integer or nil, then the parameter type is "Int | Nil".

It's not entirely unlike how algebraic data types with a "None" case work in the ML family of languages.

Re:Crystal 1.0 – What to expect by KMag on Tuesday March 23, 2021 @03:02AM (#26551908)
In other words, it avoids "Tony Hoare's billion dollar mistake" in conflating reference types and optional types. Tony Hoare had a gut feeling that it was going to cause code messiness when he made all references reference nullable in Algol W (instead of going through and adding extra type rules and tracking for nulls), but it was a very simple change to the compiler's type checker. It was too hard to resist such a simple change that made the language more flexible, even if it introduced footguns.

In most languages without ML-like type systems, null is treated as a "bottom type", as if it were a subclass of all classes. This violates the Liskov substitution principle and results in an unsound type system.

When I was working on Google's indexing system, I was very excited to hear rumors that Ken Thompson and Rob Pike were working on a new language. When it was unveiled, I was pretty disappointed to learn that it repeated Tony Hoare's billion dollar mistake.

Re:Crystal 1.0 – What to expect by eyelidlessness on Monday March 22, 2021 @11:12PM (#26550596)
I think it would be more straightforward to say expressions (/bindings/return types etc) can be null, but not implicitly so, and must be checked for a value before attempting to use the value. Or as a sibling comment said, in TypeScript terms, `strictNullChecks`.
Re:Crystal 1.0 – What to expect by brundolf on Monday March 22, 2021 @09:02PM (#26549670)
Or TypeScript, for a more well-known example
Re:Crystal 1.0 – What to expect by nielsbot on Tuesday March 23, 2021 @01:40AM (#26551490)
I think ad-hoc union types is one of TypeScript's best features.
Re:Crystal 1.0 – What to expect by straight-shoota on Monday March 22, 2021 @04:00PM (#26546044)
More accurately would be "no surprising nulls at runtime". If a value can be `nil`, the compiler forces to treat it as nilable. It doesn't throw random null pointer exceptions.
Re:Crystal 1.0 – What to expect by Shoop on Monday March 22, 2021 @04:00PM (#26546043)
It looks like it has nullable (nilable) types [0]. So a variable cannot be nil unless it is explicitly marked as having a nilable type.

[0] https://crystal-lang.org/reference/syntax_and_semantics/type...

Re:Crystal 1.0 – What to expect by christophilus on Monday March 22, 2021 @06:29PM (#26548213)
Fast compilation times are one of the best things from the languages I love.

I’d really love to see OCaml get true parallelism, green threads, and a decent HTTP server story. Then, I don’t think I’d look anywhere else.

Re:Crystal 1.0 – What to expect by AlchemistCamp on Monday March 22, 2021 @09:06PM (#26549691)
Then Caramel just might end your search!

https://caramel.run/

Re:Crystal 1.0 – What to expect by rbjorklin on Monday March 22, 2021 @11:31PM (#26550762)
In case you haven’t been following along with the community the last prerequisite for parallelism will land with 4.13 in the next 3-6 months (guesstimate). Once that lands 5.0 is next which will have true parallelism.
Re:Crystal 1.0 – What to expect by eikenberry on Monday March 22, 2021 @11:23PM (#26550691)
Are you saying Crystal has fast compile times or that it doesn't? You seem to be saying that it does, that that is one of the things you love about it but others below are saying it is slow.
Re:Crystal 1.0 – What to expect by christophilus on Tuesday March 23, 2021 @08:01AM (#26554012)
It was really slow last time I tried it. I really like Crystal and wish it the best, but it's hard for me to imagine using a sluggish compiler as a daily driver.
Re:Crystal 1.0 – What to expect by aidenn0 on Monday March 22, 2021 @11:55PM (#26550912)
Yeah, I like everything on your list except the first one. Maybe Crystal will be compelling enough to get me comfortable with ruby-style language syntax & semantics.
Re:Crystal 1.0 – What to expect by amir734jj on Monday March 22, 2021 @03:24PM (#26545502)
Very well said. Elegance of ruby I think is very important for ruby developers who need a performant typed language.
Re:Crystal 1.0 – What to expect by jiofih on Tuesday March 23, 2021 @05:40AM (#26552907)
“Ruby developers” should not exist. You use the right tool for the job. It’s great to have an option that is (partially) familiar, but as a developer you should not be limited by syntax choice.
Re:Crystal 1.0 – What to expect by vinceguidry on Monday March 22, 2021 @11:16PM (#26550622)
Why would rubyists need elegance in a different language for perf? Do what everyone else does, and write a C extension.
Re:Crystal 1.0 – What to expect by Cort3z on Tuesday March 23, 2021 @03:21AM (#26552028)
The point is that they / we don't want to write c.
Re:Crystal 1.0 – What to expect by vinceguidry on Tuesday March 23, 2021 @10:31AM (#26555470)
Speaking personally, I don't want to write in anything else but Ruby. If I have to code in something else, well, anything's fine. I don't want "elegance" in that language. I don't need other languages to try to be Ruby. I already have Ruby. I just want to get it done so I can build on that work... in Ruby.

I just don't understand why other people seem to think Ruby isn't enough.

Re:Crystal 1.0 – What to expect by straight-shoota on Tuesday March 23, 2021 @04:15PM (#26559863)
I like Ruby, too. But Crystal is like Ruby, and better in many regards. Performance is a huge issue with any computational intensive tasks. Crystal's static typing also avoids many simple errors you would only catch in Ruby with an extensive spec suite for many edge cases.
Re:Crystal 1.0 – What to expect by vinceguidry on Tuesday March 23, 2021 @06:15PM (#26561019)
This is a Crystal discussion, and I hate it when Crystal people show up in Ruby discussions and talk crap about Ruby so I won't argue against you, other than to say that Crystal is only like Ruby in that it's syntax is superficially similar.
Re:Crystal 1.0 – What to expect by pjmlp on Monday March 22, 2021 @04:07PM (#26546171)
Me too.

I don't have any use for it, however as language geek it is quite nice to see ecosystems blossom.

Re:Crystal 1.0 – What to expect by renox on Tuesday March 23, 2021 @06:06AM (#26553111)
D and Nim looks like competition here except for the Ruby look-alike syntax of course.
Re:Crystal 1.0 – What to expect by neya on Tuesday March 23, 2021 @02:37AM (#26551773)
Just curious, as an avid user of Elixir lang, which has most of these anyway, what should be a compelling reason for someone like me to start using Crystal (more)?

Thank you

Re:Crystal 1.0 – What to expect by IfOnlyYouKnew on Tuesday March 23, 2021 @02:53AM (#26551859)
It’s blazingly fast for pure number / text crunching. As in: I use it to ingest terabytes of data files / JSON / logs at speeds indistinguishable from C but with the convenience of programming in something like ruby.

Once replaced a python script while it was running. Expected time, python: 12 hours. Time to get it running in Crystal: 20 min. Time to finish in Crystal: 12 minutes.

Re:Crystal 1.0 – What to expect by happy-go-lucky on Tuesday March 23, 2021 @03:25AM (#26552058)
> Once replaced a python script while it was running. Expected time, python: 12 hours. Time to get it running in Crystal: 20 min. Time to finish in Crystal: 12 minutes.

Can you please elaborate on this?

Re:Crystal 1.0 – What to expect by antupis on Tuesday March 23, 2021 @03:58AM (#26552265)
Reallity probably is that code was not optimized python which was writen as POC and not touched after initial write. Python is usually fast enough when using numpy,scipy etc.
Re:Crystal 1.0 – What to expect by pcl on Tuesday March 23, 2021 @04:24AM (#26552425)
At that point, you're not really "writing Python", though. You're really using Python to orchestrate a bunch of native transformations.
Re:Crystal 1.0 – What to expect by iomcr on Tuesday March 23, 2021 @09:40AM (#26554820)
> Python is usually fast enough when not using python

Agreed.

Re:Crystal 1.0 – What to expect by IfOnlyYouKnew on Tuesday March 23, 2021 @11:40AM (#26556316)
These are the python scripts: https://github.com/jonadsimon/entendrepreneur/tree/master/pr...

I don’t do enough python to judge them. But, then again, I had even less experience in Crystal back when I worked on this.

Re:Crystal 1.0 – What to expect by iomcr on Tuesday March 23, 2021 @09:38AM (#26554802)
Crystal does a better job with making portable binaries. For example I have written an app that's a 20MB alpine docker container. A comparable app written in Elixir used an 800MB alpine docker container.

I think Elixir is one of crystal's top competitors, but only for servers. Probably you'd never leave Elixir to write a webserver in Crystal. That's just Erlang's specialty. You would leave golang, Ruby, python, PHP, etc. for crystal though, because of the type system, performance, threads, binary, etc..

I've actually started using crystal to write the kinds of scripts people would normally use python for, despite it not being a scripting language.

Re:Crystal 1.0 – What to expect by The_rationalist on Monday March 22, 2021 @05:49PM (#26547704)
All of those points are already met and in a better way by mature languages like e.g Kotlin. Really the only argument would be the "Ruby elegance" (or familiarity?) which I don't know. What make ruby/crystal more "elegant" (I would prefer the term readable) than the competition?
Re:Crystal 1.0 – What to expect by bovermyer on Monday March 22, 2021 @07:54PM (#26549132)
Well, speaking purely from personal experience, Crystal is much more enjoyable to write and read than Java derivatives.

Take that with a grain of salt, though, since I have a deep-seated hatred of Java stemming from experiences in the early 00s.

Re:Crystal 1.0 – What to expect by The_rationalist on Tuesday March 23, 2021 @09:52AM (#26554958)
Interesting, could you characterize some of what make it more enjoyable?
Re:Crystal 1.0 – What to expect by ezrast on Tuesday March 23, 2021 @03:51PM (#26559573)
Kotlin is indeed very Crystal-like, and I enjoy both languages, but I really miss union types in Kotlin, as well as deeper type inference. For example, in Crystal you can write

    def foo_then_bar(a, b)
      a.foo
      b.bar
    end
and it will just work for any two types that implement `foo` and `bar`, respectively. This isn't something I do often - I like the clarity that type-annotated parameters give - but it's a really nice feature to have available in the 2% of cases where I want it.

Then there's all the ecosystem stuff - Kotlin makes me do extra work to target native, and has little bits of weirdness inherited from Java all around the edges. None of it's deal-breaking, but it is friction.

Re:Crystal 1.0 – What to expect by The_rationalist on Tuesday March 23, 2021 @10:26PM (#26562866)
Thanks for the example, that's interesting.

Note that Kotlin has union types through this compiler plugin: https://github.com/arrow-kt/arrow-meta/issues/570 However it is experimental and shouldn't yet be used in production. Btw sealed classes take care of many uses of union types.

What kind of extra work is needed? I'd say that graal native is transparant for any library that doesn't do weird use of reflection but it's true that many libraries do abuse of reflection.

Re:Crystal 1.0 – What to expect by ezrast on Tuesday March 23, 2021 @11:58PM (#26563454)
Having to install and set up third-party pre- and post-processors is the extra work I mean. I'm sure it's not super difficult, but it's also not very accessible to those like me who aren't already familiar with Java tools. The documentation seems to assume I'm slightly competent with Maven or Gradle, etc.

I did try Kotlin/native hoping it would make it easier to remain in blissful ignorance of the JVM ecosystem, but as of a year or two ago it had significant holes in the standard library (most notably no file abstractions other than thin bindings to libc) and pretty atrocious compile times (something like 10s for hello world, and 30+ for a couple thousand lines of code).

Re:Crystal 1.0 – What to expect by bovermyer on Tuesday March 23, 2021 @03:12PM (#26559061)
Sure.

The simplicity and predictability are key with Crystal; everything is an object, and the control structures are limited in number.

Crystal code is very concise and legible. You might say it's crystal clear.

Re:Crystal 1.0 – What to expect by nine_k on Monday March 22, 2021 @06:18PM (#26548094)
Kotlin mostly requires JVM, Crystal does not. Kotlin is heavily oriented towards Java familiarity and interoperability, Crystal is heavily oriented towards Ruby familiarity, and C interoperability.

Also, Crystal was first released in 2014, when Kotlin was like 3 years old, and 100% JVM-bound.

Re:Crystal 1.0 – What to expect by The_rationalist on Monday March 22, 2021 @09:43PM (#26549979)
Kotlin mostly requires JVM, Crystal does not. With Kotlin native, Kotlin js and most importantly Graal native this is plain wrong.
Re:Crystal 1.0 – What to expect by socialdemocrat on Monday March 22, 2021 @10:14PM (#26550211)
That is like a hack. You are basically dumping a JIT image to file. That means all sorts of caveats apply such as be real careful about how you use reflection.

Also there is no ABI so you cannot use anything like a native DLL.

Native compilation while possible is clearly second class on the JVM platform. For Crystal it is first class.

Re:Crystal 1.0 – What to expect by heavyset_go on Tuesday March 23, 2021 @12:39AM (#26551190)
> Also there is no ABI so you cannot use anything like a native DLL.

Pretty sure this isn't the case with Kotlin Native[1].

[1] https://kotlinlang.org/docs/native-dynamic-libraries.html

Re:Crystal 1.0 – What to expect by yxhuvud on Monday March 22, 2021 @10:40PM (#26550393)
Crystal is also not great for dlls or .so files as the event loop and gc probably wouldn't work well in that scenario.
Re:Crystal 1.0 – What to expect by filleduchaos on Tuesday March 23, 2021 @06:09AM (#26553135)
I have used Crystal to make DLLs and it worked plenty fine.
Re:Crystal 1.0 – What to expect by iomcr on Tuesday March 23, 2021 @09:50AM (#26554933)
Sounds like a fair compromise when the alternatives includes at least one of the following tradeoffs: harder, less safe, and/or slower.
Re:Crystal 1.0 – What to expect by abhijat on Tuesday March 23, 2021 @12:24AM (#26551100)
Is kotlin/native a first class option today for server side programming? Last I looked at it, which was fairly recently, that did not seem to be the case.
Re:Crystal 1.0 – What to expect by The_rationalist on Tuesday March 23, 2021 @09:38AM (#26554800)
While Kotlin native is likely more mature than crystal I would say that graal native is much better as it allow you to reuse Java libraries and therefore spring native.
Re:Crystal 1.0 – What to expect by nine_k on Monday March 22, 2021 @09:49PM (#26550028)
This is correct today.

This was not the case when Crystal development started.

Re:Crystal 1.0 – What to expect by The_rationalist on Tuesday March 23, 2021 @09:32AM (#26554741)
Translation: Crystal had a value proposition but now it's gone, before the product launch.
Re:Crystal 1.0 – What to expect by iomcr on Tuesday March 23, 2021 @09:53AM (#26554963)
Reality: Kotlin's value proposition is android development.
Re:Crystal 1.0 – What to expect by The_rationalist on Tuesday March 23, 2021 @01:12PM (#26557385)
It's a misconception, Kotlin is suitable everywhere that Java is suitable, and even more.
Re:Crystal 1.0 – What to expect by iomcr on Tuesday March 23, 2021 @09:42AM (#26554842)
That doesn't stop 99% of the mind share and language design from being "Java with lipstick".
Re:Crystal 1.0 – What to expect by socialdemocrat on Monday March 22, 2021 @10:11PM (#26550189)
Why Kotlin when you got Swift is an equally valid point. People like choice and for a lot of us, running on the JVM is a non starter.

Try creating a small command line tool for a JVM language. You need to distribute a virtual machine with it. You got the overhead of firing up a VM or JIT just for a short lived session.

Also JVM gobbles memory. You would not want a system made up of lots of tiny command line tools all running on a JVM. That would be a lot of overhead.

Re:Crystal 1.0 – What to expect by dm3 on Tuesday March 23, 2021 @03:05AM (#26551928)
This information was true a few years ago. Now, with modular JVM you do not ship a VM with the program. JVM by itself is lean and starts up pretty fast. You can also compile to native with GraalVM - this is a viable option if you want to write lots of tiny command line tools.

See Babashka[0] for an example scripting toolkit written in Clojure.

[0]: https://github.com/babashka/babashka

Re:Crystal 1.0 – What to expect by pjmlp on Tuesday March 23, 2021 @05:40AM (#26552909)
Since 2000 AOT compiling into native code has been available to Java developers, no different from using something like Go.

That many didn't want to buy those compilers and settled with the free beer that could get hold of is another matter.

Re:Crystal 1.0 – What to expect by cb321 on Tuesday March 23, 2021 @08:46AM (#26554354)
Just to corroborate - with gcc's gcj Java folk could get compilation to an ELF binary for free as well. I was profiling such in 2004. This was unpopular/unmaintained enough that eventually gcc discontinued it.

Sadly, people often confuse "prevailing mindset of the noisiest authorities of some programming language" with "the programming language itself" { not that this is the only confusion or maybe even the worst... :-) }

Re:Crystal 1.0 – What to expect by himujjal on Monday March 22, 2021 @10:31PM (#26550328)
kotlin/native doesnt require jvm

swift support for windows is non-existent

Re:Crystal 1.0 – What to expect by eyelidlessness on Monday March 22, 2021 @11:15PM (#26550611)
> swift support for windows is non-existent

I was prepared to suggest WSL, but apparently Swift support for Windows is existent[1].

1: https://swift.org/blog/swift-on-windows/

Re:Crystal 1.0 – What to expect by ibraheemdev on Tuesday March 23, 2021 @08:37AM (#26554291)
> What make ruby/crystal more "elegant" (I would prefer the term readable) than the competition?

In the words of David Heinemeier Hansson:

> In fact, Ruby, to me, so much of the enjoyment in Ruby is these incredible subtleties, of how many different ways you can structure a conditional. Like, Ruby has, I don't know even the count, there's gotta be 60 different ways you can say `if something`, right? And it is in those 60 different ways that I find half the enjoyment of writing Ruby. Like, it was one of those things where I knew, very early on, that Python was not a language for me because it said, right in the manifesto, there should be preferably one and only one way to do things. Ruby has the exact opposite approach, there should be preferably ten thousand subtle different ways of doing things, that will allow you to write that particular conditional, with just the right emphasis, do you write it in the front, do you put it at the back, is it multi-line, is it single line? Like, there's so much variety and it's in that variety that I find poetry. And it is the poetry of writing Ruby code, of making those subtle distinctions where, at the end, you can like, "Ehh, should we move it around" like, where I just go like, giggles, right? Like, this where like we talked about that big smile, right? So much of that big smile comes from, not just like solving the problem, but solving it in a poetic way.

Re:Crystal 1.0 – What to expect by pansa2 on Tuesday March 23, 2021 @09:15AM (#26554578)
> there should be preferably ten thousand subtle different ways of doing things

This doesn’t sound elegant (meaning “pleasingly ingenious and simple”) at all.

It also only seems readable in the most shallow sense - certainly not understandable.