![]() |
|
|
|||||||
![]() |
Python - Re: Calling functions: Why this complicated ? |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
On Tue, Jul 14, 2009 at 1:40 PM, Mohan Parthasarathy<> wrote:
> Hi, > I am a newbie. I am reading > http://www.network-theory.co.uk/docs...Arguments.html > Defining a function with "N" arguments and calling them in "M" different > ways. Why does it have to be this complicated ? I like the idea of calling > the function by explicitly naming the arguments, but there are so many other > ways here that is very confusing. Do people really use all these features ? > Perhaps, there is a equivalent book to "javascript: Good Parts" for Python ? Oh $DEITY, don't even compare Python to JavaScript. At least in Python, when you try to access a non-existent attribute, a proper NameError exception is thrown rather than silently getting back "undefined"... (*has traumatic horror story flashback*) The calling syntax is not so much complicated as it is liberating. Are you a C junkie who has never heard of named arguments? Just use the call sequence like you've always done. Are you a exacting Smalltalk or Objective-C person who likes to name all the arguments all the time for clarity? You can do that. Do you want to call a function with lots of default arguments but only want to override a couple of them? Specifying them by name lets you do that succinctly. Do you not want to have to worry about the order of the parameters because it seems kinda arbitrary? Then specify the arguments by name. etc... And if you try and specify an argument twice, Python will throw an error, so anything truly confusing will get caught right away. And there's only one definition syntax, so while the call could be complicated, figuring out what it means by looking to the definition is fairly easy. There really aren't that many ways it's done in practice. In practice, the following styles cover 90% of cases: - All named arguments: foo(bar=a, baz=b, qux=c) - All sequential arguments: foo(a, b, c) - All sequential arguments, with a few optional arguments given by name: foo(a, b, c, flag=True, style=qux) - Simple pass-through: foo(*args, **kwargs) Granted, there's 4 of them, but each taken by itself seems pretty easy to read, IMHO. Cheers, Chris -- http://blog.rebertia.com Chris Rebert |
|
|
|
|
#2 |
|
Posts: n/a
|
On Jul 14, 11:31 pm, Chris Rebert <c...@rebertia.com> wrote:
> On Tue, Jul 14, 2009 at 1:40 PM, Mohan Parthasarathy<surut...@gmail.com> wrote: > > Hi, > > I am a newbie. I am reading > >http://www.network-theory.co.uk/docs...Arguments.html > > Defining a function with "N" arguments and calling them in "M" different > > ways. Why does it have to be this complicated ? I like the idea of calling > > the function by explicitly naming the arguments, but there are so many other > > ways here that is very confusing. Do people really use all these features ? > > Perhaps, there is a equivalent book to "javascript: Good Parts" for Python ? > > Oh $DEITY, don't even compare Python toJavaScript. At least in > Python, when you try to access a non-existent attribute, a proper > NameError exception is thrown rather than silently getting back > "undefined"... (*has traumatic horror story flashback*) yehh, that's what i thought, originally, but after talking it over with the people doing the EMCAScript Harmony spec, they explained that nooo, there _are_ exceptions thrown (two if the browser implements it properly, which IE of course doesn't). you can try it by installing the spidermonkey js compiler, which is the exact same js engine that's in firefox. in the python-to-javascript compiler, http://pyjs.org, however, we've taken to adding a double-check (the equivalent of getattr) when you specify the --strict option, juuust to make sure. and yes, there was a talk at europython 2009, pretty much called "javascript, the good parts, for python programmers", you can look it up, the talk audio is online by now. http://europython.eu l. lkcl |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Give you enough string functions in Java web reporting tool | freezea | Software | 0 | 10-08-2009 09:03 AM |
| Please explain this virtual functions matter (c++) | smokey1401 | General Help Related Topics | 0 | 07-11-2008 11:53 PM |
| Access Denied error while calling Windows service in web application | megha | Software | 0 | 04-05-2008 10:03 AM |
| calling a firefox within a widget | MrShahi | Software | 0 | 11-01-2007 11:10 AM |
| Please STOP calling them DVDs | amelrob@aol.com | DVD Video | 183 | 12-15-2003 03:45 AM |