an example of beautiful code.
this was a result of top down design. IE high level routines fist, lowest level routines last.
first, the algo was written in comments in english.
then the highest level code was written, defining the lower level routines and their APIs as it was written, before ever actually defining the lower level code. so the high level code determined that there would be a camera_can_see_target function, and that it would take the index of a target as a parameter. the actual camera_can_see_target function was written later. the high level code defined what the lower level APIs would be. the highest level code was written to be as english-like as possible.
this is the high level code that started this process (from SIMSpace 8.0):
void draw_targets(){// for each target, if in vis rng and pass frustum cull, add to render queue// vis rng = 100x tgt size = 200x tgt.radint a;for (a=0; a
clarity, simplicity, and read-ability are hallmarks of beautiful code.
I'm not convinced this is beautiful code, and here's why:
Declaration and initialization on two separate lines is unnecessary in this case. In fact, declaring "int a" there is completely unnecessary as that value will always be (MAXTGTS - 1) following the end of that loop unless one of those methods secretly modifies it.
Writing code like this becomes unreadable quick.
I'm not sure what sstgt means. Also, you're iterating through an entire array of objects despite some of them (likely) being inactive, and thus, ignored.
There's some duplicate code here.
I'm hoping that this method is nested inside a class. Otherwise it means you've throwing around globals. Though perhaps I'm missing something here. Can you elaborate on your methods?