The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
If Python can do it...

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Daniel Berger

Posts: 1383
Nickname: djberg96
Registered: Sep, 2004

Daniel Berger is a Ruby Programmer who also dabbles in C and Perl
If Python can do it... Posted: Oct 22, 2005 10:08 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Daniel Berger.
Original Post: If Python can do it...
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Daniel Berger
Latest Posts From Testing 1,2,3...

Advertisement
I've been trying to find another language that does implicit keyword arguments to help assuage the fears some folks have with regards to "mixing interface and implementation". At first, the only one I could think of was Oracle PL/SQL - not exactly the poster child for languages you want to cite when defending your ideas.

Last night, however, Evan mentioned that Python does implicit keyword arguments. Since 1.3, actually. I never knew! Here's a quick example:
def foo(a, b, c):
   ...

foo(1, 2, 3)              # a = 1, b = 2, c = 3
foo(a = 1, c = 2, b = 3)  # a = 1, b = 3, c = 2
foo(1, c = 3, b = 4)      # a = 1, b = 4, c = 3


Note that, like our current proposal, you can mix positional and named parameters. In fact, the rules we came up with for Sydney are identical to the current rules for Python as far as I can tell. But what about *args and **keys? The Python implementation is similar to Matz's proposal:
def foo(a, *rest, **keys):
   ...

foo(1, foo = "hello", bar = "world")

# rest = [1, "hello", "world"]
# keys = {"foo" : "hello", "bar" : "world"}

Now that I'ved spent some time looking at this, and having reviewed Matz's proposal again, I think one of the major items I disliked was the fact that *args was the first argument, while **keys was last. It just doesn't look right, and I still like the (recently suggested) idea of an Arguments class that handles **keys implicitly. But, that still doesn't deal with the issue of explicit declarations or delegation.

I've asked around a bit on #python to see if anyone had any complaints with regards to implicit keywords and delegation issues in particular. None had. At least, none that spoke up. But, after literally *years* of supporting implicit keywords, I think it's safe to say that they would have been removed by now if they had caused delegation or design problems. Let's take a cue, shall we?

I suspect that there's an initial resistance to this idea that I think is analogous to a static language programmer coming to a dynamic language for the first time, and freaking out a bit when the type declaration training wheels are removed. In theory, it could lead to all sorts of bugs/errors/etc. In reality, not only is it not an issue, it makes other things possible you may have never considered before.

Oh, and while I like the idea of using '=' over ':' for keyword arguments, I don't know that it will be possible because, unlike Python, '=' is an expression. But who knows? Evan is a mad genius - maybe he'll find a way. :)

You can read more about how keyword arguments work in Python here

Read: If Python can do it...

Topic: Xampl for Ruby, Finally… Previous Topic   Next Topic Topic: Xampl for Ruby, Finally…

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use