Looking for resources for making the jump from Java to Python easier and more productive

T

ToddLMorgan

I'm just starting out with python, after having a long history with
Java. I was wondering if there were any resources or tips from anyone
out there in Python-land that can help me make the transition as
successfully as possible? Perhaps you've made the transition yourself
or just have experience with folks who have made the transition.

I'm looking for the common types of mistakes that say a Java/C# or
even C++ developer may commonly make. More examples like those
highlighted here http://dirtsimple.org/2004/12/python-is-not-java.html
would be particularly useful. I've already made the static class
method mistake, and been thoroughly confused by packages and
imports/froms and extremely frustrated with attempting to call super
constructors etc. I'm getting the hang of passing around functions
(ala the command pattern), customising the operators and extending
inbuilt classes. All of these concepts I've done before so there
nothing really great and wonderful about using them in another
language. Some of the really powerful ideas of python (eg as suggested
in the link) about creating one function containing a template function
that can cater to all possible implementations sounds really cool and
alien to me at the same time. That's the sort of stuff I'm
interested in.

At this point in time I'd say my python code is more coding Java in
python than doing it in a pythonic way. Perhaps there some good/great
examples of Python scripts or projects that I could look at to get
inspired or learn pythonic implementation ideas? I just don't know of
any. Are there python specific equivalents to the common Patterns,
Anti-Patterns and Refactoring books that are so prevalent as
reccomended reading in C++ and Java? If so what?

Given the rising popularity of Python these days there has got to be a
few of you out there who've made the transition successfully and have
some pearls-of-wisdom to share that you'd wished you'd known about
earlier.

Thanks
Todd
 
L

Lawrence D'Oliveiro

"ToddLMorgan said:
I'm looking for the common types of mistakes that say a Java/C# or
even C++ developer may commonly make.

Using subclassing when you don't have to. For instance, you might have a
Java method which takes an argument of type java.io_OutputStream to
which it writes. You might translate this to a Python method to which
you are careful to only pass instances of subclasses of file objects.
But in fact there is no necessity for this: you are free to pass any
object which has appropriate members.

I suppose this is an instance of the more general rule: "using OO when
you don't have to".
 
L

Lawrence D'Oliveiro

"ToddLMorgan said:
Are there python specific equivalents to the common Patterns,
Anti-Patterns and Refactoring books that are so prevalent as
reccomended reading in C++ and Java?

I don't think they exist. Such books are targeted more towards
development in a corporate environment, where every proposal has to go
through multiple layers of management, and nothing is ever done by
individuals working alone, always by "teams" working on separate parts
of the project. And also where the end-users don't really get much say
in how things are supposed to work. It's only in such a high-overhead,
top-down, cover-your-ass environment that such books are looked on as
being at all useful. Possibly on the grounds that nobody ever got fired
for buying them.

I'd say languages like Python and Perl are the absolute antithesis of
this sort of development culture.
 
A

Anton Vredegoor

ToddLMorgan said:
I'm just starting out with python, after having a long history with
Java. I was wondering if there were any resources or tips from anyone
out there in Python-land that can help me make the transition as
successfully as possible? Perhaps you've made the transition yourself
or just have experience with folks who have made the transition.

Some time ago I had to learn a bit of Java in order to be able to write
some signed jython browser applets that I could use while working at a
highly restricted public library computer. So I guess I was coming from
the opposite direction :) Anyway I wondered why (and how!) very small
jython scripts could replace large blocks of java code.

Maybe looking at it from a jython perspective will be educational for
you. I think it would be a lot of fun realizing how much java code can
actually be 'automatically' generated or filled in by jython traversing
its class system.

Also I'm hoping it would produce an opportunity for an advanced java
coder to write some cool signed java applet in jython that would have
the look and feel of idle.py for python but that would run from a
webbrowser.

I know it can be done because I did write some experimental but still
already very functional things like a jython console webbrowser applet,
a websucker.py running from within a browser, and I hacked some other
jython editor-console (eclipse is good for such things) to add some
functionality and do my own signing and library selection.

Don't ask for my code yet though, it's nowhere near presentable. Anyway,
since then I found a job that gives me access to less locked down
computers which is also fun.

Anton
 
C

Chris Lambacher

http://dirtsimple.org/2004/12/python-is-not-java.html
http://dirtsimple.org/2004/12/java-is-not-python-either.html
http://dirtsimple.org/2004/12/python-interfaces-are-not-java.html

This link seems to be down at the moment.
http://naeblis.cx/rtomayko/2004/12/15/the-static-method-thing

