Tuesday 27 July 2010 — This is more than 14 years old. Be careful.
Armin’s post about Whitespace sensitivity
in Ruby piqued my interest. It points out that in Ruby, foo[42]
is different than foo [42]
and that foo/bar
is the same as foo / bar
but different than foo /bar
.
So I wanted to learn more about Ruby, and looked at a bunch of tutorials, finally ending up at Mitch Fincher’s Ruby Tutorial with Code Samples, which had the right breezy pace with no, “a variable is like a box for your numbers” stuff in it.
But I had originally gotten to Mitch’s page from a Google search for ruby puts gets. If you try it, you’ll see that when you get to Mitch’s page, a small box appears near the top, saying,
Welcome. You seem to have come here from a search engine. Your search words (ruby puts gets) are highlighted on this page for your reading pleasure.
I thought “nice,” then I thought, “that looks familiar,” then I realized it was almost exactly the box that appears at the top of my pages when you visit from a search engine (try it: batchelder white house adventure). In fact, it used the same colors. I looked at his page, and it used near-verbatim copies of my three Javascript files, though a few years ago I consolidated them into one.
I was amused, and wondered where else the code is being used. But the search engines are smart enough not to index comments in Javascript files, or names of Javascript files referenced in HTML pages, unless there’s some tricky syntax I don’t know about.
PS: about whitespace sensitivity: I’ve decided that phrase means a programming language needs tokens consisting of only whitespace in order to be parsed properly. Python and Ruby are whitespace-sensitive, and C is not, for example.
Comments
Later,
Blake.
In your example, "/ *" is tokenized as "/", "*", and "/*" is the start of a comment, but there are no tokens that are purely whitespace.
Later,
Blake.
Extending your idea, leading whitespace in Python cannot be collapsed into a single whitespace token as different indentations affect Python semantics.
To top it off, whitespace within a line (?I think in all cases?) as well as whitespace at the end of a line are ignored.
Thanks for writing the hilite javascript! I saw you use it on one of your pages. A little reading of your code showed me how you did it. I was thunderstruck at the time. I had always modified code on the server-side in perl and pushed it down to the browser. Your code was doing it on the ... gulp ... client side. It was a revelation at the time. I have been using the code for years now.
Cheers, Mitch
Add a comment: