Welcome to WebProNews Breaking eBusiness and Search News
Advertise | Newsletter | Sitemap | News Feeds News Feed 
 WebProNews Search Part of the iEntry network iEntry inc. 

The Hidden Loop

A.P. Lawrence
Expert Author
Published: 2006-09-18

WebProNews RSS Feed


Programmers use loops to avoid writing repetitive code, but sometimes forget that compilers will unroll their loops when possible for efficiency.

You can unroll your own loops, too. Rather than testing and branching, the code is sequential: (pseudocode) "for (x=1;x<5;x++);print x;next" becomes "print '1 2 3 4 5'.

Of course looping code is almost always quicker to write and easier to understand and modify in the future, but it's not ideal for efficiency. Testing and branching takes time; if you need flat out performance, you avoid loops where possible.

But that's not the only reason to unroll a loop. Yesterday I needed to write a Filepro processing table to export a CSV dump of all the database fields. I could have written that with a loop, but instead I ended up with code that looks like this:

::f(1,*,g);no(3,.0):
::export Word stat=all.csv:
:f eq "":gosub header;f="1":
::stat(1)=1
::stat(2)=2
::stat(3)=3
... (omitted code)
::stat(318)=318
::end

header::stat("1")="Date Entered"
::stat(2)="Order/Inv Number"
::stat(3)="Order Date"
... (omitted code)
::stat(318)="Xtra foo""
::write;return


Even if you don't grok Filepro's strange looking code, you can probably get the concept here. I'm apparently doing a lot of hard work that could more easily be done in a loop, right?

Well, yes, but not in this case. And it actually was done in a loop.

That is, I didn't hand write all this. I created it with a Perl script that read the database "map" file to get field names, and that of course used a loop. So creating this code was simple and easy. But why do it that way? Surely performance wasn't the issue?

No, of course not. The issue was that a non-programmer needs to modify this code. He needs to take out fields he doesn't want, relabel some fields to make more sense to the ultimate consumer, and possibly rearrange the order of some fields for the same reason. Programming that in a loop is possible, but it gets messy very quickly. By giving him individual lines, he can pick and choose what he wants easily.

*Originally published at APLawrence.com

Add to Del.icio.us | Digg | Yahoo! My Web | Furl

Bookmark WebProNews:

Receive Our Daily Email of Breaking eBusiness News


About the Author:
A.P. Lawrence provides SCO Unix and Linux consulting services http://www.pcunix.com

WebProNews RSS Feed

More Expert Articles Articles

Contact WebProNews
Advertisement





TOP NEWS

Targeted Information for Business
WebProNews is part of the iEntry network

Internet Business: Marketing: Small Business:
WebProNews MarketingNewz SmallBusinessNewz
WebProWorld AdvertisingDay PromoteNews
EcommNewz SalesNewz EntrepreneurNewz

Software: Search Engines: Web Design:
WebMasterFree Jayde B2B DesignNewz
NetworkingFiles SearchZA FlashNewz
SecurityConfig SearchNewz WebSiteNotes

Developer: IT Management: Security:
DevWebPro ITManagement SecurityProNews
DevNewz SysAdminNews SecurityConfig
TheDevWeb NetworkingFiles NetworkNewz

The iEntry Network consists of over 100 web publications reaching millions of Internet Professionals. Contact us to advertise.
eBUSINESS RESOURCES






 Advertise | Contact Us | Corporate | Newsletter | Sitemap | Submit an Article | News Feeds
 WebProNews is an iEntry, Inc. ® publication - $line) { echo $line ; } ?> All Rights Reserved
About WebProNews
WebProNews is the number one source for eBusiness News. Over 5 million eBusiness professionals read WebProNews and other iEntry business and tech publications.

WebProNews provides real-time coverage of internet business.

Free Email Newsletters:
WebProNews SearchNewz
WebProWorld DevWebPro
Marketing SecurityNews
Plus over 100 other newsletters!

Send me relevant info on products and services.


WebProWorld
Ten most recent posts.

NetworkingFiles
Featured Software

WebProNews in the News
View all recent mentions of WebProNews from around the world!

Recent Articles On ...
Google eBusiness
Yahoo Ask Jeeves
MSN Blogs
Search Engines Blogging
Affiliate Programs Marketing
eCommerce Advertising
eBay Sun Microsystems
AOL Adsense
Microsoft Adwords
Oracle IBM
Amazon Apple
SEM Mac
SEO iPod
Adsense XBox
PR Adobe



iEntry.com WebProWorld RSS Feed WebProWorld Contact WebProNews Print Version Email a friend Bookmark us