Prev: Dynamic iframe caching problem workaround needed for Firefox
Next: JavaScript code mangler / scrambler / ... khm, more than obfuscator... :)
From: Dmitry A. Soshnikov on 9 Jan 2010 08:20 On Jan 9, 2:18 am, Garrett Smith <dhtmlkitc...(a)gmail.com> wrote: > Dmitry A. Soshnikov wrote: > > On Jan 8, 1:34 am, Garrett Smith <dhtmlkitc...(a)gmail.com> wrote: > > > [snip useless (talk === demagogy)] > > >> Why do you want to modify built-ins' or other objects? > > > Maybe want, maybe not - by situation. And if, then because of ideology > > (come on, you should again ask: "What ideology?" - well, try to think > > and understand it, if will be hard, please ask, I explain completely, > > though, I've already explained) and because of that it's useful > > syntactic sugar which is provided by the authors. > > > I can do that, or cannot - by situation. In one project when I have > > own framework - I can do everything (including simply augmentation of > > the built-ins), in other project (e.g. the current one, when ExtJS is > > used) - we don't modify built-ins because ExtJS can do it also > > (although, ExtJS does it in a strange way - something it does > > augmenting built-ins, something - in own deep namspace). > > > Technically there's no difference: > > > capitalize(string); > > > or > > > string.capitalize(); > > > Moreover, `capitalize(string)' is shorter on one dot - ".", but it's > > not your case ;) > > > Thought, even technically `string.capitalize()' in theory should be > > resolved faster than global `capitalize(string)' and in own deep > > namespace such as `Ext.util.Format.capitalize()'. > > >>> Please answer, which problems will I have if I: > >>> (a) had own implementation of .trim' and used it as string '.trim() > >>> (b) then switch to built-in implementation and use it in the same way > >> The only problem in that particular usage pattern is a minor performance > >> penalty. > > > Excuse me? Did I understand correctly that you said that new built-in > > implementation will have minor performance when I switch on it from > > the own `trim' implementation that I used before? Or it's just already > > trolling is started (not even demagogy)? > > I take you have believe that your hand-rolled trim will not be slower > than native trim. That would be a very inefficient native > implementation, to perform slower, no? Did you test your beliefs? > > Fine; I guess you did not test, but believe like everything else that > you are ultimately correct. > > I set up a test case. > > Not all readers will have the foresight to see potential problems of > modifying foreign objects. However, most should be able to compare two > times and determine that the larger time means slower performance. > > I've set up a test function that uses your hand-rolled "trim" method > renamed to "dcTrim" and compared the performance of that method (as > `String.prototype.dcTrim`), to native `trim` (`String.prototype.trim`). > > // Your (Crockford's) hand-rolled function. > String.prototype.dcTrim = function(){ > return this.replace(/^\s+|\s+$/g, ""); > > }; > > // Names of trim functions to test. > var trimNames = ["trim", "dcTrim"]; > > /* Accepts a name of a function to use for trimming, as in: > * stringArray[0][trimName](); > * and logs the result to the console. > */ > function testTrim(trimName){ > // populate an array of strings > var data = [], > LEN = 1000000; > data.length = LEN; > > // Populate an array of data with unique strings that need trimming. > for(var i = 0; i < LEN; i++) { > data[i] = " \t \t new test " + (Math.random() * i) + " \t \t "; > } > > // Trim the strings in the data. > var startTime = +new Date; > for(i = 0; i < LEN; i++) { > data[i] = data[i][trimName](); > } > var totalTime = new Date-startTime; // end time. > > // Get the next test in trimNames. > var next = trimNames.pop(); > console.log(trimName + ": " + totalTime); > if(next) > setTimeout("testTrim('" + next + "')", 500); > > }; > > void setTimeout("testTrim('" + trimNames.pop()+ "')", 500); > > Results in Firefox 3.5: > > dcTrim: 7027 > trim: 2307 > > The native the user-defined "dcTrim" performed three times slower. > Since you won't normally trim that many strings, you won't be saving 5 > seconds. That is why I fairly called it a "minor performance penalty". > > I think it's clear now that your name calling (troll) is either very > short-sighted or is a desperate attempt to win the argument (so much for > the "truth"). > > >> Why would you want to use a hand-rolled version that doesn't behave as > >> standard? > > > I don't understand again - is it trolling or is it kind of > > "privileged" humor? Did I understand correctly that you switch my (b) > > and (a)? For what? If I've told - first (a), then (b). > > I've asked for your motivation of why you prefer using a hand-rolled > trim over the native. Trying to get you to write code is like pulling teeth. > > > [snip useless talk] > > >>> Who is here ignoring the known consequences? > >> You. Crockford. Probably others. > > > Excuse me? > > > [snip useless talk] > > You've shown 0 good examples of your ideology put to practice (no code). > > I've shown problems with programs that modifying objects they don't own. > > Your arrogance isn't justified any more than that of "The world's > foremost authority on javascript" (that is what he calls himself, you know). > > >> Why do yo want to replace built-in function with your own? > > > I can't believe this (that's already not even funny ;), so no points > > for you). It's already trolling but not demagogy. Again (please pay > > maximum attention now and include your brain) - first (a), then (b), > > but not the vice versa, ok? Good. > > I am not trolling but trying to explain things to an arrogant man who > just wants to name-call and won't show any code or any good examples of > API design, yet continues to lecture ideology. > > > [snip useless talk] > > I'll tell you what is useless: Your ideology. Good for nothing. > > >> This is seeming like a more and more of a waste of time. > > > Yes, by the truth I've already mentioned that and wanted to conclude > > this talk. > > >> You've got 0 rational argument > > > Ok, take a cookie (or cracker), you have deserved it. And yeah, learn > > ECMAScript and its ideology > > Your idealistic philosophies and ideology, coupled with your arrogance > are getting in the way of rational decision making. > -- > Garrett > comp.lang.javascript FAQ:http://jibbering.com/faq/ No-no-no, don't ask anymore crackers, that was the last one I gave to you, I've told the talk is over. You include already lie and slander stupidly repeating and bending your own line, although I told, that first (a), then (b), but not vice versa, so don't ask, I haven't any food for you, troll. /ds
From: Dmitry A. Soshnikov on 9 Jan 2010 08:22 On Jan 9, 2:30 am, Garrett Smith <dhtmlkitc...(a)gmail.com> wrote: > that is too much to expect from > one who writes fake code using Microsoft Word and publishes that on the > NG as arguments via Google Groups. Demagogy. False. Weak trolling. No-no, don't ask, your food is over. /ds
From: Jorge on 9 Jan 2010 08:56 On Jan 9, 12:18 am, Garrett Smith <dhtmlkitc...(a)gmail.com> wrote: > (...) > > The user-defined "dcTrim" performed three times slower. > (...) That's something Dmitry already knows. Probably you're the only one among the regulars that feels the need to write such benchmark that, besides, has nothing to do with what he was saying. -- Jorge.
From: Garrett Smith on 9 Jan 2010 13:10
Dmitry A. Soshnikov wrote: > On Jan 9, 2:18 am, Garrett Smith <dhtmlkitc...(a)gmail.com> wrote: >> Dmitry A. Soshnikov wrote: >>> On Jan 8, 1:34 am, Garrett Smith <dhtmlkitc...(a)gmail.com> wrote: >>> [snip useless (talk === demagogy)] [snip] Don't quote the entire message. Don't quote signatures. > No-no-no, don't ask anymore crackers, that was the last one I gave to > you, I've told the talk is over. > I have no idea what "asking crackers" means to you. > You include already lie and slander stupidly repeating and bending > your own line, although I told, that first (a), then (b), but not vice > versa, so don't ask, I haven't any food for you, troll. > No lies, no slander, and you've not explained how at all you got to those conclusions, either. Ad hominem makes discussion impossible and consequently degrade the quality of this group. This group is supposed to be focused on technical discussion. Try to let that concept sink in. -- Garrett comp.lang.javascript FAQ: http://jibbering.com/faq/ |