Follow Slashdot blog updates by subscribing to our blog RSS feed

 



Forgot your password?
typodupeerror
×
Programming

Why the Creator of Ruby on Rails Prefers Dynamic Typing (hey.com) 148

"I write all novel client-side code as JavaScript instead of TypeScript, and it's a delight," says the creator of Ruby on Rails. Posting on Twitter, David Heinemeier Hansson opined that TypeScript "sucked out much of the joy I had writing JavaScript. I'm forever grateful that Yukihiro 'Matz' Matsumoto didn't succumb to the pressure of adding similar type hints to Ruby."

When it comes to static vs dynamic typing, "I've heard a million arguments from both sides throughout my entire career," Hansson wrote on his blog today, "but seen very few of them ever convinced anyone of anything."

But wait — he thinks we can all get along: Personally, I'm unashamedly a dynamic typing kind of guy. That's why I love Ruby so very much. It takes full advantage of dynamic typing to allow the poetic syntax that results in such beautiful code. To me, Ruby with explicit, static typing would be like a salad with a scoop of ice cream. They just don't go together.

I'll also confess to having embraced the evangelical position for dynamic typing in the past. To the point of suffering from a One True Proposition affliction. Seeing the lack of enthusiasm for dynamic typing as a reflection of missing education, experience, or perhaps even competence.

Oh what folly. Like trying to convince an introvert that they'd really like parties if they'd just loosen up a bit...

These days, I've come to appreciate the magnificence of multiplicity. Programming would be an awful endeavor if we were all confined to the same paradigm. Human nature is much too varied to accept such constraint on its creativity...But it took a while for me to come to these conclusions. I'm a recovering solutionist. So when I see folks cross their heart in disbelief that anyone, anywhere might fancy JavaScript over TypeScript, I smile, and I remember the days when I'd recognize their zeal in the mirror.

Hansson also sees the "magnificence of multiplicity" in positions about functional vs object-oriented programming. "Poles on both these axes have shown to deliver excellent software over the decades (and awful stuff too!)."
This discussion has been archived. No new comments can be posted.

Why the Creator of Ruby on Rails Prefers Dynamic Typing

