/* jquery */ /* jquery accordion style*/ /* jquery init */

Learn Python - Program Structure

So far all our programs have had a simple flow, from top to bottom. While this is fine for small examples, as soon as programs become longer and more complex, things tend to become more difficult.

One common problem is it becomes more difficult to recall what each section of code actually does. Even with plenty of comments you'll spend lots of time scrolling up and down the source to identify the pieces to change or extend. The end result is a long program listing that's difficult to read and prone to bugs.

Another issue is that you may see very similar pieces of code repeated. Obviously, this isn't an efficient way of programming. Even more importantly, the more code you write the more errors are likely to be introduced, and the more bugs you'll have to find and fix.

A far better approach is to break the solution down into a series of identifiable elements. Each element can be designed and coded in isolation.

A post from my Learn Python on the Raspberry Pi tutorial.