Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: does lack of type declarations make Python unsafe? (http://www.velocityreviews.com/forums/t318979-re-does-lack-of-type-declarations-make-python-unsafe.html)

Mark 'Kamikaze' Hughes 06-29-2003 08:39 AM

Re: does lack of type declarations make Python unsafe?
 
Thu, 19 Jun 2003 09:56:37 GMT, Alex Martelli <aleax@aleax.it>:
><posted & mailed>
> David Abrahams wrote:
>> the type of c is a container

> Rather, "c is a container". Choosing to express "c is a container"
> as "the type of c is the type of a container" is just the kind of
> useless, redundant boilerplate that negatively impacts productivity.
> And in neither C++ nor Java can you express "c is a container", either
> directly or indirectly, except in comments


That is incorrect for Java, and for most C++ class libraries.

List c = new ArrayList();
c.add("foo");
c.add("bar");
System.out.println( c instanceof Collection );
System.out.println( c.size() );
for(Iterator it = c.iterator(); it.hasNext(); ) {
System.out.println( it.next() );
}

Java classes can have interfaces, which may define methods, or may
just be markers for behaviors. You can create your own completely
custom class that implements Collection, and it can be used anywhere
any of the java.util.* Collections could. In fact, I find it hard to
understand how anyone could make such an assertion, unless they were
just spouting off without researching it.

For me, the value of statically-defined types is that I know that
mistyping a method name will show up as an error at compile-time, not at
run-time. With __slots__ in the new-style classes, at least now Python
can be made to report mistyped field names as errors at run-time instead
of silently assigning to them, which was a maddening type of bug to
find. I'd prefer to have compile-time checking, but I'm happy enough
with Python's other advantages to live with run-time checking for some
projects.

Python and Java are not diametrically opposed religions that must
fight to the death in jihad, despite the existence of loonies favoring
exactly that. They solve different problems; sometimes in similar ways,
sometimes not.

Getting worked up enough about the evils of a type system to post
hundreds of lines of poorly-researched screed complete with Stockholm
Syndrome references, though... I say this as a friend, there are a lot
of decaffeinated brands on the market today that are just as tasty as
the real thing.

--
<a href="http://kuoi.asui.uidaho.edu/~kamikaze/"> Mark Hughes </a>
"We remain convinced that this is the best defensive posture to adopt in
order to minimize casualties when the Great Old Ones return from beyond
the stars to eat our brains." -Charlie Stross, _The Concrete Jungle_

Anton Vredegoor 06-29-2003 01:53 PM

Re: does lack of type declarations make Python unsafe?
 
kamikaze@kuoi.asui.uidaho.edu (Mark 'Kamikaze' Hughes) wrote:

>> And in neither C++ nor Java can you express "c is a container", either
>> directly or indirectly, except in comments

>
> That is incorrect for Java, and for most C++ class libraries.
>
> List c = new ArrayList();
> c.add("foo");
> c.add("bar");
> System.out.println( c instanceof Collection );
> System.out.println( c.size() );
> for(Iterator it = c.iterator(); it.hasNext(); ) {
> System.out.println( it.next() );
> }


As some googling seems to indicate this is an extendable list of
references. Since int doesn't derive from object, this will probably
fail:

c.add(1)

One decaffeinated Java with extra coffein please :-)

Anton

---

z,w=zip(range(99,0,-1)+['no'],'s'*98+' s')," on the wall"
n,t="%s bottle%s of beer","take one down, pass it around"
for x,y in zip(z,z[1:]):print'\n'.join((n%x+w,n%x,t,n%y+w,''))

Anton Vredegoor 07-01-2003 10:30 AM

Re: does lack of type declarations make Python unsafe?
 
kamikaze@kuoi.asui.uidaho.edu (Mark 'Kamikaze' Hughes) wrote:

<discussing Java collections>
>> Since int doesn't derive from object, this will probably
>> fail:
>> c.add(1)

