473,406 Members | 2,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

things I wish python could do

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.

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

I want a way to extend a class as easily as I can define it.

3. you cant extend the builtins (string,list,etc), you have to inherit
them. Guido says he wont let us because it would create compatability
issues, and possibly break the interpreter. Maybe if we had namespace
functionality, that wouldnt be an issue?

4. assignments cant be made inside of anonymous functions.

I think most python programmers will agree, that python emphasizes
simplicity, readability, and uniformity. Ultimately, I dont think that any
of those things are important enough to justify the reduction of
flexibility, syntactic mutability, and versatility. 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).

Despite the fact that I disagree with quite a bit of the philosophy behind
prothon, I have enjoyed watching it, because it inspires good dialogue
about language development. (as long as those with closed minds keep their
mouths closed as well)

Are there are any strong reasons why a language shouldn't support the
things I list? Is anybody aware of features promised for future python
versions that solve or nullify my problems? Are any of my perceived
problems really just products of ignorance?
Jul 18 '05 #1
12 1638
Ryan Paul wrote:
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.

1. many keywords (eg:try/except) are strictly imperative, and cannot be
used in a functional context. Python is a language of statements and expressions. This won't change.
If you dislike this feature, ml, lisp, (or it seems, ruby) will be more
to your liking. Python has an imperative definition. A pure functional
system has problems defining things like "print" which, by their very
nature, cause side-effects.
this really should be possible: map(print,mylist) After:
def prints(*args):
print ', '.join(map(str, args))
you can do:
map(prints, mylist)
or even:
prints(*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))
})
I want a way to extend a class as easily as I can define it.

OK, this is just plain wrong. You are walking the wrong way around a
building and then claiming, "these two doors are too far apart."

class Shape:
def __init__(self,numSides, perimeter):
self.numSides = numSides
self.perimeter = perimeter
# which is, I expect what you meant)

Shape.triangle = classmethod(lambda klass, side: klass(3, side*3))
Shape.square = classmethod(lambda klass, side: klass(4, side*4))
and even:
Shape.__repr__ = lambda self: 'Shape(%r, %r)' % (self.numSides,
self.perimeter)

Using klass above allows you to follow this code with:
class FunnyShape(Shape):
def avgSide(self):
return float(self.perimeter) / self.numSides

where you can then:
FunnyShape.triangle(5).avgSide()
3. you cant extend the builtins (string,list,etc), you have to inherit
them. Guido says he wont let us because it would create compatability
issues, and possibly break the interpreter. Maybe if we had namespace
functionality, that wouldnt be an issue? Nope, the complaint is about affecting the global environment
(thus making packages that you import unsure of the behavior of
the primitives).
4. assignments cant be made inside of anonymous functions. The idea is that generally anonymous functions should be trivial, or
you are better off separately defining them and assigning a meaningful
name to the code. Such code takes more effort at the time you write it,
but the code becomes much more readable.
I think most python programmers will agree, that python emphasizes
simplicity, readability, and uniformity.
Ultimately, I dont think that any of those things are important
enough to justify the reduction of flexibility, syntactic
mutability, and versatility.

Then you really would prefer ruby or smalltalk. If you are building
non-trivial, long-lived programs, you spend _far_ more time reading
code than writing it. Flexibility is important, but there need not
be more than one way to do something to accommodate tastes. Code
that mixes styles is the hardest kind of code to read (other than
machine-generated code).

I believe syntactic mutability is an idea that has been tried and
found wanting. The more you can define non-standard syntax, the
more you have to know about a particular piece of code before you
can read it.

As for versatility, the pinnacle of versatility and flexibility
is machine code (not that wimpy assembler). I have found very
few things I'd avoid doing in python, and most of those can be
build as extension modules fairly easily.

I've seen too many interlisp and smalltalk code sets that cannot
use each other's modules. When you can modify the primitives
of a system for your convenience, it becomes tough to work with
someone else who doesn't share your particular quirks of how to
modify the base system.

After having written code for more than three decades, I find python
refreshing in having a language system with a clear discernible,
readable structure that I can trust.

Sorry for having taken troll-bait if that is what this post was.

--
-Scott David Daniels
Sc***********@Acm.Org
Jul 18 '05 #2
Ryan Paul wrote:
1. many keywords (eg:try/except) are strictly imperative, and cannot be
used in a functional context.

this really should be possible: map(print,mylist)


To make everything functional in Python would probably be a
huge effort with cosmetic effects only. What about defining
e.g.

def fprint(item):
print item

putting all functional definitions in a module 'functional'
and using it:

from functional import fprint

....
map(fprint, mylist)

Mit freundlichen Gruessen,

Peter Maas

--
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Hubert-Wienen-Str. 24
Tel +49-241-93878-0 Fax +49-241-93878-20 eMail pe********@mplusr.de
-------------------------------------------------------------------
Jul 18 '05 #3
Ryan Paul <se*******@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 :-)
Jul 18 '05 #4
On Thu, May 13, 2004 at 10:07:19AM +0200, Jacek Generowicz wrote:
[...]
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):
...


Or there's the evil solution, available right now:
http://www.intarweb.us:8080/evil/reopenable.py

-Andrew.
Jul 18 '05 #5

"Jacek Generowicz" <ja**************@cern.ch> wrote in message
news:ty*************@pcepsft001.cern.ch...
Ryan Paul <se*******@sbcglobal.net> writes: Yes, I find the whole statement expression dichotomy one huge PITA.
Would you really prefer writing <target> = expression as set('<target>',
expression) or as the 'special-form' pseudofunction call setq(<target>,
expression)? Just about all Python statements are statements because they
would also be a PITA, and possibly more so, as expressions.
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_.