The above articles were really helped me understand the python way of doining
things. In particular they mention language features that may be named the
same and do similar things, but would be used for totally different reasons in
the two languages.

I hope you find them as helpful as I did.

-Chris
 
A

Ant

Take a look at the newgroup archives over the last week or two - there
seem to have been a glut of people coming from Java to Python and
asking the same sort of questions. There were some links to a bunch of
Python 'gotcha' pages which will be useful.

For my part, I came from Java to Python, and found that it was useful
to do a load of small scripts in the simplest way possible, or in as
many different ways possible. For example, trying a script involving
creating a new iterable object from a list using for loops, list
comprehensions, generators or functional built-ins (such as map()). The
clearest method usually seems to be considered the most pythonic.

A couple of sites to practice against are:
http://www.pythonchallenge.com/
http://mathschallenge.net/

They give a good set of problems which will work various aspects of
Python that aren't familiar to Java guys, and also break the mindset
that everything has to be done in classes.

I'm still making the transition of course ;-)
 
T

ToddLMorgan

I've actually managed to find some other links by backtracking through
some of the links that you provided.

The most comprehensive so far is this one
http://www.razorvine.net/python/PythonForJavaProgrammers and a summary
version (on the same site)
http://www.razorvine.net/python/PythonComparedToJava

The site owner (Irmen de Jong) appears to be be compiling a decent
migration path from Java to Python on a Moin-Moin Wiki so perhaps he'll
be harvesting more useful information from here and other places in the
near future as the pages only appears a few days ago.

There was also a follow up to
http://naeblis.cx/rtomayko/2004/12/15/the-static-method-thing with
http://naeblis.cx/rtomayko/2005/01/20/getters-setters-fuxors

Hopefully this will prove helpful to some other folks :- )

I'm still working my way up to the practice sites (python and math
challenge) ... I want to do a bit more reading first :- )

ciao & thanks
Todd
 
H

Harry George

Lawrence D'Oliveiro said:
I don't think they exist. Such books are targeted more towards
development in a corporate environment, where every proposal has to go
through multiple layers of management, and nothing is ever done by
individuals working alone, always by "teams" working on separate parts
of the project. And also where the end-users don't really get much say
in how things are supposed to work. It's only in such a high-overhead,
top-down, cover-your-ass environment that such books are looked on as
being at all useful. Possibly on the grounds that nobody ever got fired
for buying them.

I'd say languages like Python and Perl are the absolute antithesis of
this sort of development culture.

On "antithesis" comment:

Python can be used for Agile Programming, with the end user there at
the monitor. But it can also be used for heavy duty development
regimens with data models, specifications, development teams working
multiple shifts or working worldwide, separate test-and-release teams,
etc.

On response to the OP:

The most important thing you bring to the table is knowledge of data
formats, algorithms, OO programming, and test-driven design. E.g.,
XML, HTML, LDAP, SQL, pipes, stacks, queues, threads, dictionaries,
lexers, parsers, regular expressions, matrix transformations, GUI
dialogs, etc. Many of us consider Python a secret weapon in learning
new paradigms and technologies

The most important things you need to leave behind:

1. Intuition about what is already available vs what you have to
write. Java tries to reinvent the whole compsci world. Python just
says "Nice C/C++/FORTRAN library; I think I'll use it via a binding."
If it is codable, it is probably scriptable in Python.

2. Temptation to reinvent entire stacks of libraries to replicate the
Java module import structure. This is a real problem in migrating
existing code. You have to take deep breath and ask "What is the
fundamental task, and how would a programmer do that in Python?"
Entire library trees melt away when you do this.

3. Fear you are missing something when you get done. Python takes
c. 1/3 as many LOC as Java for the same task. At first I kept saying:
"This wee bit of code couldn't posssibly do the whole job, could it?"
If you have a good regression test suite, you are done when it works.
If you need help getting on board unittests, see mkpythonproj:
http://www.seanet.com/~hgg9140/comp/index.html#L006
 
B

bruno at modulix

Lawrence said:
Using subclassing when you don't have to. For instance, you might have a
Java method which takes an argument of type java.io_OutputStream to
which it writes. You might translate this to a Python method to which
you are careful to only pass instances of subclasses of file objects.
But in fact there is no necessity for this: you are free to pass any
object which has appropriate members.

I suppose this is an instance of the more general rule: "using OO when
you don't have to".

Lawrence, I'm afraid you're confusing OO with "statically-typed
class-based". FWIW, dynamic typing is part of OO since Smalltalk.
 
G

gene tani

