9 ms·
The main issue I have with Ruby / Python is the fact that it's duck typed, it makes the maintenance and refactor pretty hazardous. You get objects you don't kn
by Thaxll 4y ago
The main issue I have with Ruby / Python is the fact that it's duck typed, it makes the maintenance and refactor pretty hazardous.
You get objects you don't know what's in there, 6 month later someone changed it, no compile error but it will break when you run it.
And so to overcome those major issues they added really ugly stuff that is not core to the language, linters, annotations etc ...
- itake 4y agoEven in dev, you have to basically code in irb in order to verify everything works.
- jeltz 4y agoNonsense. I used to be a professional Ruby developer and that is nowhere close to the truth. While I prefer static typing it is not hard at all to code in Ruby once you have learned the basics and I almost never used IRB other than when I was a beginner.
- pantulis 4y agoIt's good practice to use irb to quickly check stuff or inspect the programmatic surface of a new library. But that's a Ruby feature that you don't have in other languages! In no way its mandatory to code inside irb. Most of my time was spent in Textmate or Emacs.
- itake 4y agoHow many different ruby projects did you code in? Once you have memorized the global state on a project, you can rely on your intuition and rely less on irb. But anytime someone introduced a new gem (namely act_as_paranoid) or writes a new concern that modifies defaults, then you're back to need to do live code.
- phaedryx 4y agoThe solution is to be religious about testing and writing tests. If you've done it well, refactors are pretty safe and your objects are pretty well understood.
- pantulis 4y agoAlso, you need to be religious about testing and writing tests _anyway_.
- ajmurmann 4y agoAs someone who spent a good chunk of their career teaching TDD, I agree and disagree. Yes, tests are crucial. However, which tests to write varies among other things by language. When I write Ruby, I benefit from testing even the simplest things. When I write Rust or even Type Script or Swift I'll focus much more on tests for complex logic and on integration and acceptance tests. Static typing eliminates an entire, larger category of issue I need to address with tests.
- pantulis 4y agoSure! But you need to be a testing practitioner anyway. I agree that perhaps the number of tests is different, but the teams processes and cultures should already be there. But to counter myself, the perceived lack of developer speed and flexiblity of a strongly typed language (with Rust, I always get the feeling that I'm fighting with the compiler!) is also solved in the long run with practice and tooling.
- vidarh 4y agoWhen I write Ruby, I test expected behaviours, and if there are type errors in there those tends to fall out from tests I needed anyway. If you need to test specifically for errors due types, then generally that suggests that either your application does not normally exercise those code paths at all and/or you fail to test behaviours of your application.
- 4y ago
- pantulis 4y agoIt's not like strong typing came after Ruby. In fact, duck typing was a _feature_ of Ruby on its days. At the end of the day, you choose your battles, it's not a black-or-white decision.
- JW_00000 4y agoNo, but gradual/optional typing did come after Ruby. Back in 2005, you could choose between static typing with type checking but lots of verbosity (e.g. Java "Point point = new Point();" or C++ "for (std::map<int, BlaBla>::iterator it = myMap.begin(); it != myMap.end(); it++)") or dynamic typing without type checking but also without the verbosity. Since optional typing, dynamically typed languages got the guarantees of type checking, and JavaScript/TypeScript and Python have embraced this. With type inferencing, statically typed languages lose their verbosity, and Java and C++ have embraced that (as have newer languages like Rust, Go, and Swift). It feels like Ruby hasn't progressed on this front...
- JeremyNT 4y agoRuby does have optional type annotations, if you want them: https://github.com/ruby/rbs https://github.com/ruby/rbs
- FpUser 4y ago>"for (std::map<int, BlaBla>::iterator it = myMap.begin(); it != myMap.end(); it++)")" All you really needed is: for (auto it : myMap) and you still get compile type safety
- vlunkr 4y agoI still think it's a great choice for smaller projects. I can't imagine it at the scale of shopify.
- blacksmith_tb 4y agoApparently they couldn't imagine it either[1]. 1: https://sorbet.org/ https://sorbet.org/
- badrequest 4y agoThis is built by Stripe, not Shopify.
- blacksmith_tb 4y agoOops, my bad, I should have doublechecked that!
- eric-hu 4y agoIt is, but Shopify uses it as well and maintains the companion tool, tapioca. https://github.com/Shopify/tapioca https://github.com/Shopify/tapioca Tapioca is used to generate type signatures on gems and code that creates functions at runtime. Sorbet ships with some of that behavior, but they updated their docs to recommend tapioca over sorbet where the behavior overlaps.
- davidw 4y agoWhat are you using that's strongly typed and as quick to get stuff done with as Ruby?
- bastardoperator 4y agoNothing, it was just an opportunity to use buzzwords and inject negativity.
- jetpackjoe 4y agoI think TypeScript, especially with a full stack framework such as Remix or Next, satisfies these two constraints.
- reducesuffering 4y agoYep, Next / Typescript
- vidarh 4y agoRuby. (Ruby is strongly typed in the "doesn't automatically coerce types" and "maintains a fixed type for an object" sense; using the term "strong typing" is inherently ambiguous because it has so many partially conflicting meanings)
- tinglymintyfrsh 4y agorbs / steep, and sorbet. Monkeypatching is evil. Rubocop custom cops to reign-in what's allowed in CI/CD.
- vidarh 4y agoI used to have that attitude. Then I wrote my first Ruby project as an experiment. That was 17 years ago, and the majority of the code I've written since has been Ruby. What clinched it was that the first Ruby project I wrote involved trying to reimplement a piece of C code we had. It ended up 10% the size with more functionality, and it took me a tiny fraction of the time to write. If you write code the way you write statically typed code, then sure, you're in for a world of hurt. I could imagine using a statically typed language again if it made me as productive as Ruby, but most statically types languages have near useless type systems that I wouldn't wish on my worst enemy.
- pak9rabid 4y agoHave you looked into Crystal? It's supposed to be a statically-typed language, with the syntax of Ruby. https://en.wikipedia.org/wiki/Crystal_(programming_language) https://en.wikipedia.org/wiki/Crystal_(programming_language)
- vidarh 4y agoI have, and last time I looked it deviated from Ruby in entirely pointless ways that makes it fairly uninteresting to me. I get they want it to be its own language, but it'd have been far more interesting to me if it stayed as close as possible wherever it could.
- mostlysimilar 4y agoI don't know if I'm just a bad programmer and everyone knows something I don't, but it seems to be the benefits of a strongly typed language are wildly overblown. It's a different way of thinking about building software and it saves you from a few mistakes you could otherwise make, but you'd think I was writing code with a hammer and chisel the way people on HN talk about languages like Ruby. It feels a lot like the people who used to try to convince everyone functional programming was the only way to go and object-oriented programming was for dinosaurs.
- bcrosby95 4y ago
- zitterbewegung 4y agoPython now has an optional type system and if you add one of them such as mypy or pyre to your CI process and you can configure GitHub to refuse the pull request until types are added you can make it somewhat strongly typed. If you have a preexisting codebase I believe the way you can convert it is to add the types that you know on commits and eventually you will have enough types that adding the missing ones should be easy. For the missing ones Any is a good choice. https://pyre-check.org https://pyre-check.org and https://github.com/python/mypy https://github.com/python/mypy are popular.
- Yoric 4y agoMy experience of mypy is that, even with the most restrictive settings, it's still quite weak with respect to all reasonably strongly typed languages I've used (e.g. anything at least as strongly typed as Java). YMMV
- Slippery_John 4y agoPython's type hints are definitely an improvement and they're getting better all the time, but they're still frustrating to use at anything approaching the edge. I long for something as elegant and functional as TypeScript. One hurdle I've stumbled over recently is the question "what is a type?", the answer can be surprising. Unions, for example, are types but not `Type`s. A function that takes an argument of type `Type` will not accept a Union. So if you want to write a function that effectively "casts" a parameter to a specified type, you can't. The best you can do is have an overload that accepts `Type` and does an actual cast, and then another that just turns it into `Any`. This is, in fact, how the standard library types its `cast` function [1]. The argument I've seen for the current behavior is that `Type` describes anything that can be passed to isinstance, but that's not a satisfying answer. Even then, `Union` can be passed to isinstance and still does not work with `Type`. Talk currently is to introduce a new kind of type called `TypeForm` or something to address this, which is certainly an improvement over nothing, but still feels like technical debt. [1]: https://github.com/python/typeshed/blob/main/stdlib/typing.pyi#L745 https://github.com/python/typeshed/blob/main/stdlib/typing.p...
- Gigachad 4y agoI’ve been doing Rails development for 10 years now and I just don’t think it’s possible to safely update anything in Ruby. Our app has 20,000 rspec unit tests and 5,000 cypress browser automation tests and basically every ruby patch version creates breakages that somehow slip through all of that despite nothing being mentioned in the changelogs.
- xiphias2 4y agoWhat about recording and replaying traffic to the servers? It's not a magical solution, but it should catch regressions.
- Gigachad 4y agoReplicating the production env to do that sounds beyond our capabilities tbh. We are slowly replacing Ruby with typed languages like TS and Rust which is working wonders for reliability.
- xiphias2 4y agoGreat, it's just a usual extra tool, although RoR is amazing, I fell in love with SvelteKit