Glen Starchman <[EMAIL PROTECTED]>
> I am working on my language again after a long haitus and have a
> question for the group in regards to readability of my iterator
> functionality. Currently, I am looking at 3 different forms:
> 
> 1. "hello".each() 
>       { |x|
>               print (x)
>       }
> 2. "hello".each()
>       begin
>               print (x)
>       end
> 3. "hello".each()
>       |x|
>               print(x)
>       end
> 
> I am rather fond of number 3, but am uncertain as to which is the
> most readable for maintainers and intuitive for the developer.

Hmm.  Option 2 is definitely not a good idea (magic names tend to
cause trouble in my experience) and option 1 has the problem of
looking like the "|x|" is a command in the body (it looks to me like a
mathematical modulus operator too, which doesn't help me!)  But option
3 isn't balancing "begin" and "end" which is not brilliant either.
What about this (I'm a Tcler, I keep braces on the same line :^)

  "hello".each(x) {
      print(x)
  }

Problem with this is probably that the first x looks like an argument
to each(); I suppose it is, but not in quite the normal sense in that
it is a sort-of output-argument.  If you have local function closures
you should probably use those, especially if they are introspectable
in the number of arguments[*].  OTOH, I don't know enough about the
syntax of your language to know how well that'd work (Java does this
sort of thing, except with classes not functions, and it produces code
that doesn't win awards for extreme syntactic elegance.)  :^/

If you like 3, go for that.  Your tastes are as good a metric here as
any other I can think of, and better than many.

Donal.
[* Just one value at a time from the iteratable entity?  Nah.  But then
   I'd go for iterating over more than one iteratable object at a time too. ]
-- 
Donal K. Fellows, Department of Computer Science, University of Manchester, UK.
(work) [EMAIL PROTECTED]     Tel: +44-161-275-6137  (preferred email addr.)
(home) [EMAIL PROTECTED]  Tel: +44-1274-401017   Mobile: +44-7957-298955
http://www.cs.man.ac.uk/~fellowsd/  (Don't quote my .sig; I've seen it before!)

Reply via email to