>
> This is true, but it's completely unimportant. It's annoying at
>times, but it's an optimization for efficiency; there are good reasons
>why Java is several times faster than Python at most tasks. You can use
>the primitive wrapper classes:
>c.add( new Integer(1) );


Interesting, first define it as unimportant and next focus un Java's
strong points.

> On the rare occasions that I have to deal with a lot of Integer
>objects, I use a cache of the most commonly-used ranges, but Java's
>object creation is well-optimized these days, so there's no great harm
>in just newing up an Integer.


Weaken the use case and insist that it can be done with little extra
trouble, if any remaining -unbelievably persistent- user still would
think there's a need for it.

> Retrieving the value is done by the ugly but standard idiom:
>int n = ((Integer)it.next()).intValue();


Show how ugly it would be.

> Or you can write your own int container class, if you need to do that
>kind of operation frequently. I find that it rarely comes up, because
>Java's normally used at a higher level.


Associate it with uncommon low level activities.

> Java's not *pretty*, but it's a powerful and expressive language.


Expose the requested feature as a tradeoff with performance and
expressiveness.

Reading all this I get a very warped feeling of deja vu, because these
kind of techniques are often used here to fend off "attacks" against
Python.

Maybe the "complete reversal" technique is new so I'll try it out:

"does lack of type declarations make Python unsafe?"

No it makes it safer, because being able to produce code that is
easier to read improves the validity of the code. (Validity is defined
here by "Does the program do what you think it does")

Since languages using type declarations don't enable the coder to "fly
by wire" and force her into all kinds of ugly code constructs, changes
are the coder will get lost in the code labyrinth. Therefore for such
languages extreme caution and large amounts of tests are unavoidable.
Of course these efforts use valuable coder time that would be better
employed in "algorithm space" instead of in "implementation space".

Anton

Mark 'Kamikaze' Hughes 07-01-2003 02:20 PM

Re: does lack of type declarations make Python unsafe?
 
Tue, 01 Jul 2003 12:30:58 +0200, Anton Vredegoor <anton@vredegoor.doge.nl>:
> kamikaze@kuoi.asui.uidaho.edu (Mark 'Kamikaze' Hughes) wrote:
><discussing Java collections>
>>> Since int doesn't derive from object, this will probably
>>> fail:
>>> c.add(1)

>> This is true, but it's completely unimportant. It's annoying at
>>times, but it's an optimization for efficiency; there are good reasons
>>why Java is several times faster than Python at most tasks. You can use
>>the primitive wrapper classes:
>>c.add( new Integer(1) );

> Interesting, first define it as unimportant and next focus un Java's
> strong points.


Stop. This is not a high school debate class. You knew nothing about
Java but felt the pathological need to attack it with claims you found
on google. Despite your cretinous behavior, I politely explained the
Java idiom and motivation for dealing with primitives differently.
You're just being an ass here.

<http://kuoi.asui.uidaho.edu/~kamikaze/documents/plonk.html>

--
<a href="http://kuoi.asui.uidaho.edu/~kamikaze/"> Mark Hughes </a>
"We remain convinced that this is the best defensive posture to adopt in
order to minimize casualties when the Great Old Ones return from beyond
the stars to eat our brains." -Charlie Stross, _The Concrete Jungle_

Anton Vredegoor 07-01-2003 04:38 PM

Re: does lack of type declarations make Python unsafe?
 
kamikaze@kuoi.asui.uidaho.edu (Mark 'Kamikaze' Hughes) wrote:

> Stop. <snip>


Probably too soon for the complete reversal technique. FYI I was
trying to use your post as an example of the defensive psychological
techniques people (not just you, me too, and probably a lot of the
readers here) use when facing ambiguity. Introducing new language
features or trying to do unfamiliar things -f.e. from other languages-
with the language one is accustomed to produces exactly the kind of
feelings of unsafety -and alas, the defensive postures and abuse- that
this thread is about. I thank you anyway for serving as an example for
this, stay here and maybe you'll reverse someday, be it more slowly,
though we'll probably never marry :-|

Anton




All times are GMT. The time now is 09:48 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.