Most active commenters

    ←back to thread

    511 points mootrichard | 14 comments | | HN request time: 0.847s | source | bottom
    Show context
    muglug ◴[] No.23990520[source]
    Can someone explain why the types cannot live in Ruby code itself (after an appropriate version bump)?

    Python 3 incorporated types into the language itself, in a similar way (though non-reified) to PHP. This seems much easier to deal with than requiring two files (.rb and .rbs) to describe a single data structure.

    replies(4): >>23990918 #>>23990947 #>>23991201 #>>23991455 #
    burke ◴[] No.23990918[source]
    Because Matz won't let people add type annotations to the ruby grammar.
    replies(1): >>23991128 #
    jakearmitage ◴[] No.23991128[source]
    Which is great.
    replies(2): >>23991239 #>>23991260 #
    1. fimbulvetr ◴[] No.23991260[source]
    I don't use ruby, I am genuinely interested - why is it great? I'm assuming if it were ever allowed, it would be a use-at-will feature and wouldn't affect anyone who didn't use it. Typescript has probably doubled if not more my speed and accuracy since I've adopted it - yet I still do plenty of things in normal javascript. These days I'm usually unhappy when something does not have typings because it can make it terribly difficult to discover things.
    replies(3): >>23991436 #>>23992170 #>>23992513 #
    2. sparker72678 ◴[] No.23991436[source]
    The philosophical argument in the Ruby community is basically that Ruby is not a statically typed language, period. And a strong contingent, myself included, do not want a hybrid world where type annotations are optional, spattering redundancies all over our syntax. Mostly because I see that as a step in the direction of some kind of "strict" mode that will ultimately enforce type annotations and type-checking and destroy most of what I love about Ruby.

    That's why the approaches being used keep the type annotations out of the source files themselves.

    replies(2): >>23991582 #>>23992236 #
    3. jolux ◴[] No.23991582[source]
    The best type definition languages do not introduce redundancies. They describe information that is not already in the implementation itself.
    4. rosywoozlechan ◴[] No.23992170[source]
    > Typescript has probably doubled if not more my speed and accuracy since I've adopted it

    TypeScript hasn't ever done anything for me than give me 3rd party dependency integration headaches. I love strongly typed languages and compile time checking, but TypeScript has never seemed worth the trade off due to its broken interoperability with normal JavaScript and the terrible state of crowd sourced typedefs. I'm either fighting some badly defined third party typedef, spending a lot of time creating typedefs myself or dealing with a version issue because the typedef isn't compatible with the version of the library I'm using.

    When I use JavaScript I hardly ever run into issues that static typing would have prevented and I have zero TypeScript issues.

    Honestly how has it improved the speed at which you get things done? Were you just constantly running into JavaScript bugs due to the lack of typing?

    replies(3): >>23993397 #>>23998400 #>>24000864 #
    5. ric2b ◴[] No.23992236[source]
    > I see that as a step in the direction of some kind of "strict" mode that will ultimately enforce type annotations and type-checking

    Ruby is not the first or the second or even the third dynamic language that has added static type checking support, has this _ever_ happened?

    replies(1): >>23992558 #
    6. ysavir ◴[] No.23992513[source]
    It's great because Ruby is an Object-Oriented Programming language. Just saying that is an understatement; Ruby lives and breathes Object Oriented philosophies. It was made for them.

    The conflict here is that object oriented philosophies aren't actually about objects. They're about communication between objects. The messaging between objects. As per Alan Kay himself:

    > I'm sorry that I long ago coined the term "objects" for this topic because it gets many people to focus on the lesser idea. The big idea is "messaging".

    The goal of object oriented design is to focus on the communication between objects, not the objects themselves. Part of that is that the type of object receiving the message doesn't matter so long as it understands the message and knows how to respond. If the object looks like a duck, swims like a duck, and quacks like a duck, that's good enough--even if the duck turns out to be a chicken with an identity crises. It understood the message and responded, and that's all we want in object oriented programming, objects that can communicate with each other.

    Adding type checking flies in the face of this philosophy. Instead of type being irrelevant as long as the receiver of a message can understand that message, suddenly it's front and center. The code will accept or reject objects based on their type even if they're fully capable of upholding their end of the conversation.

    Type-less-ness is core to Ruby. But some people may still prefer to include typing. We all want to use the tools and practices that best enable us to deliver, so that's a fair want. But since Ruby as a philosophy doesn't care about type, it's important to maintain type checking as an accessory to the language, not a feature of it. Something that can be layered on top of the Ruby language for those that want it, but that can be ignored by those don't.

    replies(3): >>23992712 #>>24001964 #>>24004286 #
    7. captn3m0 ◴[] No.23992558{3}[source]
    PHP has a strict typing mode: https://www.brainbell.com/php/strict-type.html
    8. cutler ◴[] No.23992712[source]
    Bravo. Let dynamic languages be dynamic. Why does every *damn language have to approximate Java in the long run? PHP is nothing more than pseudo-Java and Javascript is heading in the same direction now classes have become firmly-established. At least there's still Clojure.
    replies(1): >>23998310 #
    9. mekster ◴[] No.23993397[source]
    What editor are you using?

    It's about having things auto completed and you get to see errors before you run.

    And what kind of library are you using to complain that third party typings are the source of your concern?

    10. jakearmitage ◴[] No.23998310{3}[source]
    Because ENTERPRISE.
    11. fimbulvetr ◴[] No.23998400[source]
    Most of the improvement is from the typings that other libraries come with, if, like you said, they are complete. Now I can just ctrl-click into an object to view it's methods and from their can view the interfaces the methods accept and the interfaces the interface accepts, and so on and so on.

    Honestly, I rarely refer to documentation for these things because every project is a snowflake and the documentation gradient goes from no documentation to perfect documentation. By that, I don't just mean the words, I mean the website or the framework used to document, as well as the style of documentation (more like flavor?) Typescript is the great equalizer that makes a project with no documentation (but decent comments or method/var names) just as documented as one that that does.

    I can also ctrl-space easy to get a list of methods in case I forgot which method I needed, or if I want to discover what's available. That's enormous in my style of programming. Sure beats going to someone else's documentation page, trying to read it.

    Some of the improvement is not necessarily that I have javascript bugs due to lack of typing but rather that with typescript I don't get those bugs which means I don't have to reason about avoiding those bugs anymore like I did with javascript. Sort of a reduced cognitive load.

    Also, I have a few coworkers that are not javascript/typescrpt savvy that I was able to get up to speed with typescript fairly easily due to the easy of using the types. There are, of course, hard things such as partials or understanding tsconfig.json or even generating types that I don't cover with them and just have them come and get me when they're ready.

    For most things without types I just do the declare module in a d.ts - however, I will first try to find another package that does the same thing with types. Most popular packages these days do include types, some better than others.

    After I re-read above, I realized that a lot of it depends on the IDE. If I were still using vim or kate/gedit, it probably wouldn't be a huge timesaver. Fortunately, I settled on one of the intellij editors.

    12. iomcr ◴[] No.24000864[source]
    This was my experience with typescript. Nothing I actually wanted to use had first class support for typescript. Nothing I settled with didn't have endless compiler errors that had more to do with the tsconfig than my actual types.

    Then at the end of the day, it was still JavaScript (an interesting word for "not ruby"), but with types slapped on top.

    I ended up switching to crystal, which is basically ruby + types (infered when possible, but I actually wanted the types) with the performance of golang.

    13. machiaweliczny ◴[] No.24001964[source]
    That's what structural typing is enforcing well. (used in TS, although IMO nominal is useful too)
    14. fomine3 ◴[] No.24004286[source]
    Agreed. I prefer typed but also really like Ruby as a dynamic language.