Most active commenters
  • regularfry(3)

←back to thread

511 points mootrichard | 15 comments | | HN request time: 1.929s | 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 #
1. 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 #
2. 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 #
3. regularfry ◴[] No.23991854[source]
As an end user, it's amazing. I do have sympathy for the implementers, though.
4. 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 #
5. chillfox ◴[] No.23991913[source]
Crystal [1] is a pretty nice ruby like language with types and it is up there with Go/Rust for runtime performance.

[1] https://crystal-lang.org/

replies(1): >>23995582 #
6. Polylactic_acid ◴[] No.23992665{3}[source]
The worst part of ruby imo is the fact that a hash can have both string and symbol keys. Countless times I have encountered issues where a function takes an options hash and the callers use both string and symbols for the same key depending on which caller it is. I end up calling the function to convert to symbols all the time.
replies(2): >>23992772 #>>23994157 #
7. rudolph9 ◴[] No.23992772{4}[source]
Actually, if my memory serves me, a ruby hash can use any object a key! And considering everything in ruby is an object (even the class `Object`) it’s really quite elegant
replies(1): >>23993152 #
8. vlunkr ◴[] No.23993152{5}[source]
This seems to be getting downvotes? I don't know why, it's accurate. Anything can be a key in Ruby.
9. Glyptodon ◴[] No.23993158{3}[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.

10. tdeck ◴[] No.23994157{4}[source]
This is why ActiveSupport (Rails) has Hash#with_indifferent_access and people use it all over the place.
11. nurettin ◴[] No.23995582{3}[source]
Crystal is nice since they added a decent concurrency model, but it doesn't support one of the major platforms (windows)
replies(2): >>23995657 #>>23999513 #
12. pjmlp ◴[] No.23995657{4}[source]
Same applies to Swift (even worse than Linux) and Go (e.g. plugins package).

So while I agree with you, I still look forward to see support for Windows eventually landing.

13. regularfry ◴[] No.23996311{3}[source]
I genuinely think that adding `:` as a hash separator was a mistake. Apart from anything else, you get this weird effect where the type of the key in `{"foo": bar}` isn't what you think it is.
14. Can_Not ◴[] No.23999513{4}[source]
Didn't ruby historically have poor support for windows? Everything great has to start small either eay.
replies(1): >>24018370 #
15. nurettin ◴[] No.24018370{5}[source]
Yeah no, you can say this against literally every criticism and be right unless someone comes up with time spans and user experiences of other great things to disprove it. Ruby was great on windows since 1.8, don't know how it was before that. I recently scripted AIX with it, so not really a contender on the same lane.