D&C GLug - Home Page

[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] Python OOP

 

> Shame I never really found a good reason to use the language, as I
> quite like it. The bloke who wrote the language now works for Google,
> who use the language in some of their applications, so at least the
> language is quite likely to survive for a while.

I've found it useful for most things. It is my language of first choice. Very 
powerful, flexible and elegant. In combination with C++ (for close to the 
metal stuff) it is a world beater. SWIG glues the two together. I've used 
this combination on my last two contracts, to great effect. You can develop, 
I estimate, up to 5 times quicker in Python than in the traditional static 
languages. If your application isn't CPU bound, it is a good choice. The 
network support is particularly good.

The joke on the c.l.p group is "if you are writing in C++ you are optimising 
too soon".

> Btw, you might be able to find the book for literally almost nothing
> -£0.01 plus postage- second hand on Amazon. Unless you're really
> interested in using the latest libraries, for a general introduction
> you can do with a version that's a view years old.

There have been some major changes in the language since the first edition, 
especially in the way objects are defined and handled. I would recommend 
using an up to date edition. The latest libraries have some significant 
improvements in a number of areas. For example, strings were not proper 
objects in version 1.5.2, the one covered by the first edition.

Going back to the original question, about OO. Using Python is not just about 
using OO. If you have not used a dynamic language before, then that is also a 
learning curve. I've seen experienced C++ OOP people come to grief with 
dynamic languages. Knowing how to do "hello world" makes Python seem simpler 
than it really is. I don't know enough about Perl to know if it would help 
here, but I suspect it would give you a head start.

They say that Basic gives you bad habits, but so do static languages. People 
worry, unduly, about data types and data structures.

Native reflection, dynamic binding, closures and continuations turn dynamic 
languages into a very different creature from the static Java, C++, Algol 68 
family. It avoids horrors such as Java's anonymous inner classes and C++ 
function objects. Native reflection gives you generic marshalling / 
serialisation, and trivial debug views of objects. Duck typing is more 
flexible than most uses of formal polymorphism. Dynamic types remove the need 
for templates in generic programming. Closures simplify callbacks. All of 
this tends to trip up people coming from static languages. All of these 
things simplify the process of developing software, leaving you to solve the 
problem, instead of wrestling with the confines of language.

The real trick to understanding Python is, "everything is a dictionary". 
Modules, namespaces, methods and properties. They are all implemented using 
associative arrays. The trick to understanding OO is, each object is just a 
collection of functions that can act on the associated data. That, and 
inheritance, are really all you should need to know. All you need to know 
about inheritance is that it should always be an "is a" relationship.

Start simple. Don't bother with continuations, meta classes or other exotic 
stuff until you know what you are doing.

Learn what is in the libraries. Most of the time, if you have a problem to 
solve, you will find that there is a library that already does what you want. 
That is why they say that Python comes with "Batteries included".

I keep this link on my home page

http://www.python.org/doc/current/modindex.html

Enjoy

D

-- 
The Mailing List for the Devon & Cornwall LUG
http://mailman.dclug.org.uk/listinfo/list
FAQ: http://www.dcglug.org.uk/linux_adm/list-faq.html