23rd - 29th May 2005
Ruby Weekly News is a summary of the week’s activity on the ruby-talk mailing list / the comp.lang.ruby newsgroup, brought to you by Tim Sutherland.
Articles and Announcements
- Rails Day Registration is Now Open!
- 2005 ICFP Programming Contest
- Rail Beta Book now available
Lucas Carlson announced “If you want your chance at thousands of dollars of prizes for one day’s work with Rails, please register soon”.
Rails Day is a competition that gives you 24 hours to write the best web application you can, using Ruby on Rails. You can do it individually or as part of a two or three person group.
It’s all on June 4th (hurry!)
Judges include Rails creator David Heinemeier Hansson and the co-author of ‘The Pragmatic Programmer’ and ‘Programming Ruby’, Dave Thomas.
Robby Findler announced that the 2005 Programming Contest of the International Conference on Functional Programming was just four weeks away.
“This year’s competition rewards programmers who can plan ahead. As before, we’ll announce a problem and give you three days to solve it. Two weeks later, we’ll announce a change to the problem specification and give you one day to adapt your program to the new spec. And you guessed it: the second half will be worth considerably more than the first.”
Dave Thomas released the beta version of the Rails book he is co-writing; ‘Agile Web Development with Rails’.
“This is basically a pre-copyedit, pre-layout version of the book, available as a PDF. Buy it now (either as a straight PDF or as a combo-pack with the paper book) and we’ll ship you the Beta PDF now, then ship you the final PDF (along with the paper book if you ordered it) when the book is finished (around the first of August).”
Quote of the Week
Matz explaining POLS (Principle of Least Surprise).
This acronym was often in the past used by Rubyists to cheerfully declare that language design decisions were resolved simply by determining which option was the ‘least surprising’.
POLS has since become notorious for generating long, futile threads where someone with a background in one language argues that a feature should behave in a certain way (since that’s the way the other language does it, that is the ‘least surprising’ way to them). Of course, someone with a different background would then say ‘actually, I think the following would be the least surprising’, and the thread spirals onwards.
The quote itself:Since someone will surprise for any arbitrary choice, it is impossible to satisfy “least surprise” in his sense. The truth is two folds: a) when there are two or more choices in the language design decision, I take the one that makes _me_ surprise least. b) as a result, you will have less surprise in Ruby than other languages, once you have accustomed to it.
But I’m tired of explaining POLS again and again. I haven’t even used it first. I hope no one will use the term “POLS” any more to sell Ruby. It’s free after all.
Matz’ comment was inspired by the thread A different perspective on Ruby which comments on a rant by Eric Will. (Warning: Rant contains a lot of swearing.)
The rant listed a number of things that Eric didn’t find ‘least surprising’ - “So much for POLS … So much for POLS … So much for POLS.”
How about Language Agreeing with Matz’ Expectations? Then people can complain that that Ruby isn’t LAME :-)
Link of the Week
Link of the Week: Anarchaia by Christian Neukirchen.
A blog, sort of. (But mostly not.) It’s an intermingling cascadra of links, quotes, images and thoughts all racing down the page (and down, down, down – it’s very long, you see.)
The #ruby-lang IRC channel is regularly quoted, as are other interesting-to-programmer places. It’s freaking crazy awesome, man.
Rubyists may know Christian from his Ruby projects - the RubyPants smart-quotes library, a Real Life Markup Language (RLML) parsing library, the Nukumi static blogging system (and now Nukumi2) and a “cool application launch bar” called slider.
(Please send in your suggestions for the next Link of the Week.)
Threads
Useless hack of the saturday morning
gabriele renzi found a “nifty” piece of Perl code.
He translated it into Ruby, the magic part of which was
implementing the gather and take
functions of Perl 6.
gather-take is used to construct an array in the following
way; gather takes a block and returns an array. Within
the block, every time take is called it adds its argument to
the array.
Example:
p gather {
take 1
take 2
take 3
}
# -> [1, 2, 3]
The above is equivalent to
arr = []
arr << 1
arr << 2
arr << 3
p arr
# -> [1, 2, 3]
The difference is that the first example doesn’t need to explicitly declare the array.
gabriele’s implementation:
class Gatherer
attr :gathered
def take(arg)
@gathered||=[]
@gathered<< arg
end
end
def gather &blk
c=Gatherer.new
c.instance_eval &blk
c.gathered
end
Pay close attention to how he calls instance_eval on a block.
That causes the block to be evaluated such that
self inside the block is c, rather than the
self from the lexical scope of the block definition.
The result is that when the code inside the block calls take,
it is c.take that is called.
Christian Neukirchen (familiar name)
thought it looked useful, but was concerned about
unintended effects of the instance_eval.
(It all goes horribly wrong, for example, if your block refers to
instance variables or methods.)
He suggested using Dynamic Variables instead.
Chris also noted thatgather-take is available in the
GOO programming language, where it is known by
packing-pack.
preventing Object#send from dispatching to a global method?
Francis Hwang outlined the following snippet of code -
def something; end
class SomeClass
def method_missing( sym, *args ) .... do magic; end
end
and asked if it is possible to make SomeClass.new.something call
SomeClass#method_missing instead of the ‘global method’
something. (Such methods are added to Object,
and are therefore available to all objects by default.)
Bertram Scharpf gave:
class SomeClass
undef :something
end
Jim Weirich suggested Francis look at the code in Builder::BlankSlate
(part of the Builder for Markup library).
It provides a class whose only methods are __send__ and __id__.
It also uses undef.
main object, rather than additions to the
Object class.
a deepcopy for "array = [1,2,3]*5"?
Boris asked “What way would you create an array that contains 5 copies of an array, without the copies interfering with each other?”
He had tried
array = [[1,2,3]]*5
# -> [[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3]]
However the result is 5 references to the same array:
array[1][1] = "a"
# -> [[1,"a",3],[1,"a",3],[1,"a",3],[1,"a",3],[1,"a",3]]
Brian Schröder said he should simply use
array = Array.new(5) { [1, 2, 3] }
That creates an Array of 5 values. They are initialised by calling
the block 5 times, which results in 5 different array objects.
Making a scripting tutorial
Vincent Foley would like to present Ruby to the Linux Users Group he attends, in Quebec. The audience is mostly system administrators rather than programmers, so it would be best to demonstrate Ruby’s utility as a ‘scripting language’.
What sort of material could he cover in an introduction? James Britt thought that Vincent shouldn’t try to go over too much. Instead, “show enough about scripting in general, very high-level, and some Ruby in particular, so as to generate interest in further exploration.”
Henrik Horneber gave a link to whytheluckystiff’s article Wearing Ruby Slippers To Work which shows Ruby code performing the same sort of tasks that sysadmins often usefind, grep and friends for.
Others posted links to tutorials and to presentations that have previously been used.
UDPSocket#recvfrom is slow
Niklas Frykholm found that theUDPSocket#recvfrom
method was “extremely slow” (two seconds per call), whereas
UDPSocket#recv was super fast.
He guessed that the difference was that recvfrom attempts to
convert an IP address to a network name.
“Apparently, on a
(badly configured???) Windows network, this can be a really slow operation.”
Socket.do_not_reverse_lookup = true
to disable the conversion. Niklas confirmed that this solved his problem.
New Releases
Finite State Ma-thing 0.6
Gavin Kistner announced the ‘Finite State Ma-thing’, a library that assists in the implementation of finite state machines.
HighLine 0.6.1
James Edward Gray II released HighLine 0.6.1. This resolves an installation issue for Windows users.
HighLine is a library that makes it easy to write console applications. It provides high level services for such things as asking questions of the user and receiving answers.
ZenHacks 1.0.0
Ryan Davis announced ZenHacks 1.0.0.
“A cornucopia of hackery. Toys, Tricks and Tools that have spawned out of my other projects (RubyInline, ParseTree, Ruby2C, etc) but don’t exactly fit there. This includes ZenDebugger, ZenProfiler, ZenOptimizer, ruby2ruby, and more.”
Packgen 0.2
Ghislain Mary released Packgen 0.2, a network packet generator. It can be used to analyse the performance of your network.
This release includes the ability to generate graphs containing information such as “bandwidth, the packet size, the packet count, the packet loss, the interarrival and the jitter of your packet flows.”
cursor-0.6
Eric Mahurin enhanced cursor, a library that provides powerful external iterator features based on the ‘cursor’ editor metaphor.
“Compared to most other general external iterators, Cursor offers two interesting features – ability to insert/delete and the ability to save/restore a position.”
Some interfaces were simplified and more methods added.
The thread discussed the general approach, with Eric noting that he’s working on a library called Grammar, “used to match what’s next in Cursor”.