I love Ruby and I love Rails, but I’ve found myself searching for something more. Something fast so I don’t need to add caching. Something type-safe so customers see fewer bugs. Something fun to use so I actually building applications. enjoy It was a good start. It made it fun to write beautiful code, but I still encountered bugs in production that have been caught with a better type system. Would Elixir scratch my itch? could . It’s beautiful. Fun. But only available on the front-end. There’s Elm I played briefly with , but I felt like the type-system and syntax was too unfriendly for me to enjoy using them. Go and Rust Finally, I tried Crystal It looked almost identical to Ruby, so why would I try it? At first, I was pretty put-off by Crystal. Well eventually I did try it, and I fell in love 💙 . It’s familiar enough to get started quickly, but new enough that it will challenge you in interesting ways. Some things I love about Crystal: Though Crystal looks similar to Ruby, Crystal is a different beast — unashamedly Ruby-like. Some people might not like it, but I love it. Beautiful syntax — It gives me anxiety just writing this: . I’ve seen this far too many times. Crystal helps catch these bugs at compile time, so they never see the light of day. Catch bugs at compile time Undefined method on Nil — Crystal uses macros to generate code for you. Bye-bye boilerplate. Meta-programming with macros — in many benchmarks Crystal beats Go, Elixir and sometimes raw C code. It’s quick. Incredibly fast Introducing , the web framework written for Crystal Lucky The goal: prevent bugs, forget about most performance issues, and spend more time on code instead of debugging and writing tests. In summary, . make writing stunning web applications fast, fun, and easy Why should you try it? — intuitive APIs and helpful compile time errors help make things simpler. and our helpful can help if you get stuck. Easy to pick up Guides chat room no more cobbling together a million libraries. Lucky includes what most apps need. Emails, an M for working with the database, templates, webpack setup for you, automated browser testing, authentication, and easy deployment. Batteries included — OR — stop worrying about performance and how many servers you need. Most responses with lots of and multiple database requests handle thousands of requests per second on moderately priced servers. Lightning fast HTML — spend less time worrying about test coverage and sneaky type errors. Let the Crystal compiler help you out. Catches bugs for you — Build server rendered HTML, use the built-in webpack config for an SPA, or build a JSON API by initializing your project with Flexible --api — Lucky prevents slow N+1 queries by raising during development if you accidentally forget to preload associations. No more N+1 issues Bullet points are boring, what’s it look like? Handling an HTTP request Calling sets up a route for automatically. route ”/users” If you want you can set up custom routes like for non REST routes. get “sign_in” If you forget to pass something a page needs, Lucky will let you know at compile-time. Setting up a model Sets up the columns that you’d like to use, along with their types You can add to the type when the column can be . Crystal will then help you remember not to call methods on it that won’t work. ? nil Lucky will set up presence validations for required fields ( and since they are not marked as nilable). name email Querying the database is automatically generated when you define a model. Inherit from it to customize queries. User::BaseQuery Set up named scopes with instance methods. Lucky sets up methods for all the columns so that . if you mistype a column name it will tell you at compile-time Use the method on String column to make sure Postgres sorts everything on lowercase. Lucky has lots of powerful abstraction for creating complex queries, and type specific methods (like ). lower lower Preventing the dreaded N+1 query If you forget to preload an association, Lucky will raise a runtime error in the development and test environment. No more accidentally slowing down requests with N+1 queries. In production, the query does not raise. That way if you accidentally make a change and don’t have a test for it, it won’t throw errors for your users. Instead you can fix the performance issue later. Sometimes you just want to load an association without the preload dance and you’re ok with a slight performance hit. Add to load the association without triggering a runtime error. ! Rendering HTML tells the compiler that it must be passed of the type . needs users : UserQuery users UserQuery If you forget to pass something that a page needs, it will let you know at compile time. Fewer bugs and faster debugging. Write tags with Crystal methods. Tags are automatically closed and whitespace is removed. Easily extract named methods since pages are made of regular classes and methods. . This make your HTML pages incredibly easy to read Link to other pages with ease. Just use the action name: . Pass params with . . Users::New Users::Show.with(user.id) No more trying to remember path helpers and whether the helper is pluralized or not If you forget to pass a param to a route, Lucky will let you know at compile-time. Since we defined as nilable, Lucky would fail to compile the page if you just did since it disallows printing . So instead we add a fallback. column age : Int32? text user.age nil No more accidentally printing empty text in HTML! Get started with Lucky Here are some ways you can get started Throw us a star on the 😉 Lucky GitHub repo Follow on Twitter. @luckyframework Check out the and get started. guides Ask for help or get ideas on our . Gitter channel Apprehensions There’s always a catch, and that’s true with Crystal and Lucky too. Neither Lucky nor Crystal are at 1.0, which means with some new versions you’ll have to make changes when upgrading. There are also fewer libraries and tutorials than in Ruby and other more mature languages. For some people, this is a fun opportunity to get in at the ground floor and help shape the community, but it’s not for everyone. If you’re interested, , and but not quite ready to make the leap follow @luckyframework on twitter throw us a star on GitHub .
Share Your Thoughts