Restoration Hardware 19th C. Casbah Crystal Chandelier

Crystal: Ruby syntax with well-nigh C efficiency

Christopher Watson HackerNoon profile picture

Anybody looks at programming languages differently. There are those that want speed and are willing to compromise syntax (I'm looking at you C++ developers), then there are those that would rather have something that looks beautiful but lacks in performance (like Ruddy). I've never understood why a linguistic communication didn't be that married the 2 ideas into a language that was both fast, and cute.

Several languages accept tried over the years and a few have gotten close. Become is a perfect example. Even so loosely based on the C language, Go has an easier to empathize and easier to read syntax without sacrificing too much on the performance end. Having been adult by Google it has also matured rapidly and gained a high adoption rate. It as well compiles downwards to machine lawmaking which ways you can utilize it to write the same types of programs in Go where you'd commonly use C. Withal information technology's still not as beginner friendly or as easy to understand as a language like Python or Cerise.

Enter Crystal, a cute Red-esque programming language that compiles down to automobile code. I stumbled upon crystal while searching for a way to brand Ruby compile to automobile code, or at least C, and instantly fell in dear. Here are some of the things I love well-nigh Crystal:

  • It'due south statically typed, merely with congenital in blazon inference. That means no more than bugs due to incorrect types.
  • It compiles to native automobile code which means much faster execution time. The compiler is also extremely fast and can compile itself in nether 30 seconds on my machine.
  • Crystal is written in Crystal which makes contributing to the linguistic communication super easy.
  • It'south syntax is and so similar to Ruby that some Cerise programs are actually valid Crystal programs and vice-versa.
  • Information technology has a modern standard library consummate with support for JSON, Markdown, XML, and YAML parsing; information technology also has built in websocket support and macros.

And those are just to name a few. Crystal also comes with a built in parcel and dependency director chosen Shards that makes distributing libraries and binaries easy.

Crystal'south syntax is clear, concise, and human readable. Here is an example (taken from their website):

That code could easily exist carmine, but the major difference is that when I run crystal build myserver.cr my little server will become compiled into a single binary file called myserver which ends up being upwardly of 100x faster than the Blood-red version.

And so how fast is information technology?

First-class question, for which we'll need some benchmarks. Lucky for me others take already taken upwards the task of creating these benchmarks and accept provided us with some pretty great data.

I decided to run some of the examples myself and got similar responses. All examples show execution time and memory usage.

Mandelbrot
Crystal
== 10.21s, 2.2Mb ==
C
== 9.81s, 0.7Mb ==
Cherry-red
== 116.65s, 8.8Mb ==

Shooting star
Crystal
== 0.20s, 2.5Mb ==
C
== 0.09s, one.2Mb ==

Binary Trees
Crystal
== 13.61s, 108.6Mb ==
C
== six.59s, 33.2Mb ==
Ruby
== 35.06s, 116.3Mb ==

As you lot can see Crystal is closer to the speed of C than information technology is to Ruby. By a lot in most cases.

Crystal's Status

Right now Crystal is still in the alpha phase, significant that there will be breaking changes along the line. That being said it is 1 of the to the lowest degree buggy alpha's that I have e'er been a part of.

Yes, Crystal is still missing some things, Windows support for one; but the future looks bright for this new kid on the block and I, for one, can't wait to see where it goes.

How Can I Help?

Crystal is open sourced and located at github.com. They accept pull requests and seem to reply to problems very chop-chop. You lot can likewise assistance out by evangelizing Crystal, like I am at present, submitting issues, and adding your own "shards" to github.

Happy coding!

Tags

# programming# crystal-lang# cherry# elixir# cplusplus

Related Stories

0 Response to "Restoration Hardware 19th C. Casbah Crystal Chandelier"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel