|
Original |
Translation |
|
17
|
In *The Mythical Man-Month*, Fredrick Brooks suggests the following rule when planning software projects: "Plan to throw one away; you will anyway." Brooks is saying that the first attempt at a software design often turns out to be wrong; unless the problem is very simple or you're an extremely good designer, you'll find that new requirements and features become apparent once development has actually started. If these new requirements can't be cleanly incorporated into the program's structure, you're presented with two unpleasant choices: hammer the new features into the program somehow, or scrap everything and write a new version of the program, taking the new features into account from the beginning.
|
|
|
18
|
Python provides you with a good environment for quickly developing an initial prototype. That lets you get the overall program structure and logic right, and you can fine-tune small details in the fast development cycle that Python provides. Once you're satisfied with the GUI interface or program output, you can translate the Python code into C++, Fortran, Java, or some other compiled language.
|
|
|
19
|
Prototyping means you have to be careful not to use too many Python features that are hard to implement in your other language. Using ``eval()``, or regular expressions, or the :mod:`pickle` module, means that you're going to need C or Java libraries for formula evaluation, regular expressions, and serialization, for example. But it's not hard to avoid such tricky code, and in the end the translation usually isn't very difficult. The resulting code can be rapidly debugged, because any serious logical errors will have been removed from the prototype, leaving only more minor slip-ups in the translation to track down.
|
|
|
20
|
This strategy builds on the earlier discussion of programmability. Using Python as glue to connect lower-level components has obvious relevance for constructing prototype systems. In this way Python can help you with development, even if end users never come in contact with Python code at all. If the performance of the Python version is adequate and corporate politics allow it, you may not need to do a translation into C or Java, but it can still be faster to develop a prototype and then translate it, instead of attempting to produce the final version immediately.
|
|
|
21
|
|
22
|
This is a very common use for Python. Past conference papers have also described this approach for developing high-level numerical algorithms; see David M. Beazley and Peter S. Lomdahl's paper "Feeding a Large-scale Physics Application to Python" in the references for a good example. If an algorithm's basic operations are things like "Take the inverse of this 4000x4000 matrix", and are implemented in some lower-level language, then Python has almost no additional performance cost; the extra time required for Python to evaluate an expression like ``m.invert()`` is dwarfed by the cost of the actual computation. It's particularly good for applications where seemingly endless tweaking is required to get things right. GUI interfaces and Web sites are prime examples.
|
|
|
23
|
The Python code is also shorter and faster to write (once you're familiar with Python), so it's easier to throw it away if you decide your approach was wrong; if you'd spent two weeks working on it instead of just two hours, you might waste time trying to patch up what you've got out of a natural reluctance to admit that those two weeks were wasted. Truthfully, those two weeks haven't been wasted, since you've learnt something about the problem and the technology you're using to solve it, but it's human nature to view this as a failure of some sort.
|
|
|
24
|
Simplicity and Ease of Understanding
|
|
|
25
|
Python is definitely *not* a toy language that's only usable for small tasks. The language features are general and powerful enough to enable it to be used for many different purposes. It's useful at the small end, for 10- or 20-line scripts, but it also scales up to larger systems that contain thousands of lines of code.
|
|
|
26
|
However, this expressiveness doesn't come at the cost of an obscure or tricky syntax. While Python has some dark corners that can lead to obscure code, there are relatively few such corners, and proper design can isolate their use to only a few classes or modules. It's certainly possible to write confusing code by using too many features with too little concern for clarity, but most Python code can look a lot like a slightly-formalized version of human-understandable pseudocode.
|
|