Live data from Hacker News

Ruby delights built into the language

technology.doximity.com

51–60 of 89 posts

Re: Ruby delights built into the language

#51

Earlier quoted context omitted.

> I though this would be about different parts of the standard library, but it's about files from the example folder. All of the examples given use only the standard lib, afaict.

Yet there's almost no real discussion of how to use the standard library here, and a lot of talking about example code that's mostly useless (seriously - why is biorhythm pseudoscience #2, and how is displaying a calendar on the CLI going to help me...?) I agree with the top post - I have a very different idea about what "built-in" means than the author of this article.

> how is displaying a calendar on the CLI going to help me

How is displaying "Hello world" on the CLI going to help me?

Re: Ruby delights built into the language

#52
post #44

I appreciate the Ruby love in this post, but it's worth pointing out that the author is clearly new to the language. I say that because he writes Ruby as if he's writing some other language, and not idiomatic Ruby. This: dirp = Dir.open(".") for f in dirp case f when /\.rb\z/ print f, "\n" else # do not print end end dirp.close Could be made much more Ruby-native (and simpler!) as: Dir.open('.').each do |f| puts f if…

That snippet looks like Python/Lua/C with the for, case and close being used. Ruby is one of those languages that like Lisp/Scheme, Smalltalk or Haskell requires you to know what is going on as well as what is available to come up with a clean/simple solution. I think finding good Ruby resources that are up to date are few but I believe most of the stuff out there still works in recent versions.

> That snippet looks like Python/Lua/C with the for, case and close being used

Not really Python like at all - apart from the one line with for. Python doesn't have a case or when statement, or syntax level regex, doesn't open or close directories, and for files it would idiomatically would use the context manager for file access rather than closing it.

But it also doesn't look like any Ruby I've seen or written either :)

Re: Ruby delights built into the language

#53

I appreciate the Ruby love in this post, but it's worth pointing out that the author is clearly new to the language. I say that because he writes Ruby as if he's writing some other language, and not idiomatic Ruby. This: dirp = Dir.open(".") for f in dirp case f when /\.rb\z/ print f, "\n" else # do not print end end dirp.close Could be made much more Ruby-native (and simpler!) as: Dir.open('.').each do |f| puts f if…

You're quite right -- the author of that code *was* very new to the language when he wrote this, but then again, so were we all. [0]

[0] https://github.com/ruby/ruby/commit/3db12e8b236ac8f88db8eb46...

Re: Ruby delights built into the language

#54
post #50

Earlier quoted context omitted.

So the weirdest part is that the OP is literally just a cut and paste of a bunch of scripts found in the ruby distribution "samples" folder (that I had no idea even existed). That pretty not great ruby wasn't written by the author -- it's actually included in a "sample" file with the ruby distro? https://github.com/ruby/ruby/blob/ruby_3_1/sample/dir.rb A file whose commit history shows... it's part of the very first…

> A file whose commit history shows... it's part of the very first commit recorded in git history, in 1998 by matz, the original author of ruby. So not necessarily written by Matz, but part of the body of work that eventually saw a `git init`, and early enough that much of the modern standard Ruby formatting was still emerging. Doesn't seem all that surprising to me in the context of when it was written.

This was written by matz some time between 1993 and 1994. It appeared in the very first preview release of ruby, version 0.49. The original tarball has the file modification timestamps:

    $ curl -s https://cache.ruby-lang.org/pub/ruby/1.0/ruby-0.49.tar.gz | tar -tvz | grep dir.rb
    -rw-r--r--  0 matz   root      127 Jun  3  1994 ruby/sample/dir.rb

Re: Ruby delights built into the language

#55
post #54
post #50

Earlier quoted context omitted.

> A file whose commit history shows... it's part of the very first commit recorded in git history, in 1998 by matz, the original author of ruby. So not necessarily written by Matz, but part of the body of work that eventually saw a `git init`, and early enough that much of the modern standard Ruby formatting was still emerging. Doesn't seem all that surprising to me in the context of when it was written.

This was written by matz some time between 1993 and 1994. It appeared in the very first preview release of ruby, version 0.49. The original tarball has the file modification timestamps: $ curl -s https://cache.ruby-lang.org/pub/ruby/1.0/ruby-0.49.tar.gz | tar -tvz | grep dir.rb -rw-r--r-- 0 matz root 127 Jun 3 1994 ruby/sample/dir.rb

[deleted]

Re: Ruby delights built into the language

#56

I appreciate the Ruby love in this post, but it's worth pointing out that the author is clearly new to the language. I say that because he writes Ruby as if he's writing some other language, and not idiomatic Ruby. This: dirp = Dir.open(".") for f in dirp case f when /\.rb\z/ print f, "\n" else # do not print end end dirp.close Could be made much more Ruby-native (and simpler!) as: Dir.open('.').each do |f| puts f if…

Or even:

  puts Dir["*.rb"]

Re: Ruby delights built into the language

#57
post #28

Earlier quoted context omitted.

… and ruins the life of future maintainers, there’s a reason few languages tried to borrow features from ruby’s metaprogramming (saying this as a rubyist)

Metaprogramming is powerful for making really nice, easy-to-use _libraries_. It shouldn't ever be used for business logic. Ever. Unless you're going to go all in and make a DSL for your business, but I don't know of anyone who actually does that.

method_missing is only one tool in the metaprogramming toolbox (just probably the worst one). i wouldn't necessarily throw out the whole toolbox, particularly with ruby.

Re: Ruby delights built into the language

#58

This almost reads more like a list of cruft which should be removed from the stdlib (obviously not benchmark.rb though). For delegation it is probably better to use forwardable and be explicit about delegated methods--delegate.rb smells like it uses method_missing magic.

You don't see much ruby anymore that uses `DelegateClass`, the primary interface to delegate.rb. It does use metaprogramming but no more than Forwardable does. Also, it's "the good kind" of metaprogramming: active at program boot only, not a whiff of method_missing. This is closer to a lisp or rust macro: code which writes code. Exactly what ruby excels at.

https://github.com/ruby/ruby/blob/afd46429fcdb83aa9fa7c193ed...

SimpleDelegator is still pretty common though, I wouldn't blink if I saw that while reviewing a PR.

Re: Ruby delights built into the language

#59
post #28

Earlier quoted context omitted.

I love method_missing - one simple method unlocks so much power and eliminates so much boiler plate.

… and ruins the life of future maintainers, there’s a reason few languages tried to borrow features from ruby’s metaprogramming (saying this as a rubyist)

It really doesn’t have to. I believe this is from Smalltalk. Objective-C has something similar. It’s extremely powerful if used properly.

Re: Ruby delights built into the language

#60
post #54
post #50

Earlier quoted context omitted.

> A file whose commit history shows... it's part of the very first commit recorded in git history, in 1998 by matz, the original author of ruby. So not necessarily written by Matz, but part of the body of work that eventually saw a `git init`, and early enough that much of the modern standard Ruby formatting was still emerging. Doesn't seem all that surprising to me in the context of when it was written.

This was written by matz some time between 1993 and 1994. It appeared in the very first preview release of ruby, version 0.49. The original tarball has the file modification timestamps: $ curl -s https://cache.ruby-lang.org/pub/ruby/1.0/ruby-0.49.tar.gz | tar -tvz | grep dir.rb -rw-r--r-- 0 matz root 127 Jun 3 1994 ruby/sample/dir.rb

Fun retrocomputing diversion: Initial Ruby development was done on Sony NEWS, the same type of workstation that hosted the earliest PlayStation development boards: https://en.wikipedia.org/wiki/Sony_NEWS
Post reply on HN