Live data from Hacker News

Ruby 3.4 Highlights

blog.sinjakli.co.uk

71–80 of 86 posts

Re: Ruby 3.4 Highlights

#71

The default block parameter name seems small, but I feel like I'm gonna use it all the time, especially when I'm in the Rails console just trying to debug data

I constantly run into situations where I need to nest an iterator computation, and things like "it" get confusing. I'm all for adding language features to avoid boilerplate, and it's clearly useful. I just want to call out that anonymous typing can be polarizing in large codebases and maybe only use it sparingly.

Being ruby you can monkey patch block to add an additional t to every nested block’s `it`

(This is terrible please don’t)

Re: Ruby 3.4 Highlights

#72

I know Shopify has a great site on comparing Ruby vs YJIT perf. https://speed.yjit.org But does anyone have current numbers on how Ruby/YJIT compares to something like Python/PHP/LuaJIT?

The Computer Language Benchmarks Game has some compared benchmarks:

Ruby+YJIT vs Python: https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

Ruby+YJIT vs PHP: https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

Ruby+YJIT vs Lua: https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

Re: Ruby 3.4 Highlights

#73

The default block parameter name seems small, but I feel like I'm gonna use it all the time, especially when I'm in the Rails console just trying to debug data

I've not been tracking ruby core discussions for ages now, but I could have sworn that exactly this was discussed and rejected a decade or so ago.

I think I remember that as well. If you read the changelog, it goes through a good deal of edge cases behaviors that they probably ironed out in the intervening time, like captured variables with the same name and nested blocks with it parameters.

Re: Ruby 3.4 Highlights

#74

I happen to be reading the latest edition of the pickaxe book, as I'll soon be using Ruby at work (first experience) and this 'it' update sounds so much better than the _1 described in the book. I remember thinking it clashed a bit with the idea of trying to make the code read like natural language.

_1 is also a bit of a footgun. It becomes an array of all block params IF the block has an arity > 1 AND no other block param (e.g. _2) is referenced anywhere within the block. It's an unusually half-baked feature by Ruby's standards. I think there was some hesitation about the name "it" initially, because "it" is an essential method name in rspec, and is used within blocks there.

Oh damn. I have been using `_1`, `_2`, etc. extensively for years... I didn't know about that footgun.

I'd like know if `it` is merely an alias for `_1`, or if protects from this "arity issue" too.

Re: Ruby 3.4 Highlights

#75

I happen to be reading the latest edition of the pickaxe book, as I'll soon be using Ruby at work (first experience) and this 'it' update sounds so much better than the _1 described in the book. I remember thinking it clashed a bit with the idea of trying to make the code read like natural language.

FYI, one of my favorite Ruby idioms is to capture command output with `open(...){_1.read}`

  pp open("|ls -lh /usr/bin/ls"){_1.read}
  "-rwxr-xr-x 1 root root 135K Aug 30 04:57 /usr/bin/ls\n"
or to quickly print tabular data

  open("|column -t -s \\t", "w"){_1 

Re: Ruby 3.4 Highlights

#76

I happen to be reading the latest edition of the pickaxe book, as I'll soon be using Ruby at work (first experience) and this 'it' update sounds so much better than the _1 described in the book. I remember thinking it clashed a bit with the idea of trying to make the code read like natural language.

FYI, one of my favorite Ruby idioms is to capture command output with `open(...){_1.read}` pp open("|ls -lh /usr/bin/ls"){_1.read} "-rwxr-xr-x 1 root root 135K Aug 30 04:57 /usr/bin/ls\n" or to quickly print tabular data open("|column -t -s \\t", "w"){_1

Am I missing something - it's 2am here, so possibly - or could you not just use backticks for the first one?

Re: Ruby 3.4 Highlights

#77
post #57
post #40

Earlier quoted context omitted.

I pity anyone needing to debug a fiddly Rspec problem in the next few years.

IIRC, the decision was that it in a block is only ever called without arguments, e.g. map { it * 2 }, and it in Rspec is only ever called with arguments, e.g. it "describes a test" do ... end. So it ended up being a non-issue.

I can totally see some add on gem for rspec breaking that assumption.

Re: Ruby 3.4 Highlights

#78
post #76

Earlier quoted context omitted.

FYI, one of my favorite Ruby idioms is to capture command output with `open(...){_1.read}` pp open("|ls -lh /usr/bin/ls"){_1.read} "-rwxr-xr-x 1 root root 135K Aug 30 04:57 /usr/bin/ls\n" or to quickly print tabular data open("|column -t -s \\t", "w"){_1

Am I missing something - it's 2am here, so possibly - or could you not just use backticks for the first one?

Oh that's embarrassing -- you're right, the first example doesn't make sense. Kinda pointless actually haha

I use it for code like this:

  raw = IO.popen(%W[gzip -d -c -- #{path}]){_1.read}
  raw = IO.popen(%W[gzip -d -c], in: pipe){_1.read}
  raw = IO.popen(%W[git status --porcelain -- #{path}]){_1.read}
Useful because it eliminates /bin/sh footguns (e.g. `md5sum hello&world` forking or `~john` expanding), plus you get kernel.spawn() options. `open("| ...)` only made sense for the second example.

Anyway, I find "_1" more eye-pleasing than:

  IO.popen(%W[gzip -d -c #{path}]){|io| io.read}

Re: Ruby 3.4 Highlights

#79
I don't understand the change of the default block parameter name. It's already _1, _2, etc. Why create yet another, backward-incompatible way?

And still, they doom march forward with the fragmentation of rbs and sorbet/tapioca, rather than adopting in-band gradual typing like Python did.

I think the greater problem is Ruby appears to be developed by a nearly-closed small clique of people who refuse to listen to others or to reason.

Re: Ruby 3.4 Highlights

#80
post #51

Earlier quoted context omitted.

You can always use Crystal or Dart if you want builtin types. I like Ruby the way it is an trust Matz with his language design decisions.

Crystal is the closest alternative to Ruby with types we have, even though they are semantically different and differ in some places. I do not see why you mentioned Dart as an alternative thought, it’s a totally different language.

> Dart as an alternative thought, it’s a totally different language

Yes it's not Ruby but it has good design, optional type annotations.

Post reply on HN