On Tue, May 18, 2010 16:46, Alan Sondheim wrote: > > > I wonder if you've ever looked at books like Andy Oram's Beautiful Code, > which deals with the aesthetics of coding on a deep enough level that I
no... I've bought several programming books over the past few years and most of them have remained unread apart from one or two chapters. > can't follow a lot of it; it's an anthology of experts talking about their > practices (Oram is an editor for O'Reilly and interesting himself). If you > get a chance, take a look; I can't follow all that you write, but it has > the same affect on me. you'll often hear programmers talk about some feature of a language as 'evil', or that that piece of code 'smells'. Even though a C program will 99% of the time compile with a C++ compiler, writing C++ in the same way as you'd write a C program is considered 'evil'. goto is often cited as 'evil' because it makes spaghetti code. you must take these sorts of evangelical preachings with a pinch of salt. there are times when the use of 'goto' can be clearer than purposely not using it. you don't have to use all the features of C++, some people use only just enough of C++ features to make their C code easier to write. james. > - Alan > > > On Tue, 18 May 2010, James Morris wrote: > >> On Tue, May 18, 2010 13:53, James Morris wrote: >> >>> 3) create an 2d array where each element in the array is either a 1 for >>> used space, or a 0 for freespace. searches are performed by inspecting >>> each element in the array. >>> >>> X-( using a char array, only 1 bit out of 8 is used, so for a 128 x 128 >>> array, that's a wastage of 14336 bits (unless my maths is wrong). >>> >>> :-) faster than any other method investigated and quite easy to >>> implement >>> all other placement strategies. >>> >>> >>> 4) create a 2d array much like in 3 but this time directly use the >>> individual bits of whatever data type is used (ie 64/32/16/8 bit >>> types). >>> >>> X-( A PITA to implement, difficult to genericize the placement >>> algorithm, >>> instead left-to-right and right-to-left are two seperate algorithms. >>> >>> :-) faster still, and less memory wastage. >> >> Implementation 3 wins only in terms of code: not only is the row-smart >> algorithm less lines of code AND more straight-forward code at that, but >> the same algorithm (or C function) handles all four permuations of >> placement options: >> >> * left-to-right & top-to-bottom >> * right-to-left & top-to-bottom >> * left-to-right & bottom-to-top >> * right-to-left & bottom-to-top >> >> Implementation 4 wins in terms of execution speed and memory efficiency, >> BUT, the implementation of left-to-right is sufficiently different to >> right-to-left, that to combine the two options would not gain anything >> and >> make the implementation more complex. >> >> The reason 4 wins out in terms of execution speed and memory efficiency, >> (despite more lines of code of greater complexity) is because not only >> are >> there less array elements to inspect, but because C bit-wise operators >> (which are used to inspect and manipulate the array data) often >> translate >> directly into CPU instructions (as opposed to sequences of CPU >> instructions). >> >> >> _______________________________________________ >> NetBehaviour mailing list >> [email protected] >> http://www.netbehaviour.org/mailman/listinfo/netbehaviour >> >> > > > == > email archive: http://sondheim.rupamsunyata.org/ > webpage http://www.alansondheim.org > music archive: http://www.espdisk.com/alansondheim/ > == > _______________________________________________ > NetBehaviour mailing list > [email protected] > http://www.netbehaviour.org/mailman/listinfo/netbehaviour > _______________________________________________ NetBehaviour mailing list [email protected] http://www.netbehaviour.org/mailman/listinfo/netbehaviour
