[Tutor] Moving from snippits to large projects?
Steven D'Aprano
steve at pearwood.info
Mon Jan 9 11:31:34 CET 2012
Leam Hall wrote:
> I'm taking the O'Reilly Python 2 course on-line, and enjoying it. Well,
> when Eclipse works, anyway. I'm still getting the hang of that.
>
> While my coding over the years has been small snippits in shell, PHP,
> and a little C, python, and perl, I've never made the transition from
> dozens of lines to hundreds or thousands. I'd like to start working on
> that transition but the projects I know about are much larger than my
> brain can handle and there are a lot of other corollary tools and
> practices to learn.
>
> How does one go from small to medium, to large, as a coder? Large
> projects, that is.
Pick something useful which you would like. Write the program. That might be a
few dozen lines.
Stage 2: pretend that other people will use it, people who don't know how it
is supposed to work, so put in plenty of error checking. Before you know it,
you've got 100-200 lines of code.
Then add documentation. There's another 200-400 lines. (Except for the most
trivial programs, in my experience documentation will be about double the size
of the code you are documenting, at least the way I write it, with plenty of
detail and examples.)
Now write extensive tests for it. Ideally, you should test every function and
class in the program. You should test that it works as expected with good
input, and fails as expected with bad input. That's another 400-800 lines. (In
my experience, proper testing will be at least four times as big as the code
you are testing.)
And lo and behold, you now have a medium-sized project. A *large* project will
be tens of thousands of lines, not hundreds. A *major* project will be
millions of lines.
Here's an example: I wrote a script to download images from the Quickmeme
website. http://www.quickmeme.com/Web-Developer-Walrus/
Even without moving onto stage 2, I have 120 lines of code and documentation.
If I were to continue to work on it, I'd start adapting the script to be more
generic. Turn it a general purpose "download anything from anywhere" library
(a bit like wget or curl, for those who know those tools). Off the top of my
head, I expect that would require 500-1000 lines of Python code and
documentation. Plus tests.
--
Steven
More information about the Tutor
mailing list