130 points · by spalladino2 · 9y ago · 78 comments
Second of which is `yield`, ruby's extremely powerful way of passing code to functions. In crystal, functions which take blocks are actually inlined, meaning that abstractions such as `3.times {}` or `5.upto(20, step: 5) { |i| ... }` have zero cost. For example, take a look at how simple the HTTP server example is on the crystal homepage. Very useful for building DSLs.
Macros are another powerful (but hopefully not overused) tool for building clean programs. Crystal macros receive AST nodes but return source code as text. This text is then compiled and placed inside the program. This may sound like it would have the disadvantages of C macros, but as they're more integrated into the language, the compiler can insert the generated AST of the compiled macro into the original AST in a clean way. Using "dumb" text templating has several advantages: it's really easy to use because you're essentially just writing crystal code, and it's powerful as you get access to the AST. It also has the advantage that it's actually quite hard to make large scale modifications to a method body, preventing a lot of the silly macro uses.
> you're essentially just writing crystal code
even more so in a quasiquote, since you don't have to worry about adding extraneous parenthesis "just in case" etc.
Having structured input is already way better than full token-level solutions like C, but why not go all the way ?
Crystal vs Ruby don't really compete in the same way Crystal and Go do, it's very much a dynamic vs static typing split. Crystal is in general a bit more cleaned up but Ruby's community is much larger.
A fast and typed Ruby, isn't it enough? ;)
a = Object.new
list_of_modules.each { |mod| a.extend(mod) }
Ruby cannot be separated from its dynamism and to claim it can is misleading. irb(main):001:0> "".methods.size
=> 170
irb(main):002:0> 0.methods.size
=> 133
If it is, I mean, I don't see it being so fast.For psychological reasons, things that build on what's familiar get increased adoption. Trend started with C syntax that I can tell.
Go is a good enough replacement for C, for user space applications.
With some improvements, even for more lower level tasks.
As for the flaws, anyone that had the pleasure to work with the Algol and Wirth family of languages is well aware of them.
...there's probably some other stuff I could say, and probably more coherently, but it's early (for me) and I kind of just wanted to get that thought out there. I hope it's at least a bit thought-provoking, or something. If not, well, my apologies for rambling at you ;)
Are you sure you are not describing Rust?
The neat thing about the OS was that it and its compiler were simple enough for students to understand that they regularly ported or improved it a few months at a time. It's also one of the most, well-documented OS's in existence.
That Go is basically a modified Oberon means Go, currently or with some modification, could be used for low-level, systems code up to operating systems. Even with a GC since the Oberon OS's are written in GC language. Most recent, graphical one is A2 Bluebottle if you want to look it up.
I just don't want to have to deal with a bunch of second guessing judgmental jerks anymore. Nobody in the Crystal community is going to go after me for something "not idiomatic" I published.
What I meant with that remark was that those languages already had fast toolchains and were more expressive.
So in this regard I also appreciate Crystal, specially since RubyMotion decided to focus on mobile.
It will still be CRuby, but the "C" is Crystal.
edit: Windows 7
Edit* Just saw where you said "play"
You can read more here: https://crystal-lang.org/docs/guides/concurrency.html
We're already well past the point where we could become "native ruby" and I'm glad of that. Ruby has quite a few warts, and I'm glad most of them haven't been copied by crystal.
Compilation times are already well under a minute for the whole of the crystal compiler itself. It was actually improved quite a bit on Linux in the latest crystal release.
"reach a point where breaking changes to the core of the language are down to a minimum"
I'm very afraid of the word minimum in this context. This is why "no one was ever fired for picking Java".
Aside from tooling I need a guarantee that my code, if following all of the best practices, should be compilable from now till the foreseeable future.
There's QT, which is huge and unwieldily and not so good looking on OS X, GTK+ which is a mess on both Windows and OS X, wxWidgets (based on other libs), and a few fringe, and incomplete libs.
For one-platform apps, though, or a single backend for multiple platform UI frontends, it will do just fine, provided we get bindings for Cocoa, Windows UI libs, GTK etc.
Crystal at the very least has good support for binding C so maybe this will be the language which finally produces a modern gui toolkit, but with the move towards web apps its becoming increasingly unlikely.
Well, the whole Cocoa/QT/WinForms scope might be huge, but we don't even have good minimal UI libs -- e.g. with just the few basic widgets: buttons, text fields, labels, radio buttons, checkboxes, kind of what HTML forms can do -- and only very limited functionality (e.g. no fancy text formatting in the labels or whatever).
Tons of programs could be GUI-fied with just the above (sort of what Tk does, but decent looking).