473,387 Members | 3,810 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,387 software developers and data experts.

My python annoyances so far


Hi all. I'm learning python these days. I'm going to use this thread
to post, from time to time, my annoyances with python. I hope someone
will clarify things to me where I have misunderstood them.

Annoyances:

1. Underscores! What's the deal with that? Especially those double
underscores. The best answer I read on this is that the double
underscores denotes special methods that the interpreter may
automatically use. For example, 4+4 get expanded by the interpreter to
4.__add__(4).

2. There are modules, there are functions, and there are classes-
methods! Wouldn't it have been easier had everything either been a
function or a class method?

Apr 25 '07 #1
38 1864
fl****@gmail.com schrieb:
Hi all. I'm learning python these days. I'm going to use this thread
to post, from time to time, my annoyances with python. I hope someone
will clarify things to me where I have misunderstood them.

Annoyances:

1. Underscores! What's the deal with that? Especially those double
underscores. The best answer I read on this is that the double
underscores denotes special methods that the interpreter may
automatically use. For example, 4+4 get expanded by the interpreter to
4.__add__(4).

http://docs.python.org/ref/specialnames.html
2. There are modules, there are functions, and there are classes-
methods! Wouldn't it have been easier had everything either been a
function or a class method?
I'm not sure what you mean here. modules are modules, they can contain
functions, classes, top-level code. Functions and class-methods are
similar, but there are some differences that make sense. But I'm not
sure if you really _mean_ class methods, given that you confuse so much.

The python community is a unusually friendly bunch of people. Yet you
should consider not calling things you don't understand "annoyances".

Diez
Apr 25 '07 #2
fl****@gmail.com wrote:
Hi all. I'm learning python these days. I'm going to use this thread
to post, from time to time, my annoyances with python. I hope someone
will clarify things to me where I have misunderstood them.

Annoyances:

1. Underscores! What's the deal with that? Especially those double
underscores. The best answer I read on this is that the double
underscores denotes special methods that the interpreter may
automatically use. For example, 4+4 get expanded by the interpreter to
4.__add__(4).

2. There are modules, there are functions, and there are classes-
methods! Wouldn't it have been easier had everything either been a
function or a class method?
1. Underscores. __add__ is a special method that gets called when you
want to add two objects together. __init__ is the initalizer method
that gets called when a class is instantiated. Special methods begin
and end with double underlines. __variable is a class (or instance)
variable that shouldn't be manipulated outside the class that is
somewhat equivalent to private variables in other languages. I say
somewhat because there is always a way to get to any variable, even
the double underline ones. _variable is a class (or instance) variable
that is internal to the class an normally shouldn't depended upon
or manipulated from the outside unless the caller really knows what
they are doing.

2. Modules are collections of code. They can be functions or classes.
Functions are functions, classes are classes, you need both in an
object oriented language. Functions alone will not suffice. If you
want to ignore classes at the beginning, please do so.

Suggestion: if you are just starting please accept that there is a
reason for Python being different from almost all "traditional" compiled
languages. If you take some time you will come to understand and,
if you are like most, love the differences. I've been creating a
cross-language COM object and after writing unit tests in VB, Delphi, and
Python I am once again reminded why I love Python. I have more lines
of declarations in the Delphi version than in the Python program for some
tests.

-Larry
Apr 26 '07 #3
fl****@gmail.com wrote:
Hi all. I'm learning python these days. I'm going to use this thread
to post, from time to time, my annoyances with python.
Please start a new thread for each annoyance. Overuse of a single thread
is an annoyance to a great many people.
I hope someone
will clarify things to me where I have misunderstood them.
Perhaps substitute "annoyance" with "misunderstanding" to garner the
friendliness of your python peers.
Annoyances:
You mean "Misunderstandings:"
1. Underscores! What's the deal with that? Especially those double
underscores. The best answer I read on this is that the double
underscores denotes special methods that the interpreter may
automatically use. For example, 4+4 get expanded by the interpreter to
4.__add__(4).
The double underscores are probably not the most aesthetic feature of
the language. By the time you know how and when to use them, they will
not bother you at all and so you will be scratching #1 off your list.
2. There are modules, there are functions, and there are classes-
methods! Wouldn't it have been easier had everything either been a
function or a class method?
Do you mean "unbound methods" or "class methods"? They are essentially
the same as functions unless you get into the internals of python, which
means you are going out of your way to look for annoyances. Such
behavior will lead to frustration and, eventually, abject ennui.

