Ruby T-Shirt Idea

What we need is a code snippet that is excessively long and obfuscate in
Perl, such as a single line of code which has to wrap around the t-shirt to
be completed (with all the @ and $ symbols, etc.), and then do the same in
Ruby underneath… which only takes a fraction of the width of the front
side of the shirt.

···

MSN 8 with e-mail virus protection service: 2 months FREE*
http://join.msn.com/?page=features/virus

IMHO it will be almost impossible to do that, being fair and idiomatic
with the Perl version, writing readable Perl, and getting that ratio at
the same time.

Though I would be glad if I was proved wrong :-).

– fxn

···

On Thursday 10 July 2003 22:32, Orion Hunter wrote:

What we need is a code snippet that is excessively long and obfuscate
in Perl, such as a single line of code which has to wrap around the
t-shirt to be completed (with all the @ and $ symbols, etc.), and
then do the same in Ruby underneath… which only takes a fraction of
the width of the front side of the shirt.

For logical neatness I just love

class Integer
def fib
return (self-1).fib + (self-2).fib if self > 2
1
end
end

(1…20).each {|i| puts i.fib}

John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : john.carter@tait.co.nz
New Zealand

A Million Monkeys can inflict worse things than just Shakespeare on
your system.

···

On Fri, 11 Jul 2003, Orion Hunter wrote:

What we need is a code snippet that is excessively long and obfuscate in
Perl,

Saluton!

  • Orion Hunter; 2003-07-10, 23:39 UTC:

What we need is a code snippet that is excessively long and obfuscate in

Stupid question: What’s the difference between a snipplet and a
snippet?

Gis,

Josef ‘Jupp’ Schugt

···


N’attribuez jamais à la malice ce que l’incompétence explique !
– Napoléon

I have little knowledge of Perl.

Suppose you wanted to iterate through an array and
print out the odd-numbered elements:

array.each_with_index {|x,i| puts x if i % 2 == 1 }

How would that look in Perl?

Hal

···

----- Original Message -----
From: “Xavier Noria” fxn@hashref.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Thursday, July 10, 2003 4:35 PM
Subject: Re: Ruby T-Shirt Idea

On Thursday 10 July 2003 22:32, Orion Hunter wrote:

What we need is a code snippet that is excessively long and obfuscate
in Perl, such as a single line of code which has to wrap around the
t-shirt to be completed (with all the @ and $ symbols, etc.), and
then do the same in Ruby underneath… which only takes a fraction of
the width of the front side of the shirt.

IMHO it will be almost impossible to do that, being fair and idiomatic
with the Perl version, writing readable Perl, and getting that ratio at
the same time.

Though I would be glad if I was proved wrong :-).


Hal Fulton
hal9000@hypermetrics.com

Something OO? With all the blessing and stuff, Perl is quite ugly, esp.
when compared to the neatness of Ruby…

···

On Fri, Jul 11, 2003 at 06:35:27AM +0900, Xavier Noria wrote:

On Thursday 10 July 2003 22:32, Orion Hunter wrote:

What we need is a code snippet that is excessively long and obfuscate
in Perl, such as a single line of code which has to wrap around the
t-shirt to be completed (with all the @ and $ symbols, etc.), and
then do the same in Ruby underneath… which only takes a fraction of
the width of the front side of the shirt.

IMHO it will be almost impossible to do that, being fair and idiomatic
with the Perl version, writing readable Perl, and getting that ratio at
the same time.

Though I would be glad if I was proved wrong :-).


_ _

__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Linux: because a PC is a terrible thing to waste
– ksh@cis.ufl.edu put this on Tshirts in '93

Saluton!

  • John Carter; 2003-07-10, 23:44 UTC:

For logical neatness I just love

class Integer
def fib
return (self-1).fib + (self-2).fib if self > 2
1
end
end

(1…20).each {|i| puts i.fib}

Fast imperative computation of fibonacci numbers:

