←back to thread

511 points mootrichard | 1 comments | | HN request time: 0.207s | 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 #
regularfry ◴[] No.23990947[source]
I can well imagine that it might be because ruby's formal syntax is already utterly bonkers, and the thought of adding types to it in any usable fashion gave someone a seizure.
replies(1): >>23991741 #
rudolph9 ◴[] No.23991741[source]
Haven't used ruby in years for the typical reasons people move away from it (performance, strong types, GVL, etc.) but syntax is #1 reason I like programming in Ruby. I did mostly ruby for about 5 years and really grew to love it! It may seem bonkers at first but quite enjoyable once you understand it. Now nearly 4 years later of mostly javascript, golang, python, haskell I still regularly stop and think to my self how much I miss ruby!
replies(3): >>23991854 #>>23991856 #>>23991913 #
hrktb ◴[] No.23991856[source]
I read parent’s “bonkers” in a positive way.

Then for instance most languages get away with inline optional typing by using “:” , for instance “ping_user(name: String)“. In ruby it’s of course already taken, in no small part because there are 3 or 4 different ways to declare hash parameters.

I’d imagine most decent syntax candidates had similar issues, due to ruby’s syntax versatility.

replies(3): >>23992665 #>>23993158 #>>23996311 #
1. Glyptodon ◴[] No.23993158[source]
I'm trying to think of any typical chars that don't already mean something and I think at best you'd have to use a pair and even then it would potentially break older code. Very badly offhand something like: `attr_accessor ~:String :name` and `def sing(~:Song song):` seems pretty ugly but borderline feasible on the premise that while ~ and : have meaning in Ruby, it's not super likely that bitwise inverting symbols is common. (I'm sure there more reasons that wouldn't work or isn't great.)

I don't like the separate file thing, but it does seem more challenging than I'd have thought to avoid.

I guess on a tangent Ruby code historically cares a lot more for duck typing so strong typing will be a headache for a lot of stuff.