7 ms·
Honestly, I just wish Rails had some degree of static typing (a la TypeScript.) As a Rails code base grows and patterns are required beyond the basics, it becom
by fny 8y ago
Honestly, I just wish Rails had some degree of static typing (a la TypeScript.) As a Rails code base grows and patterns are required beyond the basics, it becomes a nightmare to tell what comes from where. You'd probably gain some mileage from that in your React codebase.
- hombre_fatal 8y agoStatic-typing seems so at odds with Ruby/Rails that I can't even imagine what that would look like.
- ehsanu1 8y agoIt would ideally look pretty similar to typescript. There's actually a few projects adding typing to ruby, but they seem to be mostly trying to catch issues at runtime, which to me is pointless. Or the syntax is onerous, using decorators and/or separate type definitons. I'd be really interested in a typescript like superset of ruby, and I've even thought about building a prototype of it, though it's quite outside my area of expertise.
- hombre_fatal 8y agoI don't mean the syntax, I mean the abuse (ostensibly a language feature) of method_missing that's incumbent in the ecosystem. What would be the type signature of Active Record?
- favorited 8y agoAren't your ActiveRecord models basically the only place in a Rails app where you do specify the types of your properties?
- hombre_fatal 8y agoI'm referring to things like dynamic find_by_* messages since more people might be familiar with that. But I don't know why you'd say that. ActiveRecord models are one of the main places you'll see a bunch of `use SomeGem::Thing` that introduce a bunch of magic methods on model instances. And my point is that we aren't talking about method composition here that you can statically analyze with a bolted-on type system. Ruby's metaprogramming runs so deep that it's a substantially bigger challenge than other dynamically-typed languages. One clue is that humans even have a hard time with it. The first shock that people have with Ruby is when you see a method or identifier and grep shows up with zero results. Aside, I can kinda tell that Ruby is entering Perl territory when there are no beginners around to chime in with their gripes.
- favorited 8y agoI only say that because it seems like low-hanging fruit. If I have a class with a random @ivar that's added inside a random method, there's nothing up-front to check against. An ActiveRecord subclass at least has a database schema to validate against.
- deleted 8y ago[deleted]
- asark 8y agoThe magic stuff's awful. Any time you have to dig into a mothballed Rails codebase from a version either older or newer than what you're used to, or with a bunch of Railsy magic gems that aren't in your usual toolkit, it's hell. I'd rather let the computer tell me what stuff is and where it's defined than memorize a bunch of magic prefixes.
- digitaltrees 8y agoI am a beginner. I don’t know enough to gripe, I bet that’s a common feeling among beginners.
- pwim 8y agoStripe has built a type checker for Ruby that they're using internally. I don't think it has been released yet, but you can get a preview of it at https://sorbet.run/ https://sorbet.run/.
- deleted 8y ago[deleted]
- pmontra 8y agoSo it's something along the lines of Erlang / Elixir dialyzer. I don't like it much (dialyzer) because of the verbosity and unDRYness. Every function definition becomes two lines and the name of the function is repeated in both. Type names are longer than they should and are separated from argument names. We had a discussion about Ruby's type annotations 4 years ago at https://news.ycombinator.com/item?id=9481186 https://news.ycombinator.com/item?id=9481186 I found it by googling the status of the work on Ruby 3 type annotations. The top comment is mine and I still agree with the past myself.
- gurkendoktor 8y agoI'm waiting for a chance to try out Crystal/Amber, which is type-checked (not sure how safe?) and can be pre-compiled like Go apps. It looks really close to Rails: https://github.com/ChangJoo-Park/amber-realworld-example-app/blob/master/src/models/user.cr https://github.com/ChangJoo-Park/amber-realworld-example-app... (I couldn't find any code snippets on the official Amber framework page, I hope this is representative.)
- Willamin 8y agoCrystal is definitely type safe, I’d recommend taking a look at the Lucky web framework also written in Crystal.
- ethagnawl 8y agoKemal is great, too. Though, IIRC, it's more akin to Sinatra.
- realusername 8y agoCrystal/Amber combination is such a joy to work with, it's too bad it's not more popular, I'm contributing a bit to the project sometimes and use it for personal stuff. I regret it's not that trendy because it's the best web experience I ever had.
- tomc1985 8y agoHave you tried elixir?
- ethagnawl 8y agoI've been meaning to revisit Kotlin's web framework offerings. I've used it in small doses for Android and AWS Lambda functions and, IMO, it seems to potentially be the best of both worlds; strict where it needs to be and flexible where it doesn't. I'm currently supporting a few Python Lambda functions at work and they feel very slapdash in comparison.
- jrs95 8y agoThe biggest problem with Kotlin is also it's biggest strength: excellent interop with Java. This means that you can use all of the Java libraries...but that also makes writing new libraries in idiomatic Kotlin unnecessary, so you're going to get less of them, and have to use a lot of crummy old Java APIs.
- vbsteven 8y agoTry Kotlin with the Spring Boot framework. I view Spring Boot as the Rails of the Java world and the Spring team has done a lot of work lately on Kotlin compatibility and idiomatic APIs. This week I’ve been porting one of my Spring Boot apps to Kotlin and that was a great experience. The only thing I’m waiting for is good reactive drivers for Postgres and then you can go with their new reactor based apis instead of the older one-thread per request Spring MVC.
- m23khan 8y ago+1 - Kotlin/Java with Spring is a totally different beast as compared to java apps of yester years.
- ethagnawl 8y agoThis is a good point. I haven't used Spring in forever, so I don't know if/how it takes advantage of any modern Java features, but I could see Java 8/9/10 and (a framework like) Spring being pleasant and productive.
- benbristow 8y agoThat's more a Ruby issue than a Rails issue. https://sorbet.run/ https://sorbet.run/ Stripe have been working on a type-checker. No idea when they're going to release it to the public though.