fib1, fib2 = 0, 1
(0…100).each {|i|
puts “#{i}: #{fib2}”
fib1, fib2 = fib2, fib1 + fib2
}

Gis,

Josef ‘Jupp’ Schugt

···


N’attribuez jamais à la malice ce que l’incompétence explique !
– Napoléon

That’s a good intent because Perl lacks an explicit construct to iterate
with both the index and the element, and does not come with a puts()
in addition.

For instance we could write

$_ % 2 and print "$array[$_]\n" foreach 0..$#array;

If one considers it’s bad style to use boolean operators to control flow
that way, we could write instead

print "$array[$_]\n" foreach grep $_ % 2, 0..$#array;

or plain

foreach (0..$#array) { 
    print "$array[$_]\n" if $_ % 2;
}

Note that I have not used “for”, which is wholly interchangeable with
“foreach”, to shorten the snippets. I prefer to write foreach when I
mean foreach.

I woldn’t be proud wearing a T-shirt that compared Ruby to any other
language that way. Both Ruby and Perl have their place, I love both.

– fxn

···

On Thursday 10 July 2003 23:42, Hal E. Fulton wrote:

Suppose you wanted to iterate through an array and
print out the odd-numbered elements:

array.each_with_index {|x,i| puts x if i % 2 == 1 }

How would that look in Perl?

“Hal E. Fulton” hal9000@hypermetrics.com writes:

I have little knowledge of Perl.

Suppose you wanted to iterate through an array and
print out the odd-numbered elements:

array.each_with_index {|x,i| puts x if i % 2 == 1 }

How would that look in Perl?

You’re actually printing the indices of the elements which are odd.
If you want to do that in Perl:

$i=0; foreach (@array) { print “$i\n” if $_ % 2; $i++; }

or

for($i=0; $i<=@array; $i++) {
print “$array[$i]\n” if $array[i] % 2;
}

If you want to print out the odd-numbered elements themselves:

foreach (@array) { print "$\n" if $ %2; }

-=Eric

···


Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
– Blair Houghton.

Mauricio Fernández graced us by uttering:

Xavier Noria wrote:

Orion Hunter wrote:

What we need is a code snippet that is excessively long and
obfuscate in Perl, such as a single line of code which has
to wrap around the t-shirt to be completed (with all the @
and $ symbols, etc.), and then do the same in Ruby
underneath… which only takes a fraction of the width of
the front side of the shirt.

IMHO it will be almost impossible to do that, being fair and
idiomatic with the Perl version, writing readable Perl, and
getting that ratio at the same time.

Though I would be glad if I was proved wrong :-).

Something OO? With all the blessing and stuff, Perl is quite
ugly, esp. when compared to the neatness of Ruby…

Non-OO, idiomatic Perl can almost always beat ruby by at least a
few characters. OO Perl automatically doubles the length (and
execution time) of a program.

IMHO, whatever snippet chosen should make effective use of
iterators, as this is probably the feature that makes Ruby the
most unique among its contemporary counterparts.

Cheers,
Tim Hammerquist

···


Ford, you’re turning into a penguin. Stop it.
– Arthur Dent, “The Hitchhiker’s Guide to the Galaxy”

Oh, oh, oh, oh… I just remembered a good one:

def twice
yield
yield
end
twice { puts “Ruby rocks!” }


Daniel Carrera | OpenPGP fingerprint:
Graduate TA, Math Dept | 6643 8C8B 3522 66CB D16C D779 2FDD 7DAC 9AF7 7A88
UMD (301) 405-5137 | http://www.math.umd.edu/~dcarrera/pgp.html

“Hal E. Fulton” hal9000@hypermetrics.com writes:

I have little knowledge of Perl.

Suppose you wanted to iterate through an array and
print out the odd-numbered elements:

array.each_with_index {|x,i| puts x if i % 2 == 1 }

How would that look in Perl?

You’re actually printing the indices of the elements which are odd.