So you should strike your latter point off your list of
annoyances...misunderstandings. For example:
pyclass Thing(object):
.... doit = classmethod(doit)
....
pyThing.doit(88)
Param is "param".
pyThing.doit(object())
Param is "param".
pydef doit(athing, param):
.... print 'Param is "%s".' % param
....
pyclass Thing(object):
.... doit = doit
....
pyt = Thing()
pyt.doit(4)
Param is "4".

If your latter misunderstanding is about the lack of actual class
methods, then consider:
pyclass Thing(object):
.... doit = classmethod(doit)
....
pyThing.doit(4)
Param is "4".
James
Apr 26 '07 #4
On Wed, 25 Apr 2007 15:50:53 -0700, flifus wrote:
>
Hi all. I'm learning python these days. I'm going to use this thread
to post, from time to time, my annoyances with python. I hope someone
will clarify things to me where I have misunderstood them.

Annoyances:

1. Underscores! What's the deal with that? Especially those double
underscores. The best answer I read on this is that the double
underscores denotes special methods that the interpreter may
automatically use. For example, 4+4 get expanded by the interpreter to
4.__add__(4).

I know! It's such a trial, especially since my keyboard is broken and when
I type an underscore I get a small electric shock.

2. There are modules, there are functions, and there are classes-
methods! Wouldn't it have been easier had everything either been a
function or a class method?
What really annoys me is the way function names use vowels _and_ *ow!*
consonants. Some of them even use the letter Y, which sometimes is a
vowel and sometimes is a consonant. That just makes me mad.

--
Steven.

Apr 26 '07 #5
fl****@gmail.com wrote:
Hi all. I'm learning python these days. I'm going to use this
thread to post, from time to time, my annoyances with python. I
hope someone will clarify things to me where I have misunderstood
them.

Annoyances:

1. Underscores! What's the deal with that? Especially those double
underscores. The best answer I read on this is that the double
underscores denotes special methods that the interpreter may
automatically use.
That's right. But what's the annoyance here?

It's a clear seperation. A bigger annoyance would be if the method
name were, e. g., "add". Now you define your own class, don't think
about this and define a method "add" yourself, and you wonder why
your class behaves strangely.
2. There are modules, there are functions, and there are classes-
methods!
You forgot static methods and types. And all of them are objects.
Wouldn't it have been easier had everything either been a
function or a class method?
IMHO no (this isn't Java). Why should I have to define a class if I
just code a little script with a few functions? That would be
forcing the programmer into using a programming paradigm.

Will you ask why there is no StringBuffer in Python? :)

Regards,
Björn

--
BOFH excuse #385:

Dyslexics retyping hosts file on servers

Apr 26 '07 #6
fl****@gmail.com wrote:
Hi all. I'm learning python these days. I'm going to use this thread
to post, from time to time, my annoyances with python. I hope someone
will clarify things to me where I have misunderstood them.

Annoyances:

1. Underscores! What's the deal with that? Especially those double
underscores. The best answer I read on this is that the double
underscores denotes special methods that the interpreter may
automatically use. For example, 4+4 get expanded by the interpreter to
4.__add__(4).

2. There are modules, there are functions, and there are classes-
methods! Wouldn't it have been easier had everything either been a
function or a class method?
Actually, it's really simple. When you get right down to it,
*everything* in *every* current implementation of Python is either a one
or a zero. Would you like us to make it all zeros?

Perhaps you should meditate on the idea to the concept of "sufficient
and necessary complexity" ...

If you're a beginning programmer then it might be that Python contains
features you haven't yet needed. If you come from other languages (and
there's a certain Java-ish feel to the second comment) then perhaps you
aren't yet sufficiently familiar with Python to stop trying to write
other languages in it. I know I gave up Java because, among other
reasons, I found it tedious that I had to build a class method (and
reference it) when what I really wanted was a function.

