Re: A java hobbyist programmer learning python

2009-01-26 Thread Scott David Daniels
Tim Rowe wrote: ... I like the second style because it makes it leaves the 2-d implementation hidden, which is the whole point of encapsulation. I like the second as well, in that it it allows the parent to update any related data structures (for example, updating a display). However, I am a bi

Re: A java hobbyist programmer learning python

2009-01-26 Thread Tim Rowe
> I like the latter two styles, particularly the last one. That way you > can see at a glance that those member variables are defined in the > super class. I like the second style because it makes it leaves the 2-d implementation hidden, which is the whole point of encapsulation. > But then I am

Re: A java hobbyist programmer learning python

2009-01-25 Thread TheFlyingDutchman
>         If you're building an extension tree, you'll either have to supply > layers of getter/setter methods, or hand-mangle references to attributes > defined in the superclass. > >         Say you start with a "Point2D" class, and make the X, Y coordinates > double underscore. > >         Now e

Re: A java hobbyist programmer learning python

2009-01-24 Thread TheFlyingDutchman
On Jan 23, 8:57 am, Dennis Lee Bieber wrote: > On Fri, 23 Jan 2009 01:48:32 -0800 (PST), TheFlyingDutchman > declaimed the following in comp.lang.python: > > > abstraction. In Python, all class attributes are public but names may > > be "mangled" to discourage unauthorized access, but otherwise n

Re: A java hobbyist programmer learning python

2009-01-23 Thread TheFlyingDutchman
> > * No getters and setters. Python takes a very permissive approach to > class attributes, taking the philosophy "we're all adults here". It's > easy to change a public attribute to a private attribute with a getter/ > setter if you need to, so there's nothing to be gained by writing getters > f

Re: A java hobbyist programmer learning python

2009-01-22 Thread Aahz
In article <7xy6x9nzwd@ruckus.brouhaha.com>, Paul Rubin wrote: >Chris Rebert writes: >>attribution deleted by Paul Rubin: >>> >>> class Calculator(): ... >> >> Delete the 3 Java-ish accessor methods; good Python style just uses >> the attributes directly (i.e. s

Re: A java hobbyist programmer learning python

2009-01-19 Thread Rhodri James
On Sun, 18 Jan 2009 02:24:51 -, Steven D'Aprano wrote: Let me re-write your code in a more Pythonic way. This is not the only way to do this, and it probably isn't the best way, but it may give you a flavour for the way Python is usually written. import sys import operator class Calc

Re: A java hobbyist programmer learning python

2009-01-17 Thread elhombre
"Steven D'Aprano" wrote in message news:0182896d$0$8693$c3e8...@news.astraweb.com... On Sun, 18 Jan 2009 11:11:45 +1000, elhombre wrote: Hello, below is my first fragment of working python code. As you can see it is very java like as that is all I know. Is this the right approach to be taki

Re: A java hobbyist programmer learning python

2009-01-17 Thread elhombre
"John Machin" wrote in message news:5d2c588a-9b01-4a85-85b2-b132754e6...@o40g2000prn.googlegroups.com... On Jan 18, 12:11 pm, "elhombre" wrote: Hello, below is my first fragment of working python code. As you can see it is very java like as that is all I know. Is this the right approach to be

Re: A java hobbyist programmer learning python

2009-01-17 Thread elhombre
"Paul Rubin" wrote in message news:7xy6x9nzwd@ruckus.brouhaha.com... Chris Rebert writes: > class Calculator(): ... Delete the 3 Java-ish accessor methods; good Python style just uses the attributes directly (i.e. self.operator instead of self.getOperator

Re: A java hobbyist programmer learning python

2009-01-17 Thread elhombre
"Chris Rebert" wrote in message news:mailman.7468.1232242083.3487.python-l...@python.org... On Sat, Jan 17, 2009 at 5:11 PM, elhombre wrote: ... Rather than have a long if-elif-else chain like this, you can use a dictionary with functions as values. For example: def add(x, y): return x +

Re: A java hobbyist programmer learning python

2009-01-17 Thread Steven D'Aprano
On Sun, 18 Jan 2009 11:11:45 +1000, elhombre wrote: > Hello, below is my first fragment of working python code. As you can see > it is very java like as that is all I know. Is this the right approach > to be taking? You might find it very useful to read: http://dirtsimple.org/2004/12/python-is-n

Re: A java hobbyist programmer learning python

2009-01-17 Thread John Machin
On Jan 18, 12:11 pm, "elhombre" wrote: > Hello, below is my first fragment of working python code. As you can see it > is very java like as that is all I know. Is this the right approach to be > taking? > Should I be taking a different approach? Thanks in advance. > > import sys > > class Calculat

Re: A java hobbyist programmer learning python

2009-01-17 Thread Chris Rebert
On Sat, Jan 17, 2009 at 5:53 PM, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > Chris Rebert writes: >> Rather than have a long if-elif-else chain like this, you can use a >> dictionary with functions as values. For example: >> >> def add(x, y): >> return x + y > > These functions are al

Re: A java hobbyist programmer learning python

2009-01-17 Thread Paul Rubin
Chris Rebert writes: > > class Calculator(): ... > Delete the 3 Java-ish accessor methods; good Python style just uses > the attributes directly (i.e. self.operator instead of > self.getOperator()). I think I would get rid of the whole Calculator class unless there was a good reason to keep it (

Re: A java hobbyist programmer learning python

2009-01-17 Thread Chris Rebert
On Sat, Jan 17, 2009 at 5:11 PM, elhombre wrote: > Hello, below is my first fragment of working python code. As you can see it > is very java like as that is all I know. Is this the right approach to be > taking? > Should I be taking a different approach? Thanks in advance. > > import sys > > clas

A java hobbyist programmer learning python

2009-01-17 Thread elhombre
Hello, below is my first fragment of working python code. As you can see it is very java like as that is all I know. Is this the right approach to be taking? Should I be taking a different approach? Thanks in advance. import sys class Calculator(): def __init__(self): self.operator