Crystal 0.11.0 released!
Crystal 0.11.0 has been released!
This release comes with syntax and semantic changes that favor consistency, standard library refactors, many performance improvements and bug fixes. A new version of shards is included.
Read the full changelog here.
Type declarations and uninitialized variables
Before this release,
:: was used to declare the type of instance variables.
:: inside a method had the meaning of declaring a variable with uninitialized (unsafe) contents:
This was confusing, as a same syntax had two meanings. Now, the
:: syntax is gone. To declare the type
of a variable you use a single colon (
This is also consistent with the syntax of type restrictions:
To declare a variable with uninitialized content you now do:
which is much more explicit and clear.
Additionally, type annotations are now allowed in class and global variables.
To upgrade your code to this new syntax, just run
crystal tool format on your project: the formatter still
understand the old syntax and will modify your code to use the new syntax :-)
String heredocs are now more powerful and convenient: leading space is removed from heredoc lines according to the leading space of the closing delimiter. For example:
The old behaviour was inconvenient because it forced you to write all content aligned to the left. For example:
Now you can write it like this:
Thank you rhysd for suggesting this change.
return could be used inside a captured block. For example:
return usually returns from a method, bypassing the block, but in the case of a captured
return just exited the block and gave it a value. This was inconsistent, so now
you have to use
next, which is the way you give a block it’s value in other situations.
will give an error in this case.
Standard library changes
A huge refactor has been done to
HTTP::Server to support streaming and upgrading protocols.
Previously you would write a server like this:
The problem with this approach is that there’s no way to stream content to the response body. Well, there was a way: you would set an IO as the response body, but this was awkward and complex.
Now the handler receives a context which includes a response object to which you can write to.
Streaming data is now super easy:
The above code will write the numbers from 0 to 9, waiting 1 second between each write.
Before this release
libpcl was used for fiber context switch. Now this is done with inline
assembly, which not only frees us from
libpcl, it also works much faster.
URI.parse was rewritten by will to not use regular
expressions, which gave it a huge performance improvement.
The compiler’s code now does an initial pass to declare all classes, macros and methods. This got rid of many bugs that depended on order of declaration, forcing you to use some ugly workarounds.
We want to thank everyone that contributes, discusses, promotes and critizices this project. We
never stop being amazed at how much you do and help us grow the community, slowly getting us to
Happy crystaling!comments powered by Disqus