Finally, I think as a learner you *can* do the language a service by
explaining what you find unnatural, inconvenient or incomprehensible. Do
please realise though that many times things will be as they are for
specific reasons, and sometimes even when the reasons aren't that good
some people will argue for retaining the status quo.

Your posting actually reads quite like a letter to Viz - see

http://www.viz.co.uk/

and follow the "Letterbocks" link - so it gave me a smile before I
realised it was (probably) serious.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com

Apr 26 '07 #7
fl****@gmail.com wrote:
Annoyances:
Every language has annoyances. Python is no exception. Post away.
Anyone that is offended can go drink a Guinness.
1. Underscores! What's the deal with that? Especially those double
underscores. The best answer I read on this is that the double
underscores denotes special methods that the interpreter may
automatically use. For example, 4+4 get expanded by the interpreter to
4.__add__(4).
I thought those were pretty ugly myself. Now, I am used to them.
2. There are modules, there are functions, and there are classes-
methods! Wouldn't it have been easier had everything either been a
function or a class method?
I know what you mean. I always write:

someStringVar.len

and then I backspace and retype:

len(someString).

But then again, I can never remember whether length is a member or a
method in other languages.

Apr 26 '07 #8
7stud wrote:
fl****@gmail.com wrote:
>Annoyances:

Every language has annoyances. Python is no exception. Post away.
Anyone that is offended can go drink a Guinness.
I find Guinness annoying.
--
Michael Hoffman
Apr 26 '07 #9
On 26 Apr, 12:00, Bjoern Schliessmann <usenet-
mail-0306.20.chr0n...@spamgourmet.comwrote:
fli...@gmail.com wrote:
Hi all. I'm learning python these days. I'm going to use this
thread to post, from time to time, my annoyances with python. I
hope someone will clarify things to me where I have misunderstood
them.
Annoyances:
1. Underscores! What's the deal with that? Especially those double
underscores. The best answer I read on this is that the double
underscores denotes special methods that the interpreter may
automatically use.

That's right. But what's the annoyance here?

It's a clear seperation. A bigger annoyance would be if the method
name were, e. g., "add". Now you define your own class, don't think
about this and define a method "add" yourself, and you wonder why
your class behaves strangely.
2. There are modules, there are functions, and there are classes-
methods!

You forgot static methods and types. And all of them are objects.
Wouldn't it have been easier had everything either been a
function or a class method?

IMHO no (this isn't Java). Why should I have to define a class if I
just code a little script with a few functions? That would be
forcing the programmer into using a programming paradigm.

Will you ask why there is no StringBuffer in Python? :)

Regards,

Björn

--
BOFH excuse #385:

Dyslexics retyping hosts file on servers
Hi. You wrote c++, didn't you?

Well, why do some things in the library have to be functions, and
other things have to be class methods?

Why aren't they all just either functions or class methods? like
perhaps ruby.

Apr 26 '07 #10
fl****@gmail.com wrote:
Well, why do some things in the library have to be functions, and
other things have to be class methods?
They don't have to be. They just are. That's like asking why do some
functions start with the letters a-m, and others with n-z. Why can't
they all begin with a-m? The answer would be that it would make the
language harder to use to cram concepts that should more naturally start
with n-z into spellings that start with a-m.
--
Michael Hoffman
Apr 26 '07 #11
In <11**********************@t38g2000prd.googlegroups .com>, flifus wrote:
Well, why do some things in the library have to be functions, and
other things have to be class methods?

Why aren't they all just either functions or class methods? like
perhaps ruby.
To which class should `sorted()` belong to then? Or the functions in the
`math` module? What about `itertools`?

In languages without functions, like Java, you'll have to write static
methods where you really want functions, just because Java forces you to
stuff everything into classes.

And instead of a simple ``lambda`` function one needs to write an
anonymous class with a method. Quite convoluted.

