MikeJarosz
2007-02-27, 10:22 PM
I posted a similar memo on the Mrs. Peel thread that I would like to open to a wider discussion.
I have in the past worked in FORTRAN, Cobol, Basic, Unix, and a little bit of C, not to mention two assembly languages. In all of them, it was considered bad practice to put non executable statements or simple assignments inside of a loop. Example:
'area of a circle
For Radius = 1 to 1000
PI = 3.14159
Area = PI * Radius * Radius
debug.print Radius; tab; Area
next Radius
In the above code, PI is assigned 1000 times, when it only needs to be done once before starting the loop.
I've been learning the Revit API by dissecting the sample code provided by Autodesk. Almost every VB.NET example loops through the elements collection testing for certain conditions. When the condition is met, the code repeatedly does a DIM to explicitly create a new variable. Since this is in the elements collection loop, on a decent sized drawing, this could be thousands of cycles.
I mention this because I am assuming that the professional programmers at Autodesk know better than I about the inner workings of Revit API and MS VB.NET and the best way of doing things. Could it be that the Basic compiler is so much more sophisticated that the old rules of style don't matter anymore?
One other conflicting rule of scope was to DIM a variable as close to where it is first used instead of the top of the program, so the reader can easily locate the definition. Could this be what Autodesk programmers are doing?
I took the code for room data and rearranged it with the DIM statements outside of the loops. It worked OK and it seemed a bit faster. Will this make me look like a provincial peasant to the slick guys at the factory?
I just had one last thought. Maybe programming practices like this are why Revit can be so slow at times!
I have in the past worked in FORTRAN, Cobol, Basic, Unix, and a little bit of C, not to mention two assembly languages. In all of them, it was considered bad practice to put non executable statements or simple assignments inside of a loop. Example:
'area of a circle
For Radius = 1 to 1000
PI = 3.14159
Area = PI * Radius * Radius
debug.print Radius; tab; Area
next Radius
In the above code, PI is assigned 1000 times, when it only needs to be done once before starting the loop.
I've been learning the Revit API by dissecting the sample code provided by Autodesk. Almost every VB.NET example loops through the elements collection testing for certain conditions. When the condition is met, the code repeatedly does a DIM to explicitly create a new variable. Since this is in the elements collection loop, on a decent sized drawing, this could be thousands of cycles.
I mention this because I am assuming that the professional programmers at Autodesk know better than I about the inner workings of Revit API and MS VB.NET and the best way of doing things. Could it be that the Basic compiler is so much more sophisticated that the old rules of style don't matter anymore?
One other conflicting rule of scope was to DIM a variable as close to where it is first used instead of the top of the program, so the reader can easily locate the definition. Could this be what Autodesk programmers are doing?
I took the code for room data and rearranged it with the DIM statements outside of the loops. It worked OK and it seemed a bit faster. Will this make me look like a provincial peasant to the slick guys at the factory?
I just had one last thought. Maybe programming practices like this are why Revit can be so slow at times!