Money is the Root of all ..

Posted by Rick DeNatale Wed, 06 Jun 2007 03:16:00 GMT

$. Or at least implicit $

Just seen on ruby-talk:

|If we call gets(), the returned string is copied to a special variable $_
|Do we have such things for getc(), too?
No, implicit global variables are evil. I’d rather remove $_ in the future.

matz.

Maybe the reason that Matz picked $ as the sigil for global variables wasn’t to follow perl!

And this just after we learn that “Fahrenheit-451” was about the dangers not of government censorship but of TV.”

Posted in ,  | Tags  | no comments

Closing in on Closures and Jumping into Continuations

Posted by Rick DeNatale Wed, 06 Jun 2007 01:41:00 GMT

Recently on ruby-talk someone asked if continuations and closures were the same thing.

They are related in that they both are tied to a particular point in time in the execution of a program. The difference is that closures are like a souvenir of a trip, while continuations are like a kind of time-machine. Read more...

Posted in ,  | Tags ,  | no comments

Ruby Extensions vs. Smalltalk Primitives

Posted by Rick DeNatale Mon, 04 Jun 2007 14:16:00 GMT

One of the ways in which Ruby differs from Smalltalk is in how much of the implementation is buried in C, which forms a barrier for deep understanding.

For the purposes of this article, I’m going to use the term extension a little loosely to refer to both core library and extension code written in C.

For example, in Ruby, much of the code which implements core classes like Array, is implemented by C code. This is good for performance, but for those with a need or desire to grok the code, not so much. In contrast, Smalltalk has a large brigade of Collection classes which are written in Smalltalk.

This is not to say that Smalltalk doesn’t use the equivalent of extensions. Smalltalk calls them primitives.

There are some interesting differences which might be interesting for the Ruby Core team to ponder, if they haven’t already.

Read more...

Posted in ,  | Tags , , ,  | 3 comments

Chain, Chain, Chain

Posted by Rick DeNatale Sat, 02 Jun 2007 22:28:00 GMT

I’ve noticed some confusion lately on the part of some newcomers to Ruby about how methods are found at runtime, and in particular, the relationship between instance and class methods.

A week or so ago, someone posted some questions on ruby-talk about this issue, and then today I ran across this blog review of David Black’s “Ruby for Rails” which contained this:

On every method call, Ruby will search its object space in the following order:
  1. Current instance, followed by class methods
  2. Mixed in methods
  3. Superclass instance (repeat 1)
  4. Object methods, followed by Kernel mixin

I often get confused with mixin, class, and instance method precedence, so this is a useful model to revisit and keep in mind.

I don’t know where that reference to class methods in item 1 came from. I don’t think David said that in his book.

Here’s how it really works

Here in the form of answers to the questions posed on ruby-talk last week is my explanation of how Ruby finds methods when a message is sent to an object

Read more...

Posted in ,  | Tags , ,  | 1 comment

Our Kind of Ducks, Odd Ducks, and Trained Ducks

Posted by Rick DeNatale Mon, 30 Apr 2007 20:01:00 GMT

A couple of days ago, someone asked on ruby-talk how to implement a cyclic version of Enumerable#each_cons. In words, he was looking for a method:

class Array
   def each_cycle(size, start=0)
      #insert implementation here
   end
end

# So that this:
%{a b c d e}.each_cycle(2) {|cyc| p cyc}

#would print:
["a", "b"]
["b", "c"]
["c", "d"]
["d", "e"]
["e", "a"]

As usual, several helpful rubyists responded with suggestions, one of which leads me to YADTBE (Yet Another Duck Typing Blog Entry)

Read more...

Posted in  | Tags ,  | 3 comments

Hungarian Ducks

Posted by Rick DeNatale Mon, 09 Apr 2007 21:07:00 GMT

It’s interesting how events flow sometimes.

One of my major interests outside of software development is human spaceflight. Today I opened the local paper to the coming events section and discovered that the latest ‘rich cosmonaut’ to buy a trip up to the international space station, was arriving there today, and that his name was Charles Simonyi. As I’m writing this, he has just become the first Hungarian in space, or at least that’s what I heard him say over NASA TV.

Update: Actually that honor went to Bertalan Farkas who flew on Soyuz 36 in May of 1980.

Now that’s a familiar name. So I spent a little time this morning looking at his article on Wikipedia, and following some links. Thereby hangs an interesting tale which relates to duck-typing.

Read more...

Posted in  | Tags ,  | 2 comments

Power, Responsibility and Tricksy VM Implementers

