??? 08/03/06 14:49 Read: times |
#121615 - small and readable Responding to: ???'s previous message |
Matthew Barlage said:
I am very interested in seeing how people on this forum go about optimizing their code. I am usual happy that my functions give me the result I want, and take the "If it ain't broke don't fix it" approach.
My approach: try to hold the code small, clean, readable and maintenable. E.g. whenever I detect similiar pieces of code, I try to write a subroutine for it, which was called with different parameters. Or if the same expression was needed on different places, you can try to calculate it once and store the result to use it later. In general I try to avoid copy&paste sequences. Because on later changing of something you forget to change at least one of the pasted pieces (murphys law). There is no code which need no maintenance, exept only such code which was never used. Further optimization can be done on considering, how often a certain task was needed. Then a task can be delayed by a timer to use CPU time for other tasks. Often it can be seen, that the CPU was fully blocked by unimportant tasks. On most cases, if you try to hold code small, then it need also less code space, was executed faster and contain less errors. Peter |