Re: Efficient programming
by CountZero (Bishop) on Dec 22, 2008 at 07:06 UTC
|
Let's look at your requirements:
CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
| [reply] |
Re: Efficient programming
by tilly (Archbishop) on Dec 22, 2008 at 09:06 UTC
|
The path to mastery is an ancient node of mine that may shed some light on this. I would also recommend picking up Code Complete 2 and actually reading the whole thing. (Rather than, say, using it as a doorstop.) It is not bout Perl, but its advice pertains to programming Perl as well as any other language. | [reply] |
Re: Efficient programming
by monarch (Priest) on Dec 22, 2008 at 06:37 UTC
|
Ah, grasshopper, you seek knowledge, but the time is not yet right to reveal this to you. First, you must learn patience!
Meditate upon this now..
Update: I should explain this comment: I believe all programmers seek to write the most optimal code, it is utopia! But it is a quest that takes us our natural lives and enlightenment comes with study and practice. The question being asked, i.e. how to do this in Perl, can be partially answered by learning any computer language (as others have mentioned below about gaining wisdom of algorithms and such). And specific understanding of efficiency in Perl can be gained by studying and utilising Perl itself - there are many such routes, including reading the Camel book, reading much of PerlMonks, and studying the source code of Perl itself!
And so patience is required because the road is long.. take some initial steps and read as much as you can.
| [reply] |
Re: Efficient programming
by ikegami (Patriarch) on Dec 22, 2008 at 06:48 UTC
|
Efficient programs come from efficient algorithms. You'd best search for material on algorithms.
| [reply] |
|
OTOH, "Data dominates. If you've chosen the right data structures and organized things well, the algorithms will almost always be selfevident. Data structures, not algorithms, are central to programming." (Rob Pike Notes on Programming in C)
As for the OP, "efficient" is a buzzword. Make your programming simple, concise, clear, and correct. For some simple guidelines, try that URL I pasted above, it's the best article about programming practices I know.
| [reply] |
|
| [reply] |
|
| [reply] |
Re: Efficient programming
by eye (Chaplain) on Dec 22, 2008 at 07:49 UTC
|
The section on "Efficiency" in Chapter 24 of Programming Perl (3rd ed) has some terse suggestions on how to achieve various types of efficiency. | [reply] |
Re: Efficient programming
by jplindstrom (Monsignor) on Dec 22, 2008 at 13:44 UTC
|
| [reply] |
Re: Efficient programming
by nagalenoj (Friar) on Dec 22, 2008 at 09:48 UTC
|
| [reply] |
Re: Efficient programming
by dragonchild (Archbishop) on Dec 22, 2008 at 21:52 UTC
|
To hop on board what everyone else is saying, evaluate in the following order:
- Does it work? If not, make it work first.
- Does it run fast enough? If so, stop. Fast enough is determined by need. If it's a batch job, then 8 hours may be fast enough. On the web, anything under 3-5 seconds is fast enough. If you need faster than 0.1s, you're probably using the wrong tools (i.e., Perl isn't the right language).
- If it needs to be faster, then find a better algorithm. Look at CPAN.
- If the right algorithms is in use, find a better implementation. Look at CPAN.
- If all else fails, ask here.
For the record, this is the exact set of steps I use and have used for over 7 years.
My criteria for good software:
- Does it work?
- Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
| [reply] |
Re: Efficient programming
by hangon (Deacon) on Dec 22, 2008 at 19:06 UTC
|
The key is to start out with a clear understanding of what you are trying to do. Otherwise you may end up writing a lot of unnecessary code and having to try to optimize it away later.
What works for me (YMMV) is to start with a pencil & notepad to sketch out the specs, data structures, api and jot down any other relevant information, then outline and refine the program in pseudocode. From there I'll code any algorithms and complex logic independently to work them out. Only then will I start coding the main program.
| [reply] |