Drifting further off topic, but oh well...

On 7/17/06, Charles O Nutter <[EMAIL PROTECTED]> wrote:

The other half of this is that named parameters *may* increase readability, but I don't think that's the real purpose. 99% of the method calls I make are passed mostly variable names. How could fetchResults(query, criteria) be made more readable? Only when callers pass a lot of literals do named parameters have an impact on readability.

Perhaps using literals would be facilitated more often with named params.  I could return to the hated "boolean" method parameter:

foo(1, true)  vs. foo(loopCount:1, eatExceptions: true)

From what I can gather (though it's still a bit unclear) Ruby 2.0 will also require you to explicitly declare named parameters (aka keyword arguments). matz made a number of proposals last year, but I've been unable to find whether there's been any final decision. Many disliked what he proposed, and some of the options may be needlessly complicated. The simplest follows; the others were just more complicated mixings of named and unnamed params.

def foo(a:, b:2)
..
end

foo(a:3, b:4) # a = 3, b = 4
foo(b:4, a:3) # a = 3, b = 4
foo(a:3) # ok, b defaults to 2
foo() # error, a has no default value
foo(1, 2) # error, no positional arguments
foo(b:4) # ditto
foo(c:5) # error, no parameter c

I've seen a couple of those threads on ruby-talk, and my own conclusion is the proposals don't really buy you much more than the current practice of using literal hashes with symbol keys.

foo(a:3, b:4) vs foo(:a => 3, :b => 4)

In Java-land, there is no inline/literal map syntax, so it's a lot more painful to try such a technique there.  Named parameter naming conventions would differ no more widely than method and class names today.

/Nick
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Jruby-devel mailing list
Jruby-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jruby-devel

Reply via email to