7 ms·
Have you used a recent (2017) version of Crystal? Quickly building fluent-feeling libraries and tools is exactly my use case for Crystal. For me, everything th
by sam0x17 9y ago
Have you used a recent (2017) version of Crystal? Quickly building fluent-feeling libraries and tools is exactly my use case for Crystal.
For me, everything that Ruby is valuable for is retained. I'm able to do all the things I did in Ruby just fine, and it prevents me from doing a lot of things I shouldn't have been doing.
We recently migrated our app from Rails to Crystal (using the Amber framework) and our code base is now 2/3rds the size and we eliminated hundreds of bugs in the process simply from static typing and explicit nil handling. Our response times are also now all under 30ms where we were at 100ms+ before.
- eropple 9y agoUntil I can perform runtime define_method calls and dynamically construct classes, it doesn't matter what Crystal does. It's fundamentally antithetical to my needs. (JavaScript isn't, but JavaScript is kind of clunky.) I have Kotlin, C#, C++, and Rust if I need static typing. Ruby is for when I don't.
- yorwba 9y agoHow late at runtime do these dynamic definitions need to be possible? Just at startup or also after the program has been running for a while? I occasionally wonder whether it might be possible to accommodate more dynamic language features with a compiler that treats them like a macro system that is expanded statically, such that no actual dynamicism is necessary at runtime.
- sam0x17 9y agoThis is exactly what crystal does
- sam0x17 9y agoYou can do all of that with really easy to write crystal macros.
- eropple 9y agoYou can dynamically build at runtime an HTTP client from an OpenAPI spec (unavailable until runtime, to be clear), method-by-method, using macros? Tell me more.
- sam0x17 9y agoGot me there. First time I've ever in my life heard of a legitimate example where you really do need dynamic methods.
- eropple 9y agoIf you're doing stuff with OpenAPI (as I've been doing over the last few weeks), it becomes a pressing thing. =( Generated clients usually are pretty awful, you usually have to generate your own (because they don't publish gems when their APIs change, which is why I've written online-generated ones!), and once you've completed the bootstrap process for an HTTP client, it's as fast as any other Ruby thing. Which is not the fastest out there by a long shot--though JRuby helps--but is Fast Enough for most stuff. I'm also not sure Crystal can implement an active record pattern off of a database? (Though I am not personally the type to go with that, I prefer row mappers.)
- sam0x17 9y agoSee GraniteORM or my crystal-mongo-orm. You just have to specify your fields at compile time and you are good-to-go. It works just like active record. https://github.com/amberframework/granite-orm https://github.com/amberframework/granite-orm https://github.com/sam0x17/crystal-mongo-orm https://github.com/sam0x17/crystal-mongo-orm
- eropple 9y ago"You have to specify your fields at compile time" is exactly not like ActiveRecord, though. That's exactly the downside to it for doing ActiveRecord. At that point, you may (should) just use an object mapper like ROM that has no model-class hooks at all. (Which I actually like. But the Rails world disagrees.)
- sam0x17 9y agoPeople think "oh, it's compiled, so I can't have dynamic methods" but that couldn't be more far from the truth. You can do all of that at compile time, and Crystal provides an excellent way of doing so. E.g.: https://github.com/sam0x17/crystal-mongo-orm/blob/master/src/mongo_orm/fields.cr#L46 https://github.com/sam0x17/crystal-mongo-orm/blob/master/src...
- notalex 9y agoReading well written source code creates a more efficient workflow than reading api docs. For me, the fact that Crystal is written in Crystal gives it a far greater advantage. Plus it is faster than Go/Java/Elixir. As others have pointed out, Crystal does have meta programming capabilities.
- semperdark 9y agoWow. I've been checking in on the Crystal ecosystem every few weeks, but I somehow missed Amber. It feels like someone has finally cracked the code that made Rails great.