How can I use Python for large scale development?

user31157 picture user31157 · Oct 25, 2008 · Viewed 18k times · Source

I would be interested to learn about large scale development in Python and especially in how do you maintain a large code base?

  • When you make incompatibility changes to the signature of a method, how do you find all the places where that method is being called. In C++/Java the compiler will find it for you, how do you do it in Python?

  • When you make changes deep inside the code, how do you find out what operations an instance provides, since you don't have a static type to lookup?

  • How do you handle/prevent typing errors (typos)?

  • Are UnitTest's used as a substitute for static type checking?

As you can guess I almost only worked with statically typed languages (C++/Java), but I would like to try my hands on Python for larger programs. But I had a very bad experience, a long time ago, with the clipper (dBase) language, which was also dynamically typed.

Answer

e-satis picture e-satis · Oct 25, 2008

Don't use a screw driver as a hammer

Python is not a statically typed language, so don't try to use it that way.

When you use a specific tool, you use it for what it has been built. For Python, it means:

  • Duck typing : no type checking. Only behavior matters. Therefore your code must be designed to use this feature. A good design means generic signatures, no dependences between components, high abstraction levels.. So if you change anything, you won't have to change the rest of the code. Python will not complain either, that what it has been built for. Types are not an issue.

  • Huge standard library. You do not need to change all your calls in the program if you use standard features you haven't coded yourself. And Python come with batteries included. I keep discovering them everyday. I had no idea of the number of modules I could use when I started and tried to rewrite existing stuff like everybody. It's OK, you can't get it all right from the beginning.

You don't write Java, C++, Python, PHP, Erlang, whatever, the same way. They are good reasons why there is room for each of so many different languages, they do not do the same things.

Unit tests are not a substitute

Unit tests must be performed with any language. The most famous unit test library (JUnit) is from the Java world!

This has nothing to do with types. You check behaviors, again. You avoid trouble with regression. You ensure your customer you are on tracks.

Python for large scale projects

Languages, libraries and frameworks don't scale. Architectures do.

If you design a solid architecture, if you are able to make it evolves quickly, then it will scale. Unit tests help, automatic code check as well. But they are just safety nets. And small ones.

Python is especially suitable for large projects because it enforces some good practices and has a lot of usual design patterns built-in. But again, do not use it for what it is not designed. E.g : Python is not a technology for CPU intensive tasks.

In a huge project, you will most likely use several different technologies anyway. As a SGBD (French for DBMS) and a templating language, or else. Python is no exception.

You will probably want to use C/C++ for the part of your code you need to be fast. Or Java to fit in a Tomcat environment. Don't know, don't care. Python can play well with these.

As a conclusion

My answer may feel a bit rude, but don't get me wrong: this is a very good question.

A lot of people come to Python with old habits. I screwed myself trying to code Java like Python. You can, but will never get the best of it.

If you have played / want to play with Python, it's great! It's a wonderful tool. But just a tool, really.