On Thursday 26 April 2007 07:28, Melchior FRANZ wrote: > * alexis bory -- Wednesday 11 April 2007: > > toggle_traj_mkr = func { > > + if(getprop("/ai/submodels/trajectory-markers") == nil) { > > + setprop("/ai/submodels/trajectory-markers", 0); > > + } > > if(getprop("ai/submodels/trajectory-markers") < 1) { > > setprop("ai/submodels/trajectory-markers", 1); > > } else { > > setprop("ai/submodels/trajectory-markers", 0); > } > } > > > Eeew. What an ugly and verbose way of saying just > > > var toggle_traj_mkr = func { > var p = "/ai/submodels/trajectory-markers"; > setprop(p, !getprop(p)); > } > > > Fortunately, nobody committed that ... to several aircraft ... :-} > > m.
Hi Melchior, I've got to confess that I have always tended to write simple but verbose code on the basis that the the simplicity should make human misinterpretation less likely and the verbosity is only in the /source/ code - the compiler will optimise it in the object executable. Of course, in this case, the code here is interpreted so I'm not sure what the effect will be on performance. Another thing about that particular code snippet is that it is resilient insofar as it ensures correct data values whereas the technique you suggest relies upon a valid value in the node to work - if it gets corrupted the function may not work or may be unpredictable. There are two sides to this, of course:) If the value is getting corrupted then this could be masked by the original code, as it explicitly writes correct values but the code you suggest will fail if the value is corrupt and will hi-light the underlying problem. I guess that including validation of data in each function would be a good idea but once again, I don't know what sort of performance hit that would cause. LeeE ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel