Live data from Hacker News

Types will be part of Ruby 3 stdlib source

twitter.com

181–190 of 216 posts

Re: Types will be part of Ruby 3 stdlib source

#181
post #82

Earlier quoted context omitted.

So, what, everyone standardizes around an IDE then? You really think that's gonna unite the vim and emacs camps? I'm personally tired of staring at variables trying to figure out what they're supposed to be, then having to dive into source to see how its used. C/C++/C# solved that problem, why are we still dealing with it?

C had some typing, but I'm not going to call it "solved" until "numberOfHats = distanceInPixels + weightInKg" is considered a compile-time error due to the three "int" values being incompatible; but "numberOfHats = aliceHatCount + bobHatCount" is acceptable. How does nobody(?) support this yet? Python supports some parts: you can subclass int, and you get all of the int methods like addition and subtraction for free,…

Every language that has generics supports this via phantom type variables that can encode extra information only in the type system alongside some other type, or with a specific newtype keyword that effectively does the same:

    newtype Pixel = Pixel Int
    newtype Em = Em Int

    pixelWidthToEm :: Pixel -> Em
    pixelWidthToEm (Pixel px) = Em px
You can try to call `pixelWidthToEm` with anything other than pixels and it won't work.

More dynamically, with an open type variable that only exists in the type system:

    data User a =
      User { name :: String, socialSecurityNumber :: String }

    data LogSafe
    data LogUnsafe

    logUser :: User LogSafe -> IO ()
    logUser = undefined

    makeUserLogSafe :: User LogUnsafe -> User LogSafe
    makeUserLogSafe = undefined
We can never log the user unless the user is deemed LogSafe and we make functions that produce log safe users that you have to call before hand, in order to make sure that sensitive data isn't printed to logs.

These are things that have been around for a long time in almost every type system, but people's general lack of interest in using type systems to help them conspires to keep them in the dark.

Here's how you can create a number type distinct from other number types in TypeScript:

    type DistanceInPixels = number & { readonly __newtype__: "DistanceInPixels" }
And a type alias that allows you to create them:

    export type Newtype = T & { readonly __newtype__: Tag }
    type Pixels = Newtype

Re: Types will be part of Ruby 3 stdlib source

#182
post #160
post #158

Earlier quoted context omitted.

The slowness of brew isnt ruby's fault. They don't keep a local cache of the taps, but instead searches for taps using an API that interfaces with github and searches local taps, remote taps, then blacklisted taps and then probably something more. It is limited by network speed, not by string searching. Edit: explained better here: https://github.com/Homebrew/brew/issues/3056#issuecomment-32...

It's not limited by network speed because I have HOMEBREW_NO_GITHUB_API and HOMEBREW_NO_AUTO_UPDATE enabled. It's not like I just today stumbled into the problem. Brew's not even consuming much system cpu time during `brew search`, despite hogging a core for a full minute. Even just `brew help` takes almost 10 sec cold.

Are you using JRuby or something? 10 seconds is too long.

> time brew help

> brew help 0.55s user 0.26s system 96% cpu 0.849 total

Re: Types will be part of Ruby 3 stdlib source

#183
post #182
post #160

Earlier quoted context omitted.

It's not limited by network speed because I have HOMEBREW_NO_GITHUB_API and HOMEBREW_NO_AUTO_UPDATE enabled. It's not like I just today stumbled into the problem. Brew's not even consuming much system cpu time during `brew search`, despite hogging a core for a full minute. Even just `brew help` takes almost 10 sec cold.

Are you using JRuby or something? 10 seconds is too long. > time brew help > brew help 0.55s user 0.26s system 96% cpu 0.849 total

Regular Ruby 2.5.1. I do have a throttled CPU due to no battery in the MacBook, but I still have Python and other stuff to compare, and Brew (or Ruby) definitely does something wrong on my machine. It's hugely CPU-bound without a particular reason for being so.

Re: Types will be part of Ruby 3 stdlib source

#184
post #171
post #135

Earlier quoted context omitted.

I honestly think that more than Matz reconsidering his own opinions, it probably turned out that having types is an instrumental thing to enable performance improvements. Keep in mind, Ruby development is headed towards a goal that the dev team has called "3x3" as in Ruby 3 aims to be three times faster than current Ruby implementation.

My recollection is that 3x3 is a goal to be 3x faster than Ruby 2.0–presumably many of those gains have already been realized, so best not to depend on tripling _current_ performance.

Yeah, the NES emulator that's one of the benchmarks is about 1.8x faster so far, so only another 1.6x to go on top of that.

Re: Types will be part of Ruby 3 stdlib source

#185
post #180

Earlier quoted context omitted.

It depends what do the type annotations do. I'm not sure how perl6 does it, but for example in python type annotations are completely ignored at runtime, so don't have any impact. We'll see how much / for what does Ruby 3 actually want to use the type information. Sorbet on its own is unlikely to affect runtime either.

Going to keep praying for type/performance optimizations in Python so we can all get past the "python is slow" thing. Async python is an absolute joy to develop with.

Care to elaborate which type of work you're doing and which libraries you're using?

Re: Types will be part of Ruby 3 stdlib source

#186
post #117

Earlier quoted context omitted.

Instead of: sig {params(name: String).returns(Integer)} ... why not simply: sig [String]=>[Integer] Yes, that's just ruby - see https://github.com/s6ruby/ruby-to-michelson/blob/master/cont... for example for live running code (in secure ruby) :-)

At the very least, sigs need to be in blocks so they can be lazy and not require that all constants in any sig be loaded at require time. It was a design decision that all type annotation arguments be named as opposed to positional. As one example why, it makes the error messages better. You can always say "You're missing a type declaration for parameter 'foo'" as opposed to "You have four positional arguments and 3…

For the "do not require" the type annotations / signatures so they can be lazy I would use / recommend a language pragma and not a block. Learn more about language pragmas (works kind like a pre-processor) :-) - https://github.com/s6ruby/pragmas I think you already have made-up your own "magic comments" / language pragma e.g. # type: true and so on.

> I'm not sure we'd make constants with unicode like > BigMap‹Address→Account› for generics, though, how do > you even type that? :)

I see you managed to type it! What's your secret? :-). By the way, you can use the alternate ASCII-style e.g. BigMap.of(Address=>Account).

Re: Types will be part of Ruby 3 stdlib source

#187
post #83

Instead of: sig {params(name: String).returns(Integer)} ... why not simply: sig {name: String, returns: Integer}

Instead of: sig {params(name: String).returns(Integer)} ... why not simply: sig [String]=>[Integer] Yes, that's just ruby - see https://github.com/s6ruby/ruby-to-michelson/blob/master/cont... for example for live running code (in secure ruby) :-)

Looking through the online docs. Here's another instead of:

   sig {params(new_value: T.nilable(Integer)).void}
... why not simply:

   sig Integer?                  # or
   sig [Option.of(Integer)]=>[]  # longest form in sruby
   sig [Integer?]=>[]            # same as Integer?

Re: Types will be part of Ruby 3 stdlib source

#188

My concern about all of this is that it might lead to basically two ruby communities; Rails and Rails devs will mostly keep writing type free code (dhh has always indicated he's not a fan of types), but a lot of other rubyists will gradually introduce types into their code. This could create two different ecosystems with different gems, best practices, blogs etc etc etc. We will see how it plays out but I'm quite con…

I really like python's approach, which is to provide syntactic support for type annotations, but have them treated as pure comments by the language runtime. That way, type checkers can check your code if you like, but no one is forced to use typed code if they don't want to, even if they are using a "typed" library.

Re: Types will be part of Ruby 3 stdlib source

#189
post #110

Earlier quoted context omitted.

Right, so why not implement the sig as a block and keep the syntax concise - the Ruby Way.

Then you'd need an extra set of delimiters, e.g.: sig {{name: String, returns: Integer}}

But that would make the hash braces redundant so you could just use parenthesis.

Re: Types will be part of Ruby 3 stdlib source

#190
FYI: The RubyKaigi 2019 Progress Report on Ruby 3 Talk Slides have more (from the source) info. See the slides titled "Static Analysis" [1]

Ruby 3 static analysis will have four items:

1. Type signature format 2. Level-1 type checking tool 3. Type signature profiling / prototyping tool 4. Level-2 type checking tools

and so on. [1]: https://docs.google.com/presentation/d/1z_5JT0-MJySGn6UGrtda...

Post reply on HN