Thursday, May 17, 2012

Coding tip for those copy and pasted fields

You know how the first paste gets you the same field name with an underscore and number added to it?  I have seen some really ugly code when someone wants to programmatically iterate over all the fields.  Things like checking a counter, or one time processing for the first field and then a loop for the rest of the fields.  All of this can be greatly simplified if you just go back to the first field and add an underscore and zero to the name.

So

Product
Product_1
Product_2

becomes

Product_0
Product_1
Product_2

etc.  Now you just loop through all fields starting with zero.  And if you come across this in an existing application, use a tool like scanEZ from Ytria to change all the existing douments.  It is well worth the time for this simple fix.


No comments:

Post a Comment