Re:Types will be part of Ruby 3 stdlib source
by eru on Friday April 19, 2019 @03:09AM
(#19697654)
I thought the ML family of languages showed that long ago? I guess TypeScript popularized the notion.
[ Parent
| on HN ]
Re:Types will be part of Ruby 3 stdlib source
by bfung on Friday April 19, 2019 @03:43AM
(#19697778)
ML family has "type inference", which means the compiler figured out the type even if not explicitly written into the code. However, the language spec is still statically typed - an int will not turn into a string and vice versa (ex: "1").
Javascript and ruby, the underlying types can change depending on where the code is in execution - a variable holding a 1 can turn into a "1" and back (implicit type conversion - try 3 * "3"). This leads to a whole class of bugs not possible in a statically typed codebase where explicit conversion needs to happen - I have no hard data, but I remember debugging this type of stuff far too often and far too many times when I could've spend my time better elsewhere. (but I actually like ruby a lot!)
Type checking is not the same as being statically vs. dynamically typed!
Re:Types will be part of Ruby 3 stdlib source
by abhorrence on Friday April 19, 2019 @12:29PM
(#19700834)
> a variable holding a 1 can turn into a "1" and back
This is true of Javascript, but not of Ruby.
irb(main):001:)> 3 * "3"
TypeError: String can't be coerced into Fixnum
People commonly conflate dynamic typing with weak typing, Ruby has the former, but not the latter (with some explicit exceptions, e.g. to_ary and friends).That's not to say you can't still end up with some interesting problems though -- if we just slightly change your example:
a = 3
b = 3
# later...
a = "oops"
product = a * b
# product is now "oopsoopsoops"
But this isn't due to automatic "weak types" style coercion -- just that Ruby lets you build a repeated string by multiplying a string by a number.
Re:Types will be part of Ruby 3 stdlib source
by eru on Saturday April 20, 2019 @10:54AM
(#19706812)
The alternative view is that those so-called 'dynamically typed' or 'untyped' languages should really be called 'monotyped languages' since all variables and expressions have the same type: a giant union of all possibilities.