things I wish python could do
Jacek Generowicz
jacek.generowicz at cern.ch
Thu May 13 04:07:19 EDT 2004
More information about the Python-list mailing list
Thu May 13 04:07:19 EDT 2004
- Previous message (by thread): things I wish python could do
- Next message (by thread): things I wish python could do
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Ryan Paul <segphault at sbcglobal.net> writes: > I've spent a lot of time using python, and personally, I feel like it is > vastly superior when compared to languages like java, and c++, but there > are still a few things that detract from its elegance and flexibility. I > thought I might mention a few of them. I'd like to hear what people think > of my complaints, and I also like to hear the complaints of others. > > 1. many keywords (eg:try/except) are strictly imperative, and cannot be > used in a functional context. Yes, I find the whole statement expression dichotomy one huge PITA. > this really should be possible: map(print,mylist) > > 2. there is no easy way to extend existing classes externally. > > its possible, but it aint pretty... > > class Shape: > def __init__(self,numSides, perimeter): > pass > > Currently you can do this: > > Shape.__dict__.update({ > 'triangle':ClassMethod( > lambda self,sideLength: Shape(3,sideLength*3)) > > 'square':ClassMethod( > lambda self,sideLength: Shape(4,sideLength*4)) > }) Which looks like (I don't know what ClassMethod is) a long-winded way of wrting: Shape.triangle = lambda self, sideLength: Shape(...)) > I want a way to extend a class as easily as I can define it. You can. There is one syntax for creating new classes, and another for mutating existing ones. Ruby conflates the two. I think that what you "want" is to cleate new classes and mutate existing ones using the same syntax. Perhaps you should question whether you really want that. Maybe there's a satisfactory solution based on the decorators that are being proposed in PEP 318: class Shape [update]: def triangle(self, sideLength): ... > 4. assignments cant be made inside of anonymous functions. Actually, there's very little you can do in anonymous functions, given that you are restricted to a _single expression_. > I was surprised to find that Ruby solves all of my python > complaints, while achieving grace and simplicity easily comparable > to that of python, and providing a few innovative extras (including > real private, public, and protected methods). Yes, access-restricted private methods were an innovation in the field of programmer productivity reduction, but it was not an innovation on Ruby's part ... though why a language which sounds quite sensible, would choose to embrace such a criminal practice is a mystery to me. (Hmm ... briefly perusing a Ruby manual, I get the impression that some of it is a result of having to get around problems caused by all classes inheriting all (would-be) global functions ... which makes me reconsider my statement that Ruby sounds quite sensible.) > Are there are any strong reasons why a language shouldn't support the > things I list? 1) Keywords are just plain wrong. 4) Python's indentation-based block structure makes general anonymous functions a bit problematic. (Briefly perusing the PEPs I notice 308 ... and I'm surprised that it's publication date is not April 1st, as it looks like a PERLification attempt.) > Is anybody aware of features promised for future python versions > that solve or nullify my problems? Read the PEPs. > Are any of my perceived problems really just products of ignorance? Probably. I'm feeling in a controversy-stirring mood. Can you tell? With any luck I've trodden on Python's, Ruby's and your toes :-)
- Previous message (by thread): things I wish python could do
- Next message (by thread): things I wish python could do
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list