Ant said:
Take a look at the newgroup archives over the last week or two - there
seem to have been a glut of people coming from Java to Python and
asking the same sort of questions. There were some links to a bunch of
Python 'gotcha' pages which will be useful.

Here's a few gotchas which i would like to drop into the python wiki,
but I couldn't find an appropriate place. Maybe the Intermediate
Conundrums page?
Anyway, if OP take the time to flip through these, it'll speed the
learning, I hope.

http://www.ferg.org/projects/python_gotchas.html
http://zephyrfalcon.org/labs/python_pitfalls.html
http://zephyrfalcon.org/labs/beginners_mistakes.html
http://www.python.org/doc/faq/
http://wiki.python.org/moin/Intermediate_Conundrums

http://diveintopython.org/appendix/abstracts.html
http://diveintopython.org/appendix/tips.html

http://blog.ianbicking.org/my-python-4k.html

http://www.onlamp.com/pub/a/python/2004/02/05/learn_python.html
http://www.norvig.com/python-iaq.html
http://www.faqts.com/knowledge_base/index.phtml/fid/245

http://amk.ca/python/writing/warts
http://c2.com/cgi/wiki?PythonProblems
 
M

Mike Orr

I don't think they exist. Such books are targeted more towards
development in a corporate environment, where every proposal has to go
through multiple layers of management, and nothing is ever done by
individuals working alone, always by "teams" working on separate parts
of the project

Hey, patterns are important. They keep people from reinventing the
wheel and banging their head against the wall. Perhaps the best source
for Python patterns is the Python Cookbook.
http://www.oreilly.com/catalog/pythoncook/
http://aspn.activestate.com/ASPN/Python/Cookbook/
I recommend at least going through the table of contents so you'll know
where to go when you're wondering, "How do I do X in Python?"

--Mike
 
L

Lawrence D'Oliveiro

"gene tani said:

Amazing. Backslashes are listed as not one, but _two_ items on the list.

The problem is not with Python at all, it is with the MS-DOS foundations
of Windows. When directory hierarchies were added in DOS 2.0, they used
the wrong character, "\" instead of "/", as the directory separator.

I call this "DOSLexia", and it has afflicted DOS/Windows users ever
since.
 
L

Lawrence D'Oliveiro

bruno at modulix said:
Lawrence, I'm afraid you're confusing OO with "statically-typed
class-based". FWIW, dynamic typing is part of OO since Smalltalk.

I wasn't talking about dynamic typing, I was talking about subclassing,
which is very much a part of OO.

Unless you subscribe to the "OO is whatever looks like a good
programming idea" definition <http://www.paulgraham.com/reesoo.html>.
 
L

Lawrence D'Oliveiro

"Mike Orr said:
Hey, patterns are important. They keep people from reinventing the
wheel and banging their head against the wall.

If you have to write more than one piece of code from the same
"pattern", then that _is_ "reinventing the wheel and banging their head
against the wall."

The correct way to avoid reinventing the wheel is to reuse code.

For example, in the OO world you hear a good deal about "patterns".
I wonder if these patterns are not sometimes evidence of ...
the human compiler, at work. When I see patterns in my programs, I
consider it a sign of trouble. The shape of a program should reflect
only the problem it needs to solve. Any other regularity in the code
is a sign, to me at least, that I'm using abstractions that aren't
powerful enough....

-- Paul Graham <http://www.paulgraham.com/icad.html>
 
B

bruno at modulix

Lawrence said:
I wasn't talking about dynamic typing, I was talking about subclassing,
which is very much a part of OO.

What you wrote implies (well, at least I understand it that way) that
polymorphic dispatch *not* based on subclassing is not OO. Hence my
reaction : the need to use subclassing (inheritance) for subtyping
(polymorphic dispatch) is not a requirement of object orientation and
has never been - it's only a limitation of languages with declarative
static typing (C++, Java, C# etc).
Unless you subscribe to the "OO is whatever looks like a good
programming idea" definition <http://www.paulgraham.com/reesoo.html>.

Not really !-)
 
T

ToddLMorgan

Thanks for those ... just by looking at the colour of the links in my
browser I'd only found 4 of those already so I appreciate the heads up
:- )
 
L

Lawrence D'Oliveiro

bruno at modulix said:
What you wrote implies (well, at least I understand it that way) that
polymorphic dispatch *not* based on subclassing is not OO. Hence my
reaction : the need to use subclassing (inheritance) for subtyping
(polymorphic dispatch) is not a requirement of object orientation and
has never been - it's only a limitation of languages with declarative
static typing (C++, Java, C# etc).

It's nothing to do with OO, because it's also present in non-OO
languages.
Not really !-)

One would hope not.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top