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

Steve Lamb grey at despair.rpglink.com
Fri Jul 28 01:17:51 EDT 2000


On Fri, 28 Jul 2000 04:42:17 GMT, Chris Lawrence <quango at watervalley.net> wrote:
>Reasonable enough.  Though you're not populating a list with a single
>nothing; you're making an empty list.  OTOH, by the logic below, why
>not [None] instead of []?

    Why not indeed?  Something other than an error is expected.

>Not sure about these.  If you want a one-element list, say so.  x =
>[1] is concise.  x = list(1) ain't.  If [] offends your sensibilities,
>try x = list(1,).

    You missed the context in which I was creating it, the rest is just little
snippets to reinforce the point and aren't supposed to be taken as examples of
practical application any more than a 4th grade text book teaching how money
works through purchases without the addition of taxes is meant to be anything
more than an example to serve the purpose of introducing a concept.

    Define a variable to get the name space in there but you don't know how it
is going to be used later on.  a = None.  Now make it a list in a concise
manner.  

for x in range(10):
  a.append(x)

    Whoops, can't do it.  It isn't a list.  So make it a list.

list(a)
for x in range(10):
  a.append(x)

    Whoops, can't do it.  None can't be transformed into a list.

for x in range(10):
  if a:
    a.append(x)
  else
    a = [x]

   All that because of type checking?  Jumping through 3 hoops just to get
done what should be a trivial matter.

>>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 does Python know you want "['a','b','c']" instead of "['abc']"?
>(And wouldn't you *really* expect "abc"?)  It can't.  But logic
>suggests that ['aa', 'b', 'c'] isn't the same thing as ['a', 'a', 'b',
>'c'], yet your representation would say they are the same.

>This strikes me as type-based magic, which Python tries to avoid.

    No, it doesn't try to avoid.  If it did then 1 + 1.2 would fail.  I much
prefer the lack of types.  Also, please read what I left of my previous
message above where I made the same point in a more concise matter.

>Huh?  Python is a strongly typed language.  None is an instance (the
>sole instance, natch) of a NoneType variable.  Should NoneType things
>transmute themselves into other types of things at the drop of a hat?
>This sounds fishily like Perlish automagic conversion.

    I would call it perl's LACK of types.  And yes, if you're going to not
declare types but take them from context and also mutate that type based on
context let's not get hussy about it being a strongly typed language.  Either
mutate types as needed or don't mutate at all and force declarations.  Don't
go half-way and then pretend there aren't quirks to learning that system any
more than the others two.

>Which begs the question: why would you want to declare a variable
>without knowing what you're going to stick in it?

    To clear its value from previous runs.  As for not knowing what I'm going
to stick into it, I do know.  It is data.  Not types, data.  Just data,
nothing but data.

>(Incidentally, you're not creating a namespace, you're making an entry
>in a particular namespace...)

    True, my mistake.

>Hmm, works in JPython too.  And Python 2.0b1.  Maybe it's a feature ;-)

    If you could get None back (which you can so long as you assigned None to
something else before reassigning it) there can be some practical applications
to that.  

>I suspect Guido will tell you, "don't do that." ;-)

    I rather be able to do it at my leasure than have something, be it person
or program, tell me I cannot. 

-- 
         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