Ruby, Now In English
PM4RK5 writes: "For those of you interested, the News & Observer had an interview with Andrew Hunt about Ruby, in response to a book he and David Thomas authored. The book, "The Pragmatic Programmer" was written for the old-fashioned programmers who seek to learn how to use newer technologies, and use them better. It has an example of code differences between Java and Ruby, on how to print 'Ho Ho Ho.' Contains information and thoughts on its current applications, how its growing, and the types of things that it is suited for."
wow, it's weird to see a local rag doing such an in-depth article on programming. well done, N&O. (even weirder that it's my local rag, but, hey..)
since i know all 6 people who read this article are going to skim it for exactly the same thing i did, here it is:
To print "Ho Ho Ho" in Java, you have to write code like this: 'for (int i=0; i 3; i++)
{System.err.print("Ho ");}.'
In Ruby you write:
'3.times do print "Ho " end.'
Indie rock lives! b-side!
10 cmpr_fag(fag1,fag2);
20 "YOU==FAGG0T!"
#!/usr/bin/perl -w
/\$Revision:\s+([^\s]+)/;
... [UIDs]
# This code is a part of Slash, and is released under the GPL.
# Copyright 1997-2001 by Open Source Development Network. See README
# and COPYING for more information, or see http://slashcode.com/.
# $Id: bitchslap,v 1.1.2.2 2001/06/05 11:51:44 pudge Exp $
use strict;
use File::Basename;
use FindBin '$Bin';
use Getopt::Std;
use Slash::Utility;
use Slash::DB;
(my $VERSION) = ' $Revision: 1.1.2.2 $ ' =~
my $PROGNAME = basename($0);
(my $PREFIX = $Bin) =~ s|/[^/]+/?$||;
my %opts;
# Remember to doublecheck these match usage()!
usage('Options used incorrectly') unless getopts('hvu:', \%opts);
usage() if ($opts{'h'} || !keys %opts);
usage('Please specify a list of User IDs') if (! scalar @ARGV);
version() if $opts{'v'};
$opts{'u'} ||= 'slash';
# We turn off warnings here because it's distracting.
$^W = 0; createEnvironment($opts{'u'}); $^W = 1;
my $slashdb = getCurrentDB();
my $constants = getCurrentStatic();
# main program logic (in braces to offset nicely)
{
for (@ARGV) {
my $user = $slashdb->getUser($_);
if (! $user) {
print "User ID#$_ is invalid.\n";
next;
}
unless ($opts{'f'}) {
die <<ERR if $user->{karma} > 10;
User $_ has a karma of $user->{karma}. Slap aborted. Use -f to forcibly slap.
ERR
}
print "Bitch Slapping #$_...\n";
print "Karma Reduced\n";
print "Default Score Reduced\n";
$slashdb->setUser($_, {
-karma => $constants->{badkarma},
-defaultpoints => -1,
});
print "ALL live comments moderated down\n\n";
$slashdb->sqlDo("UPDATE comments SET points=-1,reason=1 WHERE uid=$_");
}
}
sub usage {
print "*** $_[0]\n" if $_[0];
# Remember to doublecheck these match getopts()!
print <<EOT;
Usage: $PROGNAME [OPTIONS]
SHORT PROGRAM DESCRIPTION
Main options:
-h Help (this message)
-v Version
-u Virtual user (default is "slash")
-f Force slap.
[UIDs] Space separated list of IDs to slap.
EOT
exit;
}
sub version {
print <<EOT;
$PROGNAME $VERSION
This code is a part of Slash, and is released under the GPL.
Copyright 1997-2001 by Open Source Development Network. See README
and COPYING for more information, or see http://slashcode.com/.
EOT
exit;
}
__END__
8th Post :-D
More interesting might be slides from last month's Ruby conference as well as a nice writeup with pictures. Wish I could've been there!
The newspaper article contains the Java/Ruby example. The book Pragmatic Programmer was written before they got involved in Ruby, and has no Ruby. To muddy the waters even more, their Ruby book is subtitled The Pragmatic Programmer's Guide, but it doesn't have Java comparisons. Someone will have to write a "Ruby for Java Programmers" book.
Judging from the code in the article, one of the things that would appear to hinder Ruby is its lack of closeness to other languages. Perl, Java, etc have at their heart, C. You can see this in the bracing uses, control structures, etc.
In the end, this may not be a "bad thing" for Ruby....
:q!