←back to thread

511 points mootrichard | 2 comments | | HN request time: 0s | 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 #
dependenttypes ◴[] No.23995054{3}[source]
Strong typing generally does not mean much and everyone seems to be using a different definition. Would you consider Javascript weakly typed? What about Python?
replies(1): >>23996995 #
mumblemumble ◴[] No.23996995{4}[source]
I'd consider JavaScript to be more toward the weak typing end of things, because it does lots of automatic conversions with surprising results. (see, for example, Gary Bernhardt's "Wat?" lightning talk.) I don't think I'd consider it as weak as C, which has things like unions and pointers that let you just sort of fall out of the type system entirely.

I'd consider Python to be more strongly typed than JavaScript. It doesn't do quite so many automatic conversions. For example, in Python, `1 + "foo"` is a TypeError. In JavaScript, it's "1foo". Sadly, `1 == True` in Python, so it certainly doesn't get full marks.

replies(2): >>23997573 #>>24007106 #
jolux ◴[] No.23997573{5}[source]
Examples like the last one about Python are why I think it’s approximately meaningless as a descriptor. I don’t see why dynamic languages should have any implicit conversions at all.
replies(1): >>23999597 #
1. mumblemumble ◴[] No.23999597{6}[source]
Where you store the type information and when you do the type check is a separate question from whether you do the type conversions automatically or not.

I think a more interesting question is typecasts, like happens in languages like Java and C#. These languages are nominally statically typed, but they retains some type information at run-time, so that you can perform run-time type conversions, which requires run-time type checking. Which is the defining feature of dynamic typing.

C# is a little bit more straightforward about being a hybrid static/dynamic language, with its reified generics and dynamic references. But teasing out the details of where, how, and the extent to which Java is statically or dynamically typed would make a decent topic for a master's thesis.

It also hints at a deeper thing that one must be mindful of: static/dynamic and strong/weak are not binary categories. They're not even the extremes of two binary scales. They are somewhat vague descriptions that are meant to serve as useful shorthands for certain sets of choices that one must make when designing a language's type discipline.

But the fact that they're not cut-and-dry terms does not mean that they're meaningless. It just means that one must disabuse oneself of the notion that they're cut-and-dry before one can have a conversation about type discipline that goes beyond a certain level of detail.

replies(1): >>24003824 #
2. jolux ◴[] No.24003824[source]
You’re muddying the waters. Static and dynamic have a much clearer distinction between them than “strong” and “weak” typing do. These things aren’t binary but that doesn’t mean they are equally descriptive terms.

Java is a statically typed language with late binding implemented through subtype polymorphism and its type system has been explored pretty extensively in the literature.