Ciao,
Marc 'BlackJack' Rintsch
Apr 26 '07 #12
fl****@gmail.com wrote:
>Well, why do some things in the library have to be functions, and
other things have to be class methods?
Perhaps because some things are more naturally function like? For
'instance' (pardon the pun), functions shouldn't retain data. They
perform an operation, return data and quit. While retaining data is a
feature of an class/instance.

If I'm looking up the time of day in L.A., why do I need the whole clock
database of times including New York and London?

Another example are with respect to 'int' and 'float' operations. Why
should int(x) be a class? Did you want to save and operate on the value
of x again? No, you want the integer portion of x. Ditto float(x);
somebody input '5' but you want it clear it 5.0. You typecast it your
way. But the float operation doesn't need to retain the last input, nor
even exist after it's last use. So, without have any current values
referenced inside 'float', garbage collection can recover the memory
space of 'float'.

And before someone get's all technical, I know everything in Python is
an 'object' even None, which implies class, or is it the other way around?

sph
Apr 26 '07 #13
On 2007-04-26, Steven Howe <ho*********@gmail.comwrote:
fl****@gmail.com wrote:
>>Well, why do some things in the library have to be functions,
and other things have to be class methods?

Perhaps because some things are more naturally function like?
For 'instance' (pardon the pun), functions shouldn't retain
data. They perform an operation, return data and quit. While
retaining data is a feature of an class/instance.
Functions do retain data. Classes and instances are just a
convenient notation. ;)
>>def funmaker(f, x):
.... return lambda: f(x)
....
>>d = funmaker(int, 10)
d()
10

In addition, all functions in Python have data members, too.
>>d.label = "d"
d.label
'd'

Python's scoping rules make certain kinds of functional idioms
hard to use, though. I'm not sure how to get the following to
work in Python using functions:
>>def account(s):
.... b = s
.... def add(a):
.... b += a
.... def balance():
.... return b
.... return add, balance
....
>>add, balance = account(100)
balance()
100
>>add(5)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 4, in add
UnboundLocalError: local variable 'b' referenced before assignment

Anyhow, it doesn't work, but you can see how closely it resembles
a class definition.
And before someone get's all technical, I know everything in
Python is an 'object' even None, which implies class, or is it
the other way around?
Classes are just objects like everything else.

--
Neil Cerutti
Bach's death is attributed to the end of the Baroque era. --Music Lit Essay
Apr 26 '07 #14
On Apr 26, 6:07 pm, fli...@gmail.com wrote:
Well, why do some things in the library have to be functions, and
other things have to be class methods?

Why aren't they all just either functions or class methods? like
perhaps ruby.
A good question. Part of the answer might be that their are no
abstract base classes / interfaces in the language so far. These have
a particular meaning and you might ask whether some object has certain
abilities like being "sizable". With ABCs or interfaces it feels
natural to implement abstract methods in subclasses. Without them you
can either add methods ad hoc, without any conceptual background and
consistency requirements of your model, or you are going to implement
interface constraints in terms of so called "protocols". A protocol is
a sequence of actions which require interfaces to be present ( they
are abstract algorihms / command patterns ). Special functions
( __add__, __len__, etc. ) are the mediators of protocols. For
instance the meaning of len() can be understood in terms of protocols:

def len(obj):
return obj.__len__()

Other protocols are more implicit e.g. those that couple operators to
method calls. You already mentioned special methods for arithmetic
operations. I sometimes like to think that Python is a language
developed around protocols, and they have a strong backing in the
language. With Py3K Python will become a bit more Java like, at least
with regard to the supported language constructs.

Kay

Apr 26 '07 #15
On Apr 26, 6:07 pm, fli...@gmail.com wrote:
Well, why do some things in the library have to be functions, and
other things have to be class methods?

Why aren't they all just either functions or class methods? like
perhaps ruby.
A good question. Part of the answer might be that their are no
abstract base classes / interfaces in the language so far. These have
a particular meaning and you might ask whether some object has certain
abilities like being "sizable". With ABCs or interfaces it feels
natural to implement abstract methods in subclasses. Without them you
can either add methods ad hoc, without any conceptual background and
consistency requirements of your model, or you are going to implement
interface constraints in terms of so called "protocols". A protocol is
a sequence of actions which require interfaces to be present ( they
are abstract algorihms / command patterns ). Special functions
( __add__, __len__, etc. ) are the mediators of protocols. For
instance the meaning of len() can be understood in terms of protocols:

