Re: OT probably but still relevant (was Re: Looking for a good introduction to object oriented programming with Python)

2012-08-07 Thread Steven D'Aprano
On Mon, 06 Aug 2012 17:23:19 +0100, lipska the kat wrote:

 On 06/08/12 13:19, rusi wrote:

 I suggest this
 http://steve-yegge.blogspot.in/2006/03/execution-in-kingdom-of-
nouns.html
 
 http://bpfurtado.livejournal.com/2006/10/21/

Unfortunately the author (Bruno Furtado) has missed the point. He seems 
to think that Kingdom of Nouns (the Rant) is an anti-OO screed. It is 
not. There is more to OO than Java, and criticism of Java does not mean 
objects are bad.


Nor is it that Kingdom of Nouns believes the problem is Two lines per 
source code file!!!. It isn't just that two extra lines when you declare 
a function. It is the extraneous, unnecessary extra layer each time you 
read (or write, but mostly read) the method, and the ever-more abstract, 
deep layers of Builders, Getters, Setters, Doers and so forth.

In Python, occasionally you will come across code like this:

value = time.time()

which is the time function in the time module. Pretty skanky, right? It's 
not likely that you have a whole bunch of spam.time, foo.time, 
physics.time etc. in your code base, right? If you do, then maybe this is 
justified, but how often does that happen?

Having that duplicated time.time is a code smell that says you might 
have too many code layers here, better look at this a bit more closely.

Now imagine if this was a more Java-ish language:

value = time.time.time()

where you have method time of class time in module time. And you have to 
call it that way *all the time* (pun not intended).

That's not so much a might have too many layers, as almost certainly.

In Java, all those dot look-ups happen at compile time and are fast. In 
Python, they happen at runtime, and while they're still often fast, 
sometimes they can be slow. But that's not the real problem. The real 
problem is reading and writing it.

Python solves that two ways:

1) Modules, classes, methods and functions are first-class objects, so 
you can do this:

from time import time
# or if you prefer, import time; time = time.time
value = time()


2) It doesn't force you to use the same number of layers for 
*everything*. If you have code that will benefit from two, or three, or 
seventeen, layers, you are free to do so:

value = (time.time() + spacetime.Time.time() - Spam.time.flavour()
+ Cube.time())

And if not, then don't:

value = time() + spacetime.time() - flavour() + Cube.time()


It is this which is the point of Kingdom of Nouns. It is not an anti-OO 
screed. It is not an argument against namespaces, or encapsulation, or 
especially not that Java methods take an extra Two lines per source 
file. It is that Java forces a single mental model on you, all the time, 
whether it makes for better, more readable code or not.



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT probably but still relevant (was Re: Looking for a good introduction to object oriented programming with Python)

2012-08-07 Thread lipska the kat

On 07/08/12 10:44, Steven D'Aprano wrote:

On Mon, 06 Aug 2012 17:23:19 +0100, lipska the kat wrote:


On 06/08/12 13:19, rusi wrote:



I suggest this
http://steve-yegge.blogspot.in/2006/03/execution-in-kingdom-of-

nouns.html


http://bpfurtado.livejournal.com/2006/10/21/


Unfortunately the author (Bruno Furtado) has missed the point. He seems


Steve, chill out, you seem to have this whole Javahate thing going at 
the moment. It's just a language, like Python. You can write crap code 
in Java just like you can write crap code in any language. Just for the 
record 'Time' is way too complex a concept to encapsulate in a single 
class (we can debate that if you like although it all gets a bit 
philosophical) If you MUST have a Time Object in Java you can 
instantiate java.sql.Time, not really that complicated is it ?


I do enjoy debating with you but really, lighten up a bit, it really 
isn't that important, mankind existed for millenia before computers and 
programming languages. If we want to exist for millenia after their 
invention then we need to get off this planet. If you want to get 
excited about something then get excited about our apparent inability to 
exceed the speed of light. Until we solve that one we are doomed.


waits for rant about how Java has destroyed the space program

I'm thinking of adding a line to my sig for this group that says

I don't hate Python, I like it for it's differences

;-)

lipska

--
Lipska the Kat: Troll hunter, sandbox destroyer
and farscape dreamer of Aeryn Sun
--
http://mail.python.org/mailman/listinfo/python-list


OT probably but still relevant (was Re: Looking for a good introduction to object oriented programming with Python)

2012-08-06 Thread lipska the kat

On 06/08/12 13:19, rusi wrote:

On Aug 6, 12:46 am, lipska the katlipskathe...@yahoo.co.uk  wrote:

On 04/08/12 16:49, Jean Dubois wrote:


I'm looking for a good introduction to object oriented programming
with Python.




snip



I suggest this
http://steve-yegge.blogspot.in/2006/03/execution-in-kingdom-of-nouns.html


http://bpfurtado.livejournal.com/2006/10/21/

lipska

--
Lipska the Kat: Troll hunter, sandbox destroyer
and farscape dreamer of Aeryn Sun
--
http://mail.python.org/mailman/listinfo/python-list