[#3986] Re: Principle of least effort -- another Ruby virtue. — Andrew Hunt <andy@...>

> Principle of Least Effort.

14 messages 2000/07/14

[#4043] What are you using Ruby for? — Dave Thomas <Dave@...>

16 messages 2000/07/16

[#4139] Facilitating Ruby self-propagation with the rig-it autopolymorph application. — Conrad Schneiker <schneik@...>

Hi,

11 messages 2000/07/20

[ruby-talk:04089] Re: What are you using Ruby for?

From: Johann Hibschman <johann@...>
Date: 2000-07-17 16:58:31 UTC
List: ruby-talk #4089
Aleksi Niemel writes:

> Johann:

>> The fact that functions are not first class in Ruby still bothers me,
>> so I haven't experimented with it that much.

> That bothered me too, but now it seems to me that one wants to use
> functions only when one's hacking up some code - and Ruby is on it's
> best when you're really OO. So I thought really hard if there is
> some need for "function objects". And it seemed that there really
> is. I was hacking up a test where I wanted to plug-in functionality.

This is one thing that I never quite understood about the "pure
object-oriented languages"---they seem to dislike functions.
Functions are very real things, quite useful in fact, but their a pain
to manipulate, at least in Eiffel and Sather.

As an example of what I do in python, I have a program which
implements several functions over a dataset, then lets the user pick
which functions to plot from the command line.  There are also
multiple forms of each function, which are (in general) variable
transformations.

The code looks like:

def make_g_from_f(f):
  def temp(x, y, f=f):     # ugly python lack of closures
    return f(x, y)*scale(x, y)
  return temp

def f1(x, y):
  return <something>
register_function("f1", f1, "Compute something")

g1 = make_g_from_f(f1)     # useful python 1st-class functions
register_function("g1", g1, "Compute something scaled by scale")

...
where register_function enters the function into the table that the
dispatch code uses.

As I understand Ruby, I would have to make all of these functions into
global Proc objects and use $-names to reference them, if I want f1
and g1 to be callable using the same conventions.  That seems like it
would get very ugly very fast.

Is this a correct impression?

--J

-- 
Johann Hibschman                           johann@physics.berkeley.edu

In This Thread