def len(obj):
return obj.__len__()

Other protocols are more implicit e.g. those that couple operators to
method calls. You already mentioned special methods for arithmetic
operations. I sometimes like to think that Python is a language
developed around protocols, and they have a strong backing in the
language. With Py3K Python will become a bit more Java like, at least
with regard to the supported language constructs.

Kay

Apr 26 '07 #16
On Apr 25, 11:50 pm, fli...@gmail.com wrote:
Hi all. I'm learning python these days. I'm going to use this thread
to post, from time to time, my annoyances with python. I hope someone
will clarify things to me where I have misunderstood them.

Annoyances:

1. Underscores! What's the deal with that? Especially those double
underscores. The best answer I read on this is that the double
underscores denotes special methods that the interpreter may
automatically use. For example, 4+4 get expanded by the interpreter to
4.__add__(4).
I can understand this one. I don't have a problem with this myself,
but a lot of people find the proliferation of underscores in Python
bewildering. All I can say about it is that you soon get used to it -
and the separation is a good enough reason for me.

Fuzzyman
http://www.voidspace.org.uk/ironpython/index.shtml
2. There are modules, there are functions, and there are classes-
methods! Wouldn't it have been easier had everything either been a
function or a class method?

Apr 26 '07 #17
fl****@gmail.com wrote:
Hi. You wrote c++, didn't you?
Yes :) But I mostly don't anymore and ported my main project from
C++ to Python.
Well, why do some things in the library have to be functions, and
other things have to be class methods?
Easy. Some things abstractly operate on all kind of stuff
(called "overloaded" in other languages), while others are,
regarding their function, tied to a specific class.
Why aren't they all just either functions or class methods?
Easy. Not all code in Python operates on a class. But that's what
Python's class methods are for. Only.
like perhaps ruby.
If I were rude, I would ask now why you don't use ruby. But I bet
ruby has some annoyances ready for you too.

Regards,
Björn

--
BOFH excuse #290:

The CPU has shifted, and become decentralized.

Apr 26 '07 #18
On Apr 26, 1:22 pm, Jean-Paul Calderone <exar...@divmod.comwrote:
On 26 Apr 2007 20:05:45 +0200, Neil Cerutti <horp...@yahoo.comwrote:


On 2007-04-26, Steven Howe <howe.ste...@gmail.comwrote:
fli...@gmail.com wrote:
Well, why do some things in the library have to be functions,
and other things have to be class methods?
Perhaps because some things are more naturally function like?
For 'instance' (pardon the pun), functions shouldn't retain
data. They perform an operation, return data and quit. While
retaining data is a feature of an class/instance.
Functions do retain data. Classes and instances are just a
convenient notation. ;)
[snip]
Python's scoping rules make certain kinds of functional idioms
hard to use, though. I'm not sure how to get the following to
work in Python using functions:
>>def account(s):
... b = s
... def add(a):
... b += a
... def balance():
... return b
... return add, balance
...
>>add, balance = account(100)
balance()
100
>>add(5)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 4, in add
UnboundLocalError: local variable 'b' referenced before assignment
Anyhow, it doesn't work, but you can see how closely it resembles
a class definition.

Use the outfix closure operator, []:
>>def account(s):
... b = [s]
... def add(a):
... b[0] += a
... def balance():
... return b[0]
... return add, balance
...
>>add, balance = account(100)
>>add(5)
>>balance()
105
>>>

;)

Jean-Paul- Hide quoted text -

- Show quoted text -
Check out the Percent class I posted at
http://www.programmingforums.org/for...tml#post123290.
It allows you to write code like:

discount = Percent(20)
origprice = 35.00
saleprice = origprice - discount

-- Paul
Apr 26 '07 #19
More samples from that thread:

