"no variable or argument declarations are necessary."

Mike Meyer mwm at mired.org
Thu Oct 6 23:44:36 CEST 2005


Barbier de Reuille <pierre.barbier at cirad.fr> writes:

> Dans l'article <86mzlmpo5r.fsf at bhuda.mired.org>, Mike Meyer a écrit :
>> Pierre Barbier de Reuille <pierre.barbier at cirad.fr> writes:
>>> Mike Meyer a écrit :
>>>> Antoon Pardon <apardon at forel.vub.ac.be> writes:
>>>> 
>>>>>Op 2005-10-03, Steven D'Aprano schreef <steve at REMOVETHIScyber.com.au>:
>>>>>
>>>>>>On Mon, 03 Oct 2005 13:58:33 +0000, Antoon Pardon wrote:
>>>>>
>>>>>Declarations also allow easier writable closures. Since the declaration
>>>>>happens at a certain scope, the run time can easily find the correct
>>>>>scope when a variable is rebound.
>>>> If it happens at runtime, then you can do it without declarations:
>>>> they're gone by then. Come to think of it, most functional languages -
>>>> which are the languages that make the heaviest use of closures - don't
>>>> require variable declarations.
>>> Well, can you give a single example of such language ? Because all the
>>> functionnal language I know but one do need variable declaration : lisp,
>>> scheme, ocaml, haskell do need variable declaration ! Erlang do not ...
>> 
>> Scheme and lisp don't need variable declerations. Last time I looked,
>> Schemd didn't even *allow* variable declerations.
>
> When you want local variable in lisp you do :
>
> (let ((a 3)) (+ a 1))

Excep that's not a decleration, that's a binding. That's identical to
the Python fragment:

       a = 3
       return a + 1

except for the creation of the new scope. Not a variable decleration
in site.

> For global variable you may do:
>
> (defparameter *a* 4)
>
> or:
>
> (defvar *a* 4)

That's not Scheme. When I was writing LISP, those weren't
required. Which is what I said: variable declarations aren't required,
and aren't allowedd in Scheme.

> However, either way, variable assignment is done via :
>
> (setf *a* 5)
> (setf a 10)
>
> This is what I call variable declaration as you have different way
> to declare global variables and to assign them ... So the
> two operations are well defined and different.

Python uses "global foo" to declare global variables.

> And here there is a difference between static language and
> declarative ones ... Lisp is a dynamic language that needs variable
> declarations.

LISP doesn't need variable declarations. I certainly never wrote any
when I was writing it.

>>>> Except declarations don't add functionality to the language. They
>>>> effect the programing process. And we have conflicting claims about
>>>> whether that's a good effect or not, all apparently based on nothing
>>>> solider than personal experience. Which means the arguments are just
>>>> personal preferences.
>>> Well, so why not *allow* for variable declaration ? Languages like Perl
>>> does that successfully ... you don't like : you don't do ! you like :
>>> you do ! A simple option at the beginning of the file tell the compilor
>>> if variable declaration is mandatory or not !
>> 
>> Perl is a red herring. Unless it's changed radically since I last
>> looked, undeclared variables in Perl have dynamic scope, not lexical
>> scope. While dynamically scoped variables are a powerful feature, and
>> there have been proposals to add them to Python, having them be the
>> default is just *wrong*. If I were writing in Perl, I'd want
>> everything declared just to avoid that. Of course, if Python behaved
>> that way, I'd do what I did with Perl, and change languages.
>
> I never said to adopt the whole Perl variable semantic. I just pointed
> what I think is a good idea in Perl and that help (IMHO) precising what
> I intended ...

And I pointed out that it's a good idea in Perl because it does
something that it doesn't need doing in Python.

>>>> Dynamic languages tend to express a much wider range of programming
>>>> paradigms than languages that are designed to be statically
>>>> compiled. Some of these paradigms do away with - or relegate to the
>>>> level of "ugly performance hack" - features that someone only
>>>> experienced with something like Pascal would consider
>>>> essential. Assignment statements are a good example of that.
>>> Well, could you be more specific once more ? I can't that many paradigm
>>> only available on dynamically typed languages ... beside duck-typing
>>> (which is basically a synonym for dynamically-typed)
>> I said "dynamic languages", *not* "dynamically typed languages". They
>> aren't the same thing. Dynamic languages let you create new functions,
>> variables and attributes at run time. Python lets you delete them as
>> well.  This means that simle declarations can't tell you whether or
>> not a variable will exist at runtime, because it may have been added
>> at run time.
> Ok, I misunderstood ... however, can you still point some *usefull*
> paradigm available to dynamic languages that you cannot use with static
> ones ? As there are so many, it shouldn't be hard for you to show us
> some !

I find the ability to add attributes to an object or class at run time
useful.

        <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list