:slight_smile: No… I’m printing the elements that have odd indices, which
is what I meant.

If I printed the indices of the elements which were odd, that
would be

array.each_with_index {|x,i| puts i if x % 2 == 1 }

If you want to do that in Perl:

$i=0; foreach (@array) { print “$i\n” if $_ % 2; $i++; }

If you want to print out the odd-numbered elements themselves:

foreach (@array) { print "$\n" if $ %2; }

When I said the odd-NUMBERED elements, I meant the elements which
are NUMBERED (indexed) by odd numbers – not that the elements
themselves should be odd. In fact, I was thinking that the
elements were strings, though I didn’t say that. Ahh, dynamic typing…

Thanks for the Perl lesson… I can always use one.

Though I’m really thinking of looking at Python instead…

Cheers,
Hal

···

----- Original Message -----
From: “Eric Schwartz” emschwar@pobox.com
Newsgroups: comp.lang.ruby
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Thursday, July 10, 2003 5:22 PM
Subject: Re: Ruby T-Shirt Idea

Eric Schwartz graced us by uttering:

If you want to print out the odd-numbered elements themselves:

foreach (@array) { print "$\n" if $ %2; }

As usual, one can trim some gratuitous readable characters here
and there:

$_ % 2 and print "$_\n" for @array;

or even (and this is cheap):

$_%2&&print "$_\n" for @array;

How’s that for Ruby advocacy? :slight_smile:

Tim Hammerquist

···


One should always be in love. That is the reason one should never marry.
– Oscar Wilde

what about this on in the front …

···

make your life easy …

lrwxr-xr-x 1 root 1 Jan 2003 java →
/usr/bin/ruby
lrwxr-xr-x 1 root 1 Jan 2003 perl → /usr/bin/ruby
lwxr-xr-x 1 root 1 Jan 2003 php → /usr/bin/ruby
lrwxr-xr-x 1 root 1 Jan 2003 python → /usr/bin/ruby

lrwxr-xr-x 1 root 1 Jan 2003 sh → /usr/bin/irb
lrwxr-xr-x 1 root 1 Jan 2003 tcl → /usr/bin/ruby


-ronnie

Tim Hammerquist wrote:

Mauricio Fernández graced us by uttering:

Xavier Noria wrote:

Orion Hunter wrote:

What we need is a code snippet that is excessively long and
obfuscate in Perl, such as a single line of code which has
to wrap around the t-shirt to be completed (with all the @
and $ symbols, etc.), and then do the same in Ruby
underneath… which only takes a fraction of the width of
the front side of the shirt.

IMHO it will be almost impossible to do that, being fair and
idiomatic with the Perl version, writing readable Perl, and
getting that ratio at the same time.

Though I would be glad if I was proved wrong :-).

Something OO? With all the blessing and stuff, Perl is quite
ugly, esp. when compared to the neatness of Ruby…

Non-OO, idiomatic Perl can almost always beat ruby by at least a
few characters. OO Perl automatically doubles the length (and
execution time) of a program.

IMHO, whatever snippet chosen should make effective use of
iterators, as this is probably the feature that makes Ruby the
most unique among its contemporary counterparts.

Cheers,
Tim Hammerquist

mailto:rodrigo.bermejo@ps.ge.com

Did nobody spot the off-by-one error there? @array as a scalar gives the
number of elements in the array, not the index of the last element.

As good an argument for using iterators as I’ve ever seen…

Regards,

Brian.

···

On Fri, Jul 11, 2003 at 07:22:00AM +0900, Eric Schwartz wrote:

for($i=0; $i<=@array; $i++) {
print “$array[$i]\n” if $array[i] % 2;
}

sub twice(&) {
my $sub = shift;
&$sub;
&$sub;
}
twice { print “Ruby rocks!\n” }

– fxn

···

On Friday 11 July 2003 00:22, Daniel Carrera wrote:

def twice
yield
yield
end
twice { puts “Ruby rocks!” }