fica = Percent(7)
fedtax = Percent(15)
medicare = Percent(3)
deductions = fica + fedtax + medicare
gross = 100000
net = gross - deductions
print net # answer: 75000

wholesale = 10
markup = Percent(35)
retail = wholesale + markup
print retail # answer: 13.5

yearlyApprec = Percent(8)
basis = 10000
newbasis = basis + yearlyApprec + yearlyApprec + yearlyApprec
print newbasis # answer: 12597.12

-- Paul

Apr 26 '07 #20
On Thu, 26 Apr 2007 09:07:03 -0700, flifus wrote:
Well, why do some things in the library have to be functions, and
other things have to be class methods?

Why aren't they all just either functions or class methods? like
perhaps ruby.
Perhaps you should read about the Kingdom of Nouns:

http://steve-yegge.blogspot.com/2006...-of-nouns.html

--
Steven.

Apr 26 '07 #21
On Thu, 26 Apr 2007 10:45:22 -0700, Steven Howe wrote:
fl****@gmail.com wrote:
>>Well, why do some things in the library have to be functions, and
other things have to be class methods?
Perhaps because some things are more naturally function like? For
'instance' (pardon the pun), functions shouldn't retain data. They
perform an operation, return data and quit.
Why ever not? How the function performs the operation is an implementation
detail you shouldn't care about. Functions that cache the result of long
time-consuming complications are _good_.

You might also consider generators and iterators and co-routines. None of
those could exist if functions couldn't store data.
[snip]
Another example are with respect to 'int' and 'float' operations. Why
should int(x) be a class?
That's a terrible example, because in fact int and float _are_ classes
(actually types, which are conceptually the same as classes but
implemented differently).
--
Steven.

Apr 26 '07 #22
Steve Holden wrote:
fl****@gmail.com wrote:
>Hi all. I'm learning python these days. I'm going to use this thread
to post, from time to time, my annoyances with python. I hope someone
will clarify things to me where I have misunderstood them.

Annoyances:
2. There are modules, there are functions, and there are classes-
methods! Wouldn't it have been easier had everything either been a
function or a class method?
Actually, it's really simple. When you get right down to it,
*everything* in *every* current implementation of Python is either a one
or a zero. Would you like us to make it all zeros?

Perhaps you should meditate on the idea to the concept of "sufficient
and necessary complexity" ...
Here is something on which to meditate: classes become functions when
you get the quantum mechanics just so!

pyclass add(object):
.... def __new__(self, a, b):
.... return a + b
....
pyc = add(3, 1)
pyc
4
pytype(c)
<type 'int'>
pyadd
<class '__main__.add'>
pydef add(a, b):
.... return a + b
....
pyadd(3, 1)
4
Apr 27 '07 #23
Steven D'Aprano <st***@REMOVE.THIS.cybersource.com.auwrote:
...
detail you shouldn't care about. Functions that cache the result of long
time-consuming complications are _good_.
Not necessarily --
<http://blogs.msdn.com/oldnewthing/archive/2004/12/20/327369.aspx>
asserts the exactly opposite principle, "Don't save anything you can
recalculate"... of course, the best approach is generally a compromise,
but it's good to be aware of the potentially high costs of caching:-).
Alex
Apr 27 '07 #24
Alex Martelli wrote:
Steven D'Aprano <st***@REMOVE.THIS.cybersource.com.auwrote:
...
>>detail you shouldn't care about. Functions that cache the result of long
time-consuming complications are _good_.


Not necessarily --
<http://blogs.msdn.com/oldnewthing/archive/2004/12/20/327369.aspx>
asserts the exactly opposite principle, "Don't save anything you can
recalculate"... of course, the best approach is generally a compromise,
but it's good to be aware of the potentially high costs of caching:-).
Alex
Abelson and Sussman has a better discussion of this subject.
Look under "memoization".

John Nagle
Apr 27 '07 #25
On Apr 26, 9:08 am, Michael Hoffman <cam.ac...@mh391.invalidwrote:
7stud wrote:
fli...@gmail.com wrote:
Annoyances:
Every language has annoyances. Python is no exception. Post away.
Anyone that is offended can go drink a Guinness.

