Perl is worse! (was: Python is Wierd!)

Steve Lamb grey at despair.rpglink.com
Thu Jul 27 23:29:06 EDT 2000


On Fri, 28 Jul 2000 11:37:46 +1000, Richard Jones
<Richard.Jones at fulcrum.com.au> wrote:
>   Hey, don't worry about mis-using the linenoise - you just have to _look_
>at the damn structure in Perl the wrong way and suddenly it's something else. 

    Please, be realistic.  How is this different than Python's automatigal
variable declaration based solely on first use?  Let's not denounce one
language in favor of another when both use the same trick, one just half as
much as the other and causing twice as many problems because of it.  Let's not
also pretend that your language of choice doesn't have odd quirks, ok?  

    Just playing around try this some time:

a = None
list(a)
a = 1 
list(a)
a = 123
list(a)
a = "abc"
list(a)

    To me all of those could be converted into lists yet only the last one is.
Why do I say that?  

    None could be converted into an empty list.  None is nothing.  I fail to
see how you can't populate a list with a single nothing.

    1 is a single value.  I fail to see why that cannot be converted to [1]
which is allowed, btw. 
a = [1]
a

    123 is a single value.  I fail to see why that cannot be converted to
[123] which, again, is allowed.  See above.

    "abc" could either be a single value or a sequence.  It is converted as
["a", "b", "c"].  Of course, the same /could/ be said for the above.  However,
let's play around with this one since it is the only one that works somewhat
as expected in conversion.

a = "abc"
a
a = list(a)
a = str(a)
a

    a is now "['a', 'b', 'c']".  Which means we split a string up when
converting to list but don't concatinate on the way back.  I'd think, then,
that we'd not split the string up in the first place and consider it a single
value for a single entry in a list.  IE, ["abc"].  But, of course, dropping
back from a list to a str isn't perfect since you're going from a more complex
structure into a simple data set.

    How did I run across this?  Because I wanted to create an empty name each
time a class instance is created.  Since I was building the class I didn't
know if I was going to use a list or a str.  I figure I could just set it
to None and then manipulate it later.  Nope.  Couldn't even convert it even
though the conversion seems quite straightforward to me.  None into any
structure should yield and empty of that structure.  We can have empty
strings, tuples, lists and directories.  Funny thing, though.  I can do this
and it works just fine:

a = None
a = ""

    Amazing, that.  Automagical conversion from None to an emptry string on
the assignment operator.  Actually, we both know, and correct me as I may be
wrong, that it is really reassigning the data space a is pointing to.

    However, if we want to create the namespace with nothing we cannot because
we cannot convert it for later use.  Thus, we are back to declaring variables
except this time we're doing it with automagical (implicit) means instead of
explicit.  

    Like I said, every language has its quirks.  Every language.  Just because
this is your favorite doesn't mean it doesn't have quirks, just means you are
used to them.  Just as a perl programmer I am used to perl's quirks and take
advantage of them and, yes, sometimes get caught by them as well.  Just as I
am in the process of learning Python (rapidly, I might add) and have, and
will, be caught by its quirks and will also learn to take advantage of them.

    But please, if you're going to toss rocks out your glass house, at least
be realistic about it, ok?  At least then your neighbors are more apt to help
you sweep up the resulting mess.

    And just for fun, here's a good quirk for you.  

None = 1
a = None
>>> if a:
...   print "foo\n"
... 
foo

>>> a
1

    I think that is kinda neat, don't you?  

{grey at teleute:~} perl
null = "foo";
Can't modify constant item in scalar assignment at - line 1, near ""foo";"

    I just don't understand how people can advocate for types and the
restrictions they impose while, on the other hand, embracing a language that
is free enough to shoot yourself in the foot by reassigning None.

    Shoot yourself with "conversion" or with assignments like this, either way
your foot is shot.  I say learn proper gun safty and aim it elsewhere.  ;)
Seriously, that isn't to say that None should be restricted from being
changed, just, uh, anyone know how to change it back aside from restarting
python?  :)

-- 
         Steve C. Lamb         | I'm your priest, I'm your shrink, I'm your
         ICQ: 5107343          | main connection to the switchboard of souls.
-------------------------------+---------------------------------------------



More information about the Python-list mailing list