[Tutor] What is the best approach to organizing the order of functions in a module?

Alan Gauld alan.gauld at btinternet.com
Thu Mar 19 23:04:07 CET 2015


On 19/03/15 21:52, boB Stepp wrote:

> that I feel I need to bring some sort of order to their positioning.
> Currently my best thought is to mimic the natural order, in so far as
> it is possible, in which the functions get called. Are there better
> ways to organize them?

That sometimes works. But if they are data centric another common 
approach is to have

1) initialization/shutdown
2) Create
3) Read
4) Update
5) Delete

The so-called CRUD API.

You can then group functions under those headings
So if you have a bunch of functions for creating things
they go in section 2.

This tends to work very well if using an IDE/Editor that
supports code folding.

Its also a good migration towards OOP since the data entities tend
to become classes andthe CRUD functions become the methods of those 
classes - at least as a first iteration.

Yet another option, especially for Web apps is to adopt the
RESTful approach and group functions under those prionciples.
Very similar to CRUD just more http oriented than data.


http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list