Hacker News new | ask | show | jobs
by jrochkind1 1283 days ago
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 commit recorded in git history, in 1998 by matz, the original author of ruby.

I have no idea what's going on in that "sample" folder, very weird.

The OP is simply regurgitating the weird "sample" folder. The "author" of the OP didn't write any of this code. According to git history... matz did?!?

3 comments

I think the idioms develop over time. Or perhaps being samples, they were presented in a more language neutral way?

In any case, I wonder if the OP's motives were good or if this was just some SEO game... we have enough of the latter on the internet.

> 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
Hilarious origin story of Sony NEWS, how the engineers built a UNIX workstation they wanted, not what they were told to build.

> Sony's NEWS project leader, Toshitada Doi, originally wanted to develop a computer for business applications, but his engineers wanted to develop a replacement for minicomputers running Unix that they preferred to use.

> In the beginning, Doi's concept of the workstation was a device, which was essentially an extension of current [MIPS (Media Information Products and System) Business Group] projects. He saw it as consisting of "a 32-bit CPU developed in a short time with unrestricted applications." Basically, he thought of it as an OA computer.

> However, the engineers Doi selected for his team did not listen to what Doi told them to do. They wanted to develop a workstation that could replace the VAX Super Mini Computer developed by Digital Equipment Corp. (DEC). This was a computer that the engineers often fought with each other to use while at MIPS because of the limited number. They wanted to develop something they themselves could use for their own day to day work.

That file is very different with an added rewind and now case/when.

    dirp = Dir.open(".")
    dirp.rewind
    for f in dirp
      if (~/^\./ || ~/~$/ || ~/\.o/)
      else
        print(f, "\n")
      end
    end
    dirp.close

   if (~/^\./ || ~/~$/ || ~/\.o/)
ah, the perl heritage is strong here!
Then the reasoning for this weird code is that it's meant as a base to be extended. E.g. handling more variants of filenames? Anyways, maybe it's worth submitting a pull request with simpler code.