I find Guinness annoying.
--
Michael Hoffman
lol.
Apr 27 '07 #26
On Thu, 26 Apr 2007 19:36:09 -0700, Alex Martelli wrote:
Steven D'Aprano <st***@REMOVE.THIS.cybersource.com.auwrote:
...
>detail you shouldn't care about. Functions that cache the result of long
time-consuming complications are _good_.

Not necessarily --
Absolutely -- I didn't mean to imply that functions should _always_ cache
their "complications" (I meant to write calculations, but obviously my
fingers weren't paying attention to my brain).

<http://blogs.msdn.com/oldnewthing/archive/2004/12/20/327369.aspx>
asserts the exactly opposite principle, "Don't save anything you can
recalculate"... of course, the best approach is generally a compromise,
but it's good to be aware of the potentially high costs of caching:-).
Yes -- I wouldn't cache anything that was cheap enough to calculate. What
cheap enough (in time or memory or other resources) means depends on the
circumstances. Nor would I cache things that were likely to change often.

--
Steven D'Aprano

Apr 27 '07 #27
In <ma***************************************@python. org>, Steven Howe
wrote:
And before someone get's all technical, I know everything in Python is
an 'object' even None, which implies class, or is it the other way around?
Objects don't imply classes. There are object oriented languages without
classes like the Io language. Everything there is an object and the base
object has a `clone()` method to make a copy. So you make copies of
objects and modify them to tweak them into the way you want them.

Ciao,
Marc 'BlackJack' Rintsch
Apr 27 '07 #28
fl****@gmail.com a écrit :
(snip)
>
Well, why do some things in the library have to be functions, and
other things have to be class methods?
Why aren't they all just either functions or class methods? like
perhaps ruby.
If I tell you that Python's functions are in fact static methods of
their module, will this make you happy ? Because, while not technically
true, this is conceptually equivalent.

Or if you prefer to stick to technical truth, python's methods are
nothing more than a thin decorator around a function object (yes,
Python's functions *are* objects) - so in fact, there are *only*
functions - sometimes wrapped into a method object, sometimes not,
depending on how you access them.

In both cases, the fact that you don't have enough knowledge of a
language to understand it's design, and/or the fact that this design is
different from other one you already know, doesn't by itself make this
design an "annoyance".
Apr 27 '07 #29
Marc 'BlackJack' Rintsch a écrit :
In <ma***************************************@python. org>, Steven Howe
wrote:
>And before someone get's all technical, I know everything in Python is
an 'object' even None, which implies class, or is it the other way around?

Objects don't imply classes. There are object oriented languages without
classes like the Io language. Everything there is an object and the base
object has a `clone()` method to make a copy. So you make copies of
objects and modify them to tweak them into the way you want them.
And FWIW, in Python, classes are objects too, and are attributes of
their instances. Which makes Python quite close to prototype-based
languages like Io, Self or Javascript.
Apr 27 '07 #30
7stud a écrit :
fl****@gmail.com wrote:
>Annoyances:

Every language has annoyances. Python is no exception.
Sure. But we may disagree on what are actually Python's annoyances !-)
Post away.
Anyone that is offended can go drink a Guinness.
>1. Underscores! What's the deal with that? Especially those double
underscores. The best answer I read on this is that the double
underscores denotes special methods that the interpreter may
automatically use. For example, 4+4 get expanded by the interpreter to
4.__add__(4).

I thought those were pretty ugly myself. Now, I am used to them.
FWIW, you shouldn't have to directly use __magic__ methods - or only in
very special corner cases.

Apr 27 '07 #31
James Stroud wrote:
Here is something on which to meditate: classes become functions
when you get the quantum mechanics just so!
s/become/can behave like/

:)

Regards,
Björn

--
BOFH excuse #27:

radiosity depletion

Apr 27 '07 #32
Steven D'Aprano wrote:
Perhaps you should read about the Kingdom of Nouns:

<http://steve-yegge.blogspot.com/2006/03/
execution-in-kingdom-of-nouns.html>
Really cool. :) Thanks for sharing the link.

Regards,
Björn

