tag:blogger.com,1999:blog-34454975.post877740905777615310..comments2023-06-28T16:58:41.189+02:00Comments on Web Reflection: Lazy developers, Stack concept, and the fastest, unobtrusive, JavaScript StringBuilderAndrea Giammarchihttp://www.blogger.com/profile/16277820774810688474noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-34454975.post-72542595062627309382011-04-29T02:51:35.163+02:002011-04-29T02:51:35.163+02:00Lots of good reading here, many thanks! I had been...Lots of good reading here, many thanks! I had been researching on yahoo when I observed your article, I’m going to add your feed to Google Reader, I look forward to more from you.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-34454975.post-77220843147255637972008-06-22T17:43:00.000+02:002008-06-22T17:43:00.000+02:00Other browsers will be fast enough, and the aim is...Other browsers will be fast enough, and the aim is to use one reasonable fast way for every browser.<BR/><BR/>If we choose to use a StringBuilder, it does not make sense to write code twice, one for other browsers, one completely different for IE.<BR/><BR/>But this is only a possibility, and the problem is that if you look for a StringBuilder constructor, the faster one extends native Array without a reason. (so again, the point of this post is another one :D)Andrea Giammarchihttps://www.blogger.com/profile/16277820774810688474noreply@blogger.comtag:blogger.com,1999:blog-34454975.post-40266560811754806072008-06-22T17:06:00.000+02:002008-06-22T17:06:00.000+02:00I agree with you about the fact that we should use...I agree with you about the fact that we should use StringBuilder only when there's a huge number of concatenations.<BR/><BR/>However your class is useful mainly in Internt Explorer, other browsers optimize the concatenations in order to achieve similar results.Lorenzohttps://www.blogger.com/profile/17052539879440146404noreply@blogger.comtag:blogger.com,1999:blog-34454975.post-8646114953634597882008-06-22T11:35:00.000+02:002008-06-22T11:35:00.000+02:00Hi Mega :)Obviously I did not write an example wit...Hi Mega :)<BR/>Obviously I did not write an example with 100 concatenations, and the point of this post is that a lot of developers use a StringBuilder like constructor, but nobody uses the Stack trick to make them faster and unobtrusive.<BR/><BR/>As I wrote in that blog long time ago, the fastest way ever is the method concat, but it creates a new string, so its purpose cannot be the same of a StringBuilder.<BR/><BR/>Finally, we need a StringBuilder exactly in those case where we concatenate a lot of informations, otherwise it does not make sense to have a dedicated constructor to do something like:<BR/><I><BR/>(str = new StringBuilder("a")).append("b");<BR/>alert(str)<BR/></I><BR/>do you agree? :)Andrea Giammarchihttps://www.blogger.com/profile/16277820774810688474noreply@blogger.comtag:blogger.com,1999:blog-34454975.post-64867431808437396502008-06-22T11:26:00.000+02:002008-06-22T11:26:00.000+02:00Good work, however by doing some benchmark tests I...Good work, however by doing some benchmark tests I noticed that string concatenation is faster than join concatenation in Firefox and Opera; besides join concatenation is faster in IE only when the string to build is quite big; the IEBlog says:<BR/>"Not only is the code simpler, but it is also much faster for this case. When the number of values being concatenated is small enough the concatenation operator still wins. You’ll have to do performance testing when you choose this approach and make sure it fits your algorithm."<BR/><BR/>In other words I think that the performances of a StringBuilder are relative.Lorenzohttps://www.blogger.com/profile/17052539879440146404noreply@blogger.comtag:blogger.com,1999:blog-34454975.post-44706422775123423282008-06-22T03:36:00.000+02:002008-06-22T03:36:00.000+02:00Cheers Michael (and anonymous too)As you know, I w...Cheers Michael (and anonymous too)<BR/>As you know, I write more code for develpers than for surfer, and that is why I do not use to make my presentations rich, elegant, styled, or something else may be cool, but for my target probably superfluous.<BR/><BR/>At the same time it is the second comment I receive about "ugly demos", so I suppose you are definitively right :D<BR/><BR/>The Collection is more simple than you think, but it will be fast enough, and strict (types / classed check)<BR/>Maybe it will not be fast with the append method, but it will be fast enough with sort, reverse, and every other useful Array prototype ;)Andrea Giammarchihttps://www.blogger.com/profile/16277820774810688474noreply@blogger.comtag:blogger.com,1999:blog-34454975.post-61374407140671940642008-06-22T01:55:00.000+02:002008-06-22T01:55:00.000+02:00It seems smart. Congratulations!It seems smart. Congratulations!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-34454975.post-13776869521903426752008-06-22T01:38:00.000+02:002008-06-22T01:38:00.000+02:00Hey Andrea,At it again I see ;-) Great!So I just r...Hey Andrea,<BR/>At it again I see ;-) Great!<BR/><BR/>So I just read your post and although I haven't fully absorbed your accomplishment looks like you've created a very useful piece of code. Thanks!<BR/><BR/>I followed your link back to your Ajaxian post then looked at your test bench page. I suspect that you haven't received the kind of attention or seen the kind of adoption you might expect for such a clever solution because:<BR/><BR/>1. It's very low-level as in assembly vs. java in today's widget and GUI manipulation library environment. Only hardcore JavaScript developers would probably be interested and they'd definitely be the only ones capable of appreciating what you achieved.<BR/><BR/>2. Even hardcore developers need easy to read data showing why your creation is so important. The test bench for example isn't as informative as you may like. I for one wasn't sure what the numbers I saw meant, and looking at the page's JavaScript to try to better understand didn't help since the code was minified. I suspect "pretty" graphs or tables is not in your area of interest ;-) but I think 1 or two might go a long way to help people appreciate your work.<BR/><BR/>3. I think a demonstration of the problem <B><I>and</I></B> how your code solves it would really drive the significance home.<BR/><BR/>I read your blog often and know you're a gifted programmer, perhaps with a bit more gloss your work can attract the kind of attention it deserves! I'm definitely looking forward to your generic Collection constructor. I've created one in the past myself, but never focused on it's performance, so seeing yours will be insightful!{Michael : iSkitz}https://www.blogger.com/profile/07632896592054092882noreply@blogger.com