By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,965 Members | 787 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,965 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Apr 22 '06 #1
Share this Question
Share on Google+
17 Replies


P: n/a
In article <11**********************@u72g2000cwu.googlegroups .com>,
"ToddLMorgan" <To*********@gmail.com> wrote:
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".
Apr 22 '06 #2

P: n/a
In article <11**********************@u72g2000cwu.googlegroups .com>,
"ToddLMorgan" <To*********@gmail.com> wrote:
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.
Apr 22 '06 #3

P: n/a
ToddLMorgan wrote:
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

Apr 22 '06 #4

P: n/a

http://dirtsimple.org/2004/12/python-is-not-java.html
http://dirtsimple.org/2004/12/java-i...on-either.html
http://dirtsimple.org/2004/12/python...-not-java.html

This link seems to be down at the moment.
http://naeblis.cx/rtomayko/2004/12/1...c-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
On Sat, Apr 22, 2006 at 12:40:51AM -0700, ToddLMorgan wrote:
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

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

Apr 22 '06 #5

P: n/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 ;-)

Apr 22 '06 #6

P: n/a
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/Pyth...avaProgrammers 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/1...c-method-thing with
http://naeblis.cx/rtomayko/2005/01/2...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

Apr 23 '06 #7

P: n/a
Lawrence D'Oliveiro wrote:
In article <11**********************@u72g2000cwu.googlegroups .com>,
"ToddLMorgan" <To*********@gmail.com> wrote:

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".


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

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Apr 24 '06 #8

P: n/a

Ant wrote:
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/2...rn_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

Apr 24 '06 #9

P: n/a
Lawrence D'Oliveiro <ld*@geek-central.gen.new_zealand> writes:
In article <11**********************@u72g2000cwu.googlegroups .com>,
"ToddLMorgan" <To*********@gmail.com> wrote:
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.


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
--
Harry George
PLM Engineering Architecture
Apr 24 '06 #10

P: n/a
Lawrence D'Oliveiro wrote:
"ToddLMorgan" <ToddLMor...@gmail.com> wrote:
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


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

Apr 24 '06 #11

P: n/a
In article <11**********************@i40g2000cwc.googlegroups .com>,
"gene tani" <ge*******@gmail.com> wrote:
http://www.ferg.org/projects/python_gotchas.html


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.
Apr 24 '06 #12

P: n/a
In article <44***********************@news.free.fr>,
bruno at modulix <on***@xiludom.gro> wrote:
Lawrence D'Oliveiro wrote:
In article <11**********************@u72g2000cwu.googlegroups .com>,
"ToddLMorgan" <To*********@gmail.com> wrote:
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".


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>.
Apr 24 '06 #13

P: n/a
In article <11*********************@y43g2000cwc.googlegroups. com>,
"Mike Orr" <sl********@gmail.com> wrote:
Lawrence D'Oliveiro wrote:
"ToddLMorgan" <ToddLMor...@gmail.com> wrote:
>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


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>
Apr 25 '06 #14

P: n/a
Lawrence D'Oliveiro wrote:
In article <44***********************@news.free.fr>,
bruno at modulix <on***@xiludom.gro> wrote:

Lawrence D'Oliveiro wrote:
(snip)
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.

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 !-)

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'on***@xiludom.gro'.split('@')])"
Apr 25 '06 #15

P: n/a
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
:- )

Apr 25 '06 #16

P: n/a
bruno at modulix a écrit :
Lawrence D'Oliveiro wrote:
In article <44***********************@news.free.fr>,
bruno at modulix <on***@xiludom.gro> wrote:
Lawrence D'Oliveiro wrote:

(snip)
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.

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)


.... but I may just have it totally wrong !-)
Apr 25 '06 #17

P: n/a
In article <44***********************@news.free.fr>,
bruno at modulix <on***@xiludom.gro> wrote:
Lawrence D'Oliveiro wrote:
In article <44***********************@news.free.fr>,
bruno at modulix <on***@xiludom.gro> wrote:

Lawrence D'Oliveiro wrote:
(snip)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.

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).


It's nothing to do with OO, because it's also present in non-OO
languages.
Unless you subscribe to the "OO is whatever looks like a good
programming idea" definition <http://www.paulgraham.com/reesoo.html>.


Not really !-)


One would hope not.
Apr 27 '06 #18

This discussion thread is closed

Replies have been disabled for this discussion.