|
Posted by ^reaper^ on 08/28/05 18:30
While sipping absinthe, Onideus Mad Hatter heard a loud sucking noise
coming from alt.2600, and hastily inscribed the following unintelligible
Sanskrit in <news:jdq1h11msdruo1cf5iftvtabkrgiqk64e2@4ax.com>:
> On Sat, 27 Aug 2005 12:13:51 -0700, "^reaper^" <knocking@deaths.door>
> wrote:
>>code optimization involves making logic changes (that cannot be handled by
>>a compiler or interpreter) to reduce computes that may (or not) result in
>>a reduction of lines of code.
>
> Every single [blah blah blah]
>>For example, ordering and/or nesting decision blocks. Replacing unnecessary
>>iteration with direct access calls. Using recursion for node walking.
>>Instantiating arrays with predicted lengths. Passing variables by
>>reference. Declaring local variables immediately before they're used. Using
>>try/catch blocks for edc. Using regex for complex pattern matching or when
>>testing for multiple patterns. Balancing binary trees. Using bit masking
>>for setting and checking states. And most importantly, pulling your head
>>otter your ass when coding so your proggie doesn't end up looking,
>>smelling, and running like a pos.
>
> My code run [blah blah blah]
For all that posturing, you certainly write a whole lot of nothing. Let's
take a look at "your code" and apply /just one/ of the above optimizations
that (idiot that you are) have to do with rudimentary coding principles and
/not/ object orientation.
:var detect = navigator.userAgent.toLowerCase();
:var OS,browser,version,total,thestring;
In the following decision tree, you stupidly order the decision blocks from
least to most common thereby forcing the client app to execute unnecessary
code. To wit.
:if (checkIt('konqueror'))
:{
: browser = "Konqueror";
: OS = "Linux";
:}
:else if (checkIt('safari')) browser = "Safari"
:else if (checkIt('omniweb')) browser = "OmniWeb"
:else if (checkIt('opera')) browser = "Opera"
:else if (checkIt('webtv')) browser = "WebTV";
:else if (checkIt('icab')) browser = "iCab"
:else if (checkIt('msie')) browser = "IE"
~78% of your clients' apps are required to execute 40 unnecessary
statements before breaking out of the decision tree
:else if (checkIt('firefox')) browser = "Firefox"
~20% of your clients' apps are required to execute 35 unnecessary
statements before breaking out of the decision tree
:else if (!checkIt('compatible'))
:{
: browser = "Netscape Navigator"
: version = detect.charAt(8);
:}
:else browser = "An unknown browser";
You could simply set your 'browser' variable to an empty string since you
do not test for the string, 'An unknown browser'
:if (!version) version = detect.charAt(place + thestring.length);
You never test for version, so why are you doing this? In fact, since you
only test for windows, mac, and ie, you should be using booleans.
You stupidly do the same thing in this decision tree (least to most
common).
:if (!OS)
:{
: if (checkIt('linux')) OS = "Linux";
: else if (checkIt('x11')) OS = "Unix";
: else if (checkIt('mac')) OS = "Mac"
: else if (checkIt('win')) OS = "Windows"
: else OS = "an unknown operating system";
:}
~99% of your clients' apps will test true, since you only set the OS
variable for 'Konqueror'. Of those ~72% will be required to execute 15
unnecessary statements.
:function checkIt(string)
:{
: place = detect.indexOf(string) + 1;
: thestring = string;
: return place;
:}
At a /minimum/, 70% of your clients' apps will be required to execute 40
unnecessary statements. Which, excluding the obvious, could have just as
easily been accomplished in 4 statements by doing one of two things. Set up
3 boolean flags by testing for windows, mac, and ie. Or, if you feel
compelled to test for /all/ of the above, use regex. And yes, ECMAScript
supports regex, you flaming retard.
You, of course, didn't stop here. You went for the gold and implemented the
very same inanity in your flash, only by more than an order of magnitude.
For example, in /just one/ ActionScript alone, you have a thousand line
decision tree. Exluding the 2M xfer latency factor, and in light of the
fact that your flash contains several such ActionScripts, thereby forcing
the client app to execute several thousands of lines of code (of which over
half is unnecessary), it is _no big suprise_ people are seeing between 2
and 5 minute load times.
Btw, I checked out that other bit of stupidity. You know, this?
http://www.fatorcaos.com.br/flash5tests/speed_1.html
The guy's so-call /perf test/ introduces confounds, rendering his results
invalid and therefore worthless.
That said. Thanks for playing and being ever predictable by volunteering
for this little demo on how /not/ to write code (while at the same time
demostrating why your flashingly brilliant idea sucks teh big kahuna). ^_~
--
^reaper^
[Back to original message]
|