Domain: crystal-lang.org
Stories and comments across the archive that link to crystal-lang.org.
Comments · 6
-
Take A Look At Crystal
There is always going to be argument about which language is the best, which Linux distribution, which web framework, and systemd.
I have been using Crystal and the Lucky Web Framework for a large project, and it's been great. Crystal's handling of types, and the fact that you get all of the error-killing power of tight typing while you often don't have to specify the types at all because they are inferred, has make my code cleaner and easier to write, with fewer bugs and less need for testing. You write it like an interpreted language (it follows Ruby syntax, but treats typing and metaprogramming differently) and it has compiled speed (uses LLVM).
-
Re:Reigniting the browser wars
Web developers deserve a lot of the blame, here.
When all this fancy Javascript nonsense really started picking up steam years ago, it was common to get only a blank page unless you used a really popular browser. Why? The only way to get fancy animated special effects was to render a blank page and then fade/animate stuff into view. Thus, you avoided the oh-so-dreaded Flash of Unstyled Content (v2.0). Of course, this meant that the 10% of the population not using one of the Big Three browsers would get no content at all. Hey, no big deal! It's not like people actually needed to access "Healthcare.org" or anything.
Yeah, I remember when IE ruled the roost and web developers were screaming their heads off about standards compliance, just because a table column was misaligned by a pixel or two (but the page as a whole still worked fine). Once Google took over and became the darling of designers, nobody gave a toss about standards, even if it meant web pages wouldn't display AT ALL if you dared to use something with less than double-digit market share. We still have frameworks that detect browsers by names like "Firefox" instead of "Gecko", and inject all kinds of stupid hacks even if the page doesn't use those features.
Hell, just a few days ago I looked at the source of the Crystal-Lang homepage, and they get their jQuery library directly from a 3rd-party site rather than hosting the file locally. The designers of a programming language have a web site that doesn't use even remotely sane coding techniques. Shocker.
If we want to keep Google from taking over the Internet, first tell the hyperactive UX people to stop using every shiny toy Chrome has to offer.
-
Was OK for the '80's, But Its Time Has Past
C++ is a 1980's language (actually, Bjorn started work in 1979). It's lasted long enough that we don't have to shed any tears for its demise.
We have many better options today. Personally, I am writing in Crystal, and you can see my explorations here:
-
Crystal - Slick as Ruby, Fast as C
Eric suggests it's time to move on from C, and there are indeed better languages today that can help eliminate many classes of error.
Crystal is a rising programming language with the slogan "Fast as C, Slick as Ruby". It has some compelling features that make it more attractive than other modern language attempts like Go. You really can program in a Ruby-like language and achieve software that performs with the speed of a compiled language. And you can do systems programming in Crystal, too, because while it doesn't encourage you to use them for anything but systems programming and inter-language interfaces, it has pointers, and it can format structs as required to work on hardware registers.
But the greatest advantage of Crystal, that I have experienced so far, is that it provides type-safety without excessive declarations as you would see in Java. It does this through program-wide type inference. So, if you write a function like this:
def add(a, b)
a + b end
add(1, 2) # => 3, and the returned type is Int32
add(1.0, 2) # => 3.0, and the returned type is Float64
You get type-safe duck-typing at compile-time. If a method isn't available in a type, you'll find out at compile-time. Similarly, the type of a variable can be inferred from what you assign to it, and does not have to be declared.
Now, let's say you never want to see nil as a variable value. If you declare the type of a variable, the compiler will complain at compile-time if anything tries to assign another type to it. So, this catches all of those problems you might have in Ruby or Javascript with nil popping up unexpectedly as a value and your code breaking in production because nil doesn't have the methods you expect.
There are union types. So, if you want to see nil, you can declare your variable this way:
a : String | Nil
a : String? # Shorthand for the above.Crystal handles metaprogramming in several ways. Type inference and duck typing gives functions and class methods parameterized types for free, without any declaration overhead. Then there are generics which allow you to declare a class with parameterized types. And there is an extremely powerful macro system. The macro system gives access to AST nodes in the compiler, type inference, and a very rich set of operators. You can call shell commands at compile-time and incorporate their output into macros. Most of the methods of String are duplicated for macros, so you can do arbitrary textual transformations.
There is an excellent interface to cross-language calls, so you can incorporate C code, etc. There are pointers and structs, so systems programming (like device drivers) is possible. Pointers and cross-language calls are "unsafe" (can cause segmentation faults, buffer overflows, etc.) but most programmers would never go there.
What have I missed so far? Run-time debugging is at a very primitive state. The developers complain that LLVM and LLDB have changed their debugging data format several times recently. There's no const and no frozen objects. The developers correctly point out that const is propagated through all of your code and doesn't often result in code optimization. I actually like it from an error-catching perspective, and to store some constant data in a way that's easily shareable across multiple threads. But Crystal already stores strings and some other data this way. And these are small issues compared to the benefits of the language.
Lucky
Paul Smith of Thoughtbot (a company well-known for their Ruby on Rails expertise) is creating the Lucky web framework, written in Crystal and inspired by Rails, which has pervasive type-safety - and without the declaration overhead as in Java.
The point of all of this is that you can create a web application as you might using Ruby on Rails, but you won't have to spend as much time writing tests, because some of the
-
Re:Your Article Is All Fluff, Reader Finds
Kotlin is interesting, but when I looked into it I didn't care for some of the syntax. For example, if you're trying to make a language that's removing a bunch of boilerplate and unnecessary crap, why would you still require parentheses on methods (especially methods that take no arguments)?
Another JVM language worth mentioning is Mirah, which has Ruby-like syntax but uses the Java API with some syntactic sugar (no runtime jar). You still get static typing but it can usually infer the type without explicit declaration, and you skip a lot of the Java boilerplate stuff because of the Ruby syntax. Optional parentheses (but valid when needed for clarity or to resolve ambiguity), optional semicolons, blocks marked with begin/end or then/end instead of braces, stuff like that. I find nicer to type and still easy to read, especially compared to Java.
Something similar for native code is Crystal, with another Ruby-like variant syntax that generates native code and interoperates with C libs. This one actually has something of a runtime and implements things like Ruby's Dir and File classes. It's new and language features are in flux but it's got promise.
The Ruby inspiration won't appeal to everybody, but I like it, especially with static-typed languages that don't suffer from real Ruby's performance.
-
Re:Hmmm
Unfortunate Nim(rod) is so low and I couldn't see if crystal-Lang was on the list (graph is hard for me to read)-- both seem promising though nothing drastically new.
Thanks for the mention of Crystal (link provided since you didn't have one), I'd never heard of it until that. I've developed a fondness for Ruby-like syntax, so I'll have to look into that one later.
I also didn't see Mirah listed either, which is a damn shame. Ruby-like syntax, compiles to JVM bytecode, static typing, and doesn't need a runtime. You still have to interact with the Java APIs, same way you do with Scala and others, but it adds language features via macros, which is why it doesn't use a runtime jar.
I found it while searching for Java alternatives that can be used for Android development, and o far, I've been liking it a lot. Can be run script-style (shebang and all) for testing or quick work, the syntax is easy to type and read, it cuts out a lot of java boilerplate, and the resulting files are small and don't have external runtime dependencies like Scala, Groovy, Clojure, etc. do.
One really useful thing about it is its macros. The macro system the language itself uses is also available in programs, so you can add shortcuts or even create pseudo-methods on top of existing classes by manipulating the node tree. At its simplest it just replaces code at compile-time, like making wrapper methods to save some typing. The more complicated uses result in something akin to Ruby's monkeypatching, but without actually changing the underying classes.