Posted by Rick DeNatale Thu, 15 Mar 2007 12:05:00 GMT

In a ruby-talk discussion of the pleasures and perils of adding to or changing core ruby classes. A practice denigrated as “monkey patching” by some, but embraced as a powerful technique, when practiced with care, by others. Someone just reported an experiment involving changing a basic core method:
 Fixnum.class_eval do
   def +(number)
     self - number
   end
 end

The result: It blew up his irb.

Ruby certainly gives a lot of power. A little, and in some cases a lot, more than most popular OO languages. Read on..

Read more...

Posted in ,  | Tags , ,  | 1 comment

Are you aiming at the right bug?

Posted by Rick DeNatale Mon, 12 Mar 2007 16:26:00 GMT

How many times has this happened to you?

You have a really tough bug which defies all attacks. Finally after pondering it for hours, or days or maybe more, you realize that the symptoms you are seeing aren’t due to the posited bug at all, but are really something else.

Some examples.

On ruby-talk, I’ve been trying to help someone who was having problems making Net::SMTP work. He had some code which included:
smtp.open_message_stream('sender@mail.com', ["dummy@dummy.com"]) do
And which was working, except that he really wanted to send an email to an address held in a variable rather than “dummy@dummy.com” He was getting an error if he used ‘a’ variable for the recipient address, and wondered why the array couldn’t take a variable. Read more...

Posted in  | Tags ,  | no comments

Mum's the word (for IRB)

Posted by Rick DeNatale Mon, 12 Mar 2007 14:53:00 GMT

Ara T. Howard posted a nice little IRB hack to ruby-talk about 10 days ago.

I finally got around to incorporating it into my .irbrc file. Here’s my code:

module IRB
  def self.result_format
     conf[:PROMPT][conf[:PROMPT_MODE]][:RETURN]
  end

  def self.result_format=(str)
     result_format.replace(str)
  end

  def self.show_results
     self.result_format = "=> %s\n"
  end

  def self.hide_results
     self.result_format = ''
  end
end

Put this into your .irbc file and you can do this:

rick@frodo:~$ irb
irb(main):001:0> 1+2
=> 3
irb(main):002:0> IRB.result_format
=> "=> %s\n"
irb(main):003:0> IRB.hide_results
irb(main):004:0> 1+2
irb(main):005:0> IRB.show_results
=> "=> %s\n"
irb(main):006:0> 1+2
=> 3

Maybe there are some better names, but it seems to work.

Posted in  | Tags ,  | no comments

Whose Breakfast is it, Anyway?

Posted by Rick DeNatale Thu, 28 Dec 2006 13:12:00 GMT

I just ran across this article, via O’Reilly Ruby.

Ohloh is a web site which analyses open source projects by monitoring commits. The article is making a case that PHP is somehow better than Ruby (and Rails), is “eating Rails for breakfast,” because:

  1. About 18% of all new code added to open source projects in 2006, or at least those monitoried by Ohloh) is written in PHP, compared to something like 2% in Ruby. The trend is upward for both PHP and Ruby although PHP’s slope is steeper
  2. About 10% of open source developers contributed code in PHP, vs. Ruby contributors who accounted for about 2.5%. The trend here is downward for PHP. It peaked at around 14% in 2004. Python and Perl are slightly below PHP and are in decline as well. Ruby rose gradually in 2004 and has been level in this metric since then.
  3. 5% of open-source projects started in 2006 are being written in PHP. This is about the same as Python. Perl struggles here at about 1%. All three languages saw a decline in project starts since 2002, although PHP and Python have increased gradually over the past two years.

This last set of statistics is one hint that Ohtoh’s analysis might be slightly flawed. In contrast to PHP (and the others), 16% of new open source projects in 2006 are being written in Ruby, and the number has been growing since the start of their charts in 2001.

Which begs the question of whether these numbers really show that fewer developers are getting more done in Ruby with fewer lines of code than in PHP. If this is indeed the case, I’d say that it’s really PHP, not Ruby and Rails which is in the cereal bowl.

Lines of code has always been a lousy measure of code, and often it correlates negatively with quality. Ruby programmers pride themselves on keeping their code DRY, avoiding unnecessary duplication of code. I’ve always gotten great satisfaction working on refactoring phases of projects which resulted in a net reduction in the total number of lines of code.

In any event, such arguments are far from convincing. Despite the question of how the data has been gathered, processed, and interpreted, there’s the larger question of the validity of arguments based on populariey.

Posted in  | Tags  | no comments | no trackbacks

Older posts: 1 ... 3 4 5 6 7