Comments Filter:
  • Of course (Score:5, Interesting)

    by phantomfive ( 622387 ) on Sunday May 07, 2023 @08:57PM (#63505285) Journal
    Dynamic typing is more fun. That is 100% true. It also leads to more flexible code, because there are so many places you can insert things.

    Static typing is better for large projects because A) when you have a lot of people working on a project, it helps keep things organized. B) It lets your IDE help you with writing code.
    • Re:Of course (Score:5, Insightful)

      by Jeremi ( 14640 ) on Sunday May 07, 2023 @09:31PM (#63505339) Homepage

      Static typing is better for large projects because A) when you have a lot of people working on a project, it helps keep things organized. B) It lets your IDE help you with writing code.

      Let's also throw in C) It allows the compiler/optimizer to do a much better job of generating efficient code, since with static typing, the compiler/optimizer knows much more about what your code will and won't be expected to do at run-time.

      • Re:Of course (Score:4, Insightful)

        by phantomfive ( 622387 ) on Sunday May 07, 2023 @09:45PM (#63505367) Journal
        Yeah, but let's be honest, if you care about performance, you're not writing your code in Ruby or Python.
        • Re: (Score:2, Insightful)

          by Excelcia ( 906188 )

          If you care about your code as anything more than a run-once cobbled together hack to munge some data for your paper and which will never see the inside of a computer other than the one it was written on, then you're not writing your code in Ruby or Python.

          • What happens when you get the reviews back on your paper, and Reviewer 3 insists that you add another plot to describe concretely a point you glossed over.

            What will your "run-once cobbled together hack" do when you call upon it to run a second time?

            You "turn around" the paper and tell the Associate Editor that another plot is not needed. Reviewer 3 is laughing maniacly, "Mwuh-huh-huh-huh-huh!"

            The point being that even if something is not a commercial product, "run-once" is not an attribute of softw

        • by jsonn ( 792303 )
          ...or if you care more about the cost of the developer hour than about the CPU hour. There are a lot of situations, when the latter is dirt cheap and spending a day less on a feature request is equivalent to paying for twice the computational capacity for another month. But half of the people that diss Python are also happily pay a fortune for clown computing :)
          • by PackMan97 ( 244419 ) on Sunday May 07, 2023 @11:27PM (#63505529)
            For most companies, developer time is far more valuable than compute costs. Very few companies operate at a scale that flip that statement. At straps this is especially important. Get features out as quickie as possible. Redactor for performance when compute cost savings justify the time you're engineers will spend on the improvements.
            • by MNNorske ( 2651341 ) on Monday May 08, 2023 @09:29AM (#63506363)
              Refactor costs are exponentially larger when the underlying code is slapdash and uses dynamic structures/types. When an engineer learns how to write their code with the understanding of how it can be refactored and supported later they can make much more readable code that is still performant and will save hundreds of hours of support and maintenance time later on. I have seen too many people claim that time is money and then rush something out without thinking of the implications on maintenance and support. And, I've had to come in and clean up someone's dynamically typed mess too many times when something has broken to buy into the belief that dynamic typing helps. IMHO the only thing it helps is sloppy coding and increasing break points and support costs.
          • Sometimes the execution speed differs by orders of magnitude though. Spending orders of magnitude more on hardware can be difficult. Not to mention things dont necessarily scale.
            • by jsonn ( 792303 )
              True, but in my experience those cases are more often algorithmic problems and can happen in languages that are nearer to the hardware just as well. Ultimately, it is about choosing the right tool for the job. Ease of use, meta-programming, garbage collection, type system power, maintainability etc. are all factors that are important for choosing a tool. The arrogance shown in the comments here is ridiculous. It reminds me a lot of the famous "MongoDB is webscale" parody :)
              • In my experience the issue is frequently a failure to understand how to efficiently implement the algorithm, especially when concurrency is required, or understanding memory access patterns. Getting these things correct is often how performance increases of one or two orders of magnitude are won.
                • In web development, usually database requests are the thing that slow you down, not "Python" or "assembly language".
                  • by jsonn ( 792303 )
                    RPC in general. HTTP, database access, TCP to the cache etc. - they all add significant latency even when highly optimized.
          • Python isn't faster to develop in than other modern languages.
        • Well, if performance = time to write script + time to run script + maintenance, then depending on which takes longer Python might be more "performant", especially if maintenance is zero (just run once), or writing in other languages takes much longer. Python has optimised C doing most of the work, and the largest library of data processing tools. You might need one of those Python-only libraries to get the latest AI shit. Python is also easier to generate by AI since it has so much training data, and easie
        • Python can be compiled, so in theory, with enough effort in compilers, Python performance could be good. If you are doing things at a high level with NumPy doing heavy lifting it can already be reasonable, but that includes lots of typing information
    • Re:Of course (Score:4, Interesting)

      by Pinky's Brain ( 1158667 ) on Sunday May 07, 2023 @09:32PM (#63505343)

      Implicit type conversion chains so beautifully with reflection/serialization bullshit and to punch through input sanitizers/validators too.

      Programmers can't be trusted with it.

  • by The Evil Atheist ( 2484676 ) on Sunday May 07, 2023 @09:01PM (#63505289)
    You don't need type hints with a proper type system and type deduction. You can still "get away with" a concise syntax when you let the compiler do all the work for you before you even run the program.

    Some people seem forever stuck with "syntax issues" and fail to move past. Don't see the "code". See the blonde, brunette, redhead...

    Some people just love debugging, instead of removing whole classes of bugs in the first place.
    • Some people just love debugging, instead of removing whole classes of bugs in the first place.

      I take it you sit in the former camp then?

      • Nope. I have all the tools I need.
        • C++ means more debugging

          • Nope. You don't understand how professional development works in C++. As we've uncovered, all your programming knowledge comes from reading FUD from blogs.

            You seem to think that C++ programmers are constantly manually allocating memory or twiddling with bits and pointers at every level of the program.

            We have the things like vectors and templates for a reason. To build abstractions that don't require delving deep into the machine all the time, without sacrificing performance. Then there's constexpr, wh
  • tunnel vision (Score:5, Insightful)

    by TurboStar ( 712836 ) on Sunday May 07, 2023 @09:09PM (#63505301)

    Amazing. A dude who mostly manipulates strings doesn't care about typing. The debate vanishes as you get closer to the hardware.

    • Re: tunnel vision (Score:5, Insightful)

      by IdanceNmyCar ( 7335658 ) on Sunday May 07, 2023 @09:30PM (#63505337)

      Isn't this his point? If you aren't close to the metal, then just let the compiler handle it.

      There are plenty of people who don't need to be low level programmers and likely shouldn't be. It doesn't mean they add no value to the ecosystem.

      This being said, never been a rails fan.

      • Isn't this his point? If you aren't close to the metal, then just let the compiler handle it.

        I'm not entirely familiar with Ruby but I don't believe there's any compiler involved here.

        There are plenty of people who don't need to be low level programmers and likely shouldn't be. It doesn't mean they add no value to the ecosystem.

        That depends. Personally I have very, very low tolerance for laggy things, which frameworks like this are more likely to deliver.

        • by lsllll ( 830002 )

          I'm not entirely familiar with Ruby but I don't believe there's any compiler involved here.

          I'm not that familiar with Ruby, either, and I concur that there's no "compiler" for it, as in compiler that compiles C or assembler. But I do a lot of Coldfusion development (nowadays in Lucee and Adobe CF both) and the server engine creates JAVA bytecode out of the CF code. Many people call the JAVA bytecode compiler a "compiler". So it may really depend on the interpretation of what a compiler is.

      • by Somervillain ( 4719341 ) on Sunday May 07, 2023 @11:47PM (#63505557)

        There are plenty of people who don't need to be low level programmers and likely shouldn't be. It doesn't mean they add no value to the ecosystem.

        It's not necessarily JavaScript, Python, and Ruby's fault that they have shitty ecosystems and are associated with disaster after disaster. They attract low-skilled developers that do a shit job. However, to your point, these folks provide value, but it is negative. The personalities that love to create meaningless frameworks and reinvent the wheel because it's more fun than reading the docs on existing frameworks are a problematic cancer. They make UIs slow. They make billions of machines do more work than they should. They contribute to climate change with their inefficiency...but hey....dynamic typing is fun!!!!

        Java used to have a HUGE problem with this. Framework after framework would be introduced with no clear reason why...then server-side rendering fell out of fashion and those people went to JavaScript and python to write shitty code.

        Most Ruby apps I've seen are slow and brittle and have been rewritten or abandoned. There are not a lot of Ruby success stories. I don't blame the tool, but the tool attracted some read problematic people to write code in them. A talented engineer can write great code on any platform and a maniac can write devastating code on any platform as well. But when you pick a platform, you get the platform, the technology, but also the ecosystem and talent base. Ruby attracted everyone who thought "Java is too hard." This was good for Java...but man...we really have to do something about those low-end professionals.

        • by rta ( 559125 )

          Man on java frameworks.. after doing JSPs i got bloodied on early JSF on the java side. (well... and well before that early and EJB. mmm.... EntityBeans... )

          i also remember when Ruby (or, really, Ruby on Rails) was the new hotness and all the cool kids were doing it because "functional programming!". Then Node.js came along and all the early adopter framework writer types moved over to that.

          I have to give them both, and Python, props for forcing the Java universe to try to become more dynamic and easy

          • Rhe cool,kids were doing it because we are so tired of spelling out everything to the slow Java Compiler who can only read XML“

            Ruby on Rails was to a large extent a protest against the burpcratic horrors of Java and the ugliness of PHP

            Ruby is a beautiful language by any means, it is based on SmallTalk, not ALGOL

        • Most Ruby apps I've seen are slow and brittle and have been rewritten or abandoned. There are not a lot of Ruby success stories. I don't blame the tool, but the tool attracted some read problematic people to write code in them.

          UGH. You are reminding me of my current boggle: samba admin-tools. If you want to manage a Samba DC you have two choices AFAIK, use Windows or use samba admin-tools. admin-tools is distributed only as source and an appImage which segfaults immediately on my system. It's written in ruby as an addon for YaST, which is itself a clusterfuck. The build process doesn't correctly pass configure flags through to subprojects, and some of the subprojects (parts of YaST) have shitty build settings requirements like th

    • To me, Ruby with explicit, static typing would be like a salad with a scoop of ice cream. They just don't go together.

      He's also never heard of Heart of Palm Salad, which is served with a scoop of pistachio ice cream as the "dressing". And it is rather good...

  • by RightwingNutjob ( 1302813 ) on Sunday May 07, 2023 @09:27PM (#63505333)

    It works beautifully in small code snippets that fit into a single screen. The moment your function runs to more than 80 or 100 loc, it becomes more difficult to keep track and increases the probability of making an error.

    • by jsonn ( 792303 ) on Sunday May 07, 2023 @10:18PM (#63505405)
      Funny. Long functions without correct indentation are just unreadable garbage. Long functions don't show you the types on screen anyway. What was your point again?
      • Long functions with incorrect indentation are still correct in a curly brace language. And can be automatically indented to your liking by any half decent editor.

        • by jsonn ( 792303 )
          They may be semantically correct, but they won't be parsed correctly without significant extra overhead by humans. There is a reason why both clang and gcc will nowadays warn about mismatches between indentation and semantic structure.
          • They may be semantically correct, but they won't be parsed correctly without significant extra overhead by humans.

            Pulling down a menu item to automatically fix the indentation is significant extra overhead? I guess I'm selling myself cheap, I use menus all the time.

            • by jsonn ( 792303 )
              If you have to fix the indentation, doesn't that mean that it is significant? Make up your mind, please...
              • If you have to fix the indentation, doesn't that mean that it is significant? Make up your mind, please...

                No. It doesn't. A warning is not an error. You do NOT have to fix the indentation. You have the option to do so. My mind is made up, and I already know what I think, without any help from people who willfully refuse to understand the argument.

                • by jsonn ( 792303 )
                  If you care about the correctness of any code review, you definitely have to fix the indentation. Been there, done that, found the bugs. But you are obviously a 100x programmer, where basic human psychology doesn't apply.
                  • If you care about the correctness of any code review, you definitely have to fix the indentation.

                    And you can do it by pulling down a menu. As opposed to Python, where you have to understand the code to fix the indentation if it's lost. I do not understand why this is even an argument. Control flow through indentation is literally a throwback to punch cards. Anyone who thinks it's a good idea is ignoring the lessons of computing's past. That literally is how things used to work, and we figured out it was a terrible idea and moved past it.

                    • by jsonn ( 792303 )
                      The argument works both ways. Merge is misplacing {}? Automatic indentation will fix that for you and any clue to what is going wrong. So no, "We figured out it was a terrible idea" is blatantly bullshit. If anything, "we" figured that code formatting should be done automatically and ensure that human and machine interpretation of code flow always match up. That's ironically the point where it no longer really matters if the whitespace is semantically relevant or not.
                    • So no, "We figured out it was a terrible idea" is blatantly bullshit.

                      Well, it's obviously bullshit in that Guido clearly didn't figure it out, and lots of other people are unclear on it besides. In other ways, it's perfectly true. The vast majority of us understand why it's a bad idea, the rest are making excuses for bad decisions.

            • Pulling down a menu item to automatically fix the indentation is significant extra overhead?

              Good grief yes. That's positively barbaric. Hit = of course.

      • by narcc ( 412956 )

        Incorrect indentation isn't a problem in the real world as that can be fixed in less than a second at the press of a button. Provided, of course, that you use a language with sensible syntax.

        What was your point again?

  • by Arzaboa ( 2804779 ) on Sunday May 07, 2023 @09:40PM (#63505357)

    Ahhh, the stories of a guy figuring it out as he grows up.

    --
    Poetry is an echo, asking a shadow to dance. - Carl Sandburg

  • Ummmm (Score:5, Insightful)

    by Morpeth ( 577066 ) on Sunday May 07, 2023 @09:41PM (#63505363)

    JavaScript and delight should never be used in the same sentence. Hell, even the guy who invented JSON thinks it should be retired.
    https://devclass.com/2022/08/0... [devclass.com]

  • Nope (Score:5, Informative)

    by Waccoon ( 1186667 ) on Sunday May 07, 2023 @10:07PM (#63505391)

    "Joy" and "JavaScript" do not belong in the same sentence.

  • It's not 2010... is this relevant at all in 2023?

  • by 1s44c ( 552956 ) on Monday May 08, 2023 @01:57AM (#63505733)

    Why do people say Ruby is beautiful code? Or can be used to write beautiful code?

    Just about everything described as idiomatic Ruby looks plain ugly. The gem names are beyond stupid having no relation to their function.

    Plus Ruby is slow, like really slow.

    Why are people doing this to themselves when they can just use python which is easier to learn, faster to run, better supported, and more readable?

  • by chas.williams ( 6256556 ) on Monday May 08, 2023 @06:16AM (#63505993)
    Dynamic typing isn't going away, but anyone who believes 2 + true isn't an error must have their keyboard taken away.
    • by G00F ( 241765 )

      Dynamic typing isn't going away, but anyone who believes 2 + true isn't an error must have their keyboard taken away.

      but it's isn't true and false, its 0 or 1.

  • Yes, it is faster to code without that pesky type stuff. But when you have to read another person's code, you will kiss the ground for the type declarations. And when you refactor a large code base, you will be immensely thankful again because the type system will catch 99% of your mistakes.
    • But how many of those errors are actually due to poor naming conventions, bad comments and poor documentation.
      • Hi -

        Probably a lot. But the reality is that most people don't comment their code today. And type declarations are a type of self-documentation - and the compiler checks that it is up to date.

        My original comment stems from the massive amount of pain that I have had reverse engineering Python code to use machine learning libraries - trying to figure out what kind of thing some method returns. Same for Go code.

        Also, a few times I had to refactor large codebases in Ruby and Java. For the Java code, no new error

  • by dvice ( 6309704 ) on Monday May 08, 2023 @09:45AM (#63506397)

    Dynamic typing is better if you prototyping and you are going to throw the code away. E.g. when I'm solving school math problems, I don't want to specify the type for variable X, it would be too much work with no benefit.

    Static typing is better if you have live with the code you write. So if you are going to maintain the code you write, you want to know the types. I have wished Javascript to have static typing many times when I have had to change the data structure. It is just so much easier when compiler tells you every location you need to change.

  • Static typing makes my code fast
    DEFINT A-Z

  • Dynamic typing is fine if you like debugging more than writing working code.

If you didn't have to work so hard, you'd have more time to be depressed.

Working...