もしもし RSS

Archive

Apr
18th
Sat
permalink
Mar
16th
Mon
permalink
Machine. Unexpectedly, I’d invented a time
Dec
13th
Sat
permalink
Sep
7th
Sun
permalink
Aug
16th
Sat
permalink

Simple Ruby

Let’s take a look at this trivial Ruby example:

[1, 2, 3, 4].each { |i| puts i }

The first thing we notice is that the commas shouldn’t be necessary:

[1 2 3 4].each { |i| puts i }

We can also go Smalltalk style and remove the dot. Many languages do that, including the minimalist Io, so here we go:

[1 2 3 4] each { |i| puts i }

It’s shorter already, but now let’s switch to Groovy style, with the implicit ‘it’ object:

[1 2 3 4] each { puts it }

Can it be even shorter? Let’s try this:

[1 2 3 4] each puts

That’s better, now the ‘it’ becomes implicit too. Even if we removed some formatting, I think anyone with a programming background can understand what’s happening here and what the output will be.

For those of you interested in this syntax: the last version is valid Raven code.

Jul
18th
Fri
permalink
Jul
3rd
Thu
permalink
Jul
1st
Tue
permalink
Reverse Polish notation is the simplest way to describe arithmetic expressions. That’s how you learn arithmetic in grade school, before advancing to infix notation with Algebra. I’ve always favored simplicity in the interest of getting the job done.
Jun
12th
Thu
permalink