←back to thread

511 points mootrichard | 1 comments | | HN request time: 0.203s | 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 #
1. jolux ◴[] No.23991507[source]
If your type definitions are 3x longer than the functions implementing them, something is wrong. In languages with complete type inference, you actually don't have to write types at all if you don't want to, though in practice you end up doing so to clarify your intentions.

Static types do make certain classes of bugs impossible, like missing method bugs, typos, and the like. You can eliminate a large group of defensive programming techniques and trivial unit tests that you would need in a dynamic language to ensure a similar level of confidence in a program. Obviously they don't make all bugs impossible, there will be bugs as long as there are programs, because we write programs without perfect knowledge of the requirements, and this is an unavoidable pitfall of software.