←back to thread

511 points mootrichard | 1 comments | | HN request time: 0.215s | source
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 #
zeptonix ◴[] No.23991239[source]
Yeah, it is.

I'm having a really hard time understanding this "I need types forced down my throat" and "I like typing 3x as much as I would otherwise need to" and "yes, I want half my screen obscured by the types of everything I'm doing, not the actual code" and the "adding types now means bugs are impossible" mass cult hysteria that's running so rampant. Typing very occasionally prevents bugs that are generally easy to catch/fix or show up straight away when running an app. It's mostly a documentation system. And it slows development down.

Especially in Ruby which is such an elegant "programmer's language" I think it would just be silly.

replies(7): >>23991394 #>>23991403 #>>23991487 #>>23991507 #>>23991525 #>>23991716 #>>23992038 #
mumblemumble ◴[] No.23991525[source]
> And it slows development down.

This can depend really heavily on what you mean by "development." If it's just getting the first version banged out, sure. If it includes coming back to code a couple years later in order to incorporate a new business requirement, having that documentation present can be a really big deal. 2 seconds spent typing out a type hint now might, down the line, save several minutes on average. Even in a recent Python project I did over the course of just a couple weeks, when I got to the "clean the code up and get it ready to put on the shelf for now" phase of the project, I ended up wishing that I had bothered to use type hints just a wee bit more when I was banging it out in the first place. It would have been a net time saver.

I don't like static typing super a lot in all cases because it makes it hard to do data-level programming. Which I find to be the true productivity booster in dynamic languages. But optional typing seems to hit the sweet spot for a great many purposes.

replies(1): >>23991556 #
jolux ◴[] No.23991556[source]
I'm curious what you mean by "data-level programming."
replies(2): >>23991731 #>>23992742 #
cutler ◴[] No.23992742[source]
Try Clojure for the ultimate programming in data experience. In Clojure code is data so everything is just data.
replies(1): >>23992841 #
jolux ◴[] No.23992841[source]
I have tried programming in Clojure :) I just prefer strongly typed languages.
replies(1): >>23992912 #
mumblemumble ◴[] No.23992912[source]
Clojure is strongly typed. I think you mean statically typed.

They're orthogonal concerns. C is statically and weakly typed. Clojure is dynamically and strongly typed. PHP is dynamically and weakly typed. Haskell is statically and strongly typed. Java, as the most design-by-committe language ever, manages to be a mix of all four.

replies(3): >>23993009 #>>23995054 #>>23995161 #
1. jbritton ◴[] No.23995161[source]
Weak typing is when types get automatically transformed like 2 + “3” == 5, “2” + 3 == “23”. Strong typing doesn’t do these types of automatic conversions and throws exceptions or generates a compiler error.

Static typing — types checked at compile time. Dynamic typing — types checked at runtime.