That’s pretty funny.

I already said I don’t like language wars…
but I once of thought of this one:

mv /usr/bin/perl /has/bin

Cheers,
Hal

···

----- Original Message -----
From: “Bermejo, Rodrigo” rodrigo.bermejo@ps.ge.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Thursday, July 10, 2003 6:27 PM
Subject: Re: Ruby T-Shirt Idea

what about this on in the front …

make your life easy …

lrwxr-xr-x 1 root 1 Jan 2003 java →
/usr/bin/ruby
lrwxr-xr-x 1 root 1 Jan 2003 perl → /usr/bin/ruby
lwxr-xr-x 1 root 1 Jan 2003 php → /usr/bin/ruby
lrwxr-xr-x 1 root 1 Jan 2003 python → /usr/bin/ruby

lrwxr-xr-x 1 root 1 Jan 2003 sh → /usr/bin/irb
lrwxr-xr-x 1 root 1 Jan 2003 tcl → /usr/bin/ruby


Bermejo, Rodrigo graced us by uttering:

what about this on in the front …

make your life easy …

lrwxr-xr-x 1 root 1 Jan 2003 java → /usr/bin/ruby
lrwxr-xr-x 1 root 1 Jan 2003 perl → /usr/bin/ruby
lrwxr-xr-x 1 root 1 Jan 2003 php → /usr/bin/ruby
lrwxr-xr-x 1 root 1 Jan 2003 python → /usr/bin/ruby
lrwxr-xr-x 1 root 1 Jan 2003 sh → /usr/bin/irb
lrwxr-xr-x 1 root 1 Jan 2003 tcl → /usr/bin/ruby


Reminds me of an answer posted on the vim mailing list:

: > …any ideas on how to make vim behave like the ‘tail’ command in unix?
: >
:
: On my system “cp /usr/bin/tail /usr/local/bin/vim” does the trick,
: though Vi compatibility is subsequently somewhat impaired.

(matthew winn in vim@vim.org ml)

Cheers,
Tim Hammerquist

···


Your GP or your HP!
– Thief, 8-bit Theatre http://nuklearpower.com/

Or my own version of phpnuke:

#!/bin/sh
exec rm -rf /usr/lib/php*

:slight_smile:

···

On Fri, Jul 11, 2003 at 08:27:40AM +0900, Bermejo, Rodrigo wrote:

what about this on in the front …

make your life easy …

lrwxr-xr-x 1 root 1 Jan 2003 java →
/usr/bin/ruby
lrwxr-xr-x 1 root 1 Jan 2003 perl → /usr/bin/ruby
lwxr-xr-x 1 root 1 Jan 2003 php → /usr/bin/ruby
lrwxr-xr-x 1 root 1 Jan 2003 python → /usr/bin/ruby

lrwxr-xr-x 1 root 1 Jan 2003 sh → /usr/bin/irb
lrwxr-xr-x 1 root 1 Jan 2003 tcl → /usr/bin/ruby


Saluton!

  • Bermejo, Rodrigo; 2003-07-10, 23:46 UTC:

what about this on in the front …

make your life easy …

lrwxr-xr-x 1 root 1 Jan 2003 java →
/usr/bin/ruby
lrwxr-xr-x 1 root 1 Jan 2003 perl → /usr/bin/ruby
lwxr-xr-x 1 root 1 Jan 2003 php → /usr/bin/ruby
lrwxr-xr-x 1 root 1 Jan 2003 python → /usr/bin/ruby

lrwxr-xr-x 1 root 1 Jan 2003 sh → /usr/bin/irb
lrwxr-xr-x 1 root 1 Jan 2003 tcl → /usr/bin/ruby


The topic was ‘T-shirt’, not ‘tent’.

Java is a compiler language.

Gis,

Josef ‘Jupp’ Schugt

···


N’attribuez jamais à la malice ce que l’incompétence explique !
– Napoléon