--
BOFH excuse #118:

the router thinks its a printer.

Apr 27 '07 #33
On 26 Apr, 21:50, Bjoern Schliessmann <usenet-
mail-0306.20.chr0n...@spamgourmet.comwrote:
like perhaps ruby.

If I were rude, I would ask now why you don't use ruby. But I bet
ruby has some annoyances ready for you too.

Regards,

Björn
Well, I'd use ruby but python is everywhere, and ruby isn't. All the
applications that interest me are scriptable in python, not ruby.

Apr 27 '07 #34
fl****@gmail.com wrote:
Well, I'd use ruby but python is everywhere, and ruby isn't. All
the applications that interest me are scriptable in python, not
ruby.
Pity that you don't comment core topics.

Regards,
Björn

--
BOFH excuse #289:

Interference between the keyboard and the chair.

Apr 27 '07 #35
On 2007-04-27, Bruno Desthuilliers <br********************@wtf.websiteburo.oops.comwr ote:
7stud a écrit :
>fl****@gmail.com wrote:
>>Annoyances:

Every language has annoyances. Python is no exception.

Sure. But we may disagree on what are actually Python's annoyances !-)
That is probably why the subject says: "my annoyances"

--
Antoon Pardon
Apr 27 '07 #36
Antoon Pardon a écrit :
On 2007-04-27, Bruno Desthuilliers <br********************@wtf.websiteburo.oops.comwr ote:
>>7stud a écrit :
>>>fl****@gmail.com wrote:

Annoyances:
Every language has annoyances. Python is no exception.

Sure. But we may disagree on what are actually Python's annoyances !-)


That is probably why the subject says: "my annoyances"
May I suggest that before finding something annyoing, one has to use it?
When I first discovered Python - and before having any experience with
it - I thought that not having declarative static typing and access
restriction was kind of an annoyement. Real world experience made me
change my mind...
Apr 27 '07 #37
On 2007-04-27, Bruno Desthuilliers <bd*****************@free.quelquepart.frwrote:
Antoon Pardon a écrit :
>On 2007-04-27, Bruno Desthuilliers <br********************@wtf.websiteburo.oops.comwr ote:
>>>7stud a écrit :

fl****@gmail.com wrote:

>Annoyances:
>

Every language has annoyances. Python is no exception.

Sure. But we may disagree on what are actually Python's annoyances !-)


That is probably why the subject says: "my annoyances"
May I suggest that before finding something annyoing, one has to use it?
Sure you may. But what do you mean by use? Are the first exetcices a
newbee tries out already using or do you think these don't count?
When I first discovered Python - and before having any experience with
it - I thought that not having declarative static typing and access
restriction was kind of an annoyement. Real world experience made me
change my mind...
That people may (probably) change their mind later doesn't make it any
less annoying at the moment. The frustrations of the moment don't
disappear just because the more experienced knows these will fade in
the future.

--
Antoon Pardon
Apr 30 '07 #38
7stud <bb**********@yahoo.comwrote:
>I know what you mean. I always write:

someStringVar.len

and then I backspace and retype:

len(someString).

But then again, I can never remember whether length is a member or a
method in other languages.
.... or whether it's called length, size, count or len. Or even
whether the language is consistent from one container class to
the next.

--
\S -- si***@chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
"Frankly I have no feelings towards penguins one way or the other"
-- Arthur C. Clarke
her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
Apr 30 '07 #39

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

Similar topics

16
by: Kenneth McDonald | last post by:
For unfortunate reasons, I'm considering switching back to Win XP (from OS X) as my "main" system. Windows has so many annoyances that I can only compare it to driving in the Bay Area at rush hour...
26
by: brenocon | last post by:
Hi all -- Compared to the Python I know and love, Ruby isn't quite the same. However, it has at least one terrific feature: "blocks". Whereas in Python a "block" is just several lines of...
40
by: =?iso-8859-1?B?QW5kcuk=?= | last post by:
I'm really annoyed at Python - and not for the reasons already mentioned on this list. Everyone know that programming is supposed to be a dark art, nearly impossible to learn. Computer code is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.