Lambda expressions in Python are strictly an abbreviation for functions
with a trivial body ('return expression'), nothing more. Anonymity is a
wart, not a feature. The keyword is, to me, a mistake because of the false
expectations it stimulates.
I'm feeling in a controversy-stirring mood. Can you tell?


Bait taken ;-)

Terry J. Reedy

Jul 18 '05 #6
On Thu, 13 May 2004 12:35:48 -0400, "Terry Reedy" <tj*****@udel.edu>
wrote:

"Jacek Generowicz" <ja**************@cern.ch> wrote in message
news:ty*************@pcepsft001.cern.ch...
Ryan Paul <se*******@sbcglobal.net> writes:

Yes, I find the whole statement expression dichotomy one huge PITA.

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


Lambda expressions in Python are strictly an abbreviation for functions
with a trivial body ('return expression'), nothing more. Anonymity is a
wart, not a feature. The keyword is, to me, a mistake because of the false
expectations it stimulates.


Maybe lambda should be renamed as lameda? ;-)
--dang "$.02 too much" dude
Jul 18 '05 #7
>>>>> "Terry" == Terry Reedy <tj*****@udel.edu> writes:

Terry> Would you really prefer writing <target> = expression as
Terry> set('<target>', expression) or as the 'special-form'
Terry> pseudofunction call setq(<target>, expression)? Just about
Terry> all Python statements are statements because they would
Terry> also be a PITA, and possibly more so, as expressions.

Couldn't a = 10 still be an expression despite the syntax? Or at least
behave like one, i.e. yield a result, probably 10 or None...

These days I do think it's not that big a deal, though. Putting
assignment into the condition part of while is a habit people will
outgrow, and other statements would be very clumsy as expressions.

--
Ville Vainio http://tinyurl.com/2prnb
Jul 18 '05 #8
Daniel 'Dang' Griffith <no*****@noemail4u.com> wrote in
news:e2******************************@news.teranew s.com:
On Thu, 13 May 2004 12:35:48 -0400, "Terry Reedy"
<tj*****@udel.edu> wrote:

[...]
Lambda expressions in Python are strictly an abbreviation for
functions with a trivial body ('return expression'), nothing
more. Anonymity is a wart, not a feature. The keyword is, to
me, a mistake because of the false expectations it stimulates.


Maybe lambda should be renamed as lameda? ;-)


Or: lambada -- the forbidden function.

--
rzed
No more than $0.01 here.

Jul 18 '05 #9
>>>>> "rzed" == rzed <rz*****@ntelos.net> writes:
Maybe lambda should be renamed as lameda? ;-)


rzed> Or: lambada -- the forbidden function.

Or leave it to Lambda - the function that dare not speak its name.

(I guess I need to get some sleep now)

--
Ville Vainio http://tinyurl.com/2prnb
Jul 18 '05 #10
"Terry Reedy" <tj*****@udel.edu> writes:
Would you really prefer writing <target> = expression as set('<target>',
expression) or as the 'special-form' pseudofunction call setq(<target>,
expression)?


Almost. I'd really like to write it thus:

(setq <target> expression)

then we'd really be getting somewhere.
I'm feeling in a controversy-stirring mood. Can you tell?


Bait taken ;-)


Here's some more, if you still have the apetite :-)
Jul 18 '05 #11
Ville Vainio wrote:
Couldn't a = 10 still be an expression despite the syntax? Or at least
behave like one, i.e. yield a result, probably 10 or None...

I would think so -- even in C(++) it's possible to write:

a = b = 10;

Cheers,
Michael
Jul 18 '05 #12
In article <2g************@uni-berlin.de>,
Michael Walter <cm@leetspeak.org> wrote:
Couldn't a = 10 still be an expression despite the syntax? Or at least
behave like one, i.e. yield a result, probably 10 or None...

I would think so -- even in C(++) it's possible to write:

a = b = 10;


It's possible to write that in Python, too, but nevertheless in Python
the "b = 10" part isn't an expression.

--
David Eppstein http://www.ics.uci.edu/~eppstein/
Univ. of California, Irvine, School of Information & Computer Science
Jul 18 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Jim Newton | last post by:
does anyone know where i can find the current wish-list or to-do list for futer python releases? Does anyone know if there is a play to allow non-evaluatable statements to return values? I'm...
3
by: fowlertrainer | last post by:
Hello ! I see these things in many sources, under wxPy: def __init__(self,params,**kw,**args) What are these parameters, and what's the meaning of the double * ? Thanx for any info.
11
by: bearophile | last post by:
Hello, here are a four more questions (or suggestions) for the language (probably people have already discussed some of/all such things: I've seen the contracts for Python:...
13
by: Heather Stovold | last post by:
Wow - deciding to program in python sure requires a lot of decisions! So far: I've decided on python for the programming language. I've decided on wxpython for the GUI.... I've decided on...
23
by: gord | last post by:
As a complete novice in the study of Python, I am asking myself where this language is superior or better suited than others. For example, all I see in the tutorials are lots of examples of list...
75
by: Steven T. Hatton | last post by:
No, this is not a troll, and I am not promoting Java, C-flat, D, APL, Bash, Mathematica, SML, or LISP. A college teacher recently posted to this newsgroup regarding her observation that there has...
7
by: Eugene | last post by:
Hi all, I have the following table Name Date Wish Valid Name is person's name, date defaults to getdate() and is never assigned directly (datetime field), Wish is some message, and...
7
by: Tobiah | last post by:
I wanted to do: query = "query text" % tuple(rec.append(extra)) but the append() method returns none, so I did this: fields = rec fields.append(extra) query = "query text" % tuple(fields)
11
by: bullockbefriending bard | last post by:
I've done all the requisite profiling and thought fairly deeply about the efficiency of my python code, but am still going to have to speed up the innermost guts of what I am doing. Essentially,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.