Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #14665
| Message-ID | <4685065.IhH0G6Cc8r@PointedEars.de> (permalink) |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Organization | PointedEars Software (PES) |
| Date | 2012-06-26 09:04 +0200 |
| Subject | Re: Placing 'zeros' in front of a number ? |
| Newsgroups | comp.lang.javascript |
| References | (2 earlier) <js1amg$mv1$1@dont-email.me> <1623778.oMNUckLgyt@PointedEars.de> <b8fc4748-4126-46c4-958e-55c8462ec5ca@googlegroups.com> <11390067.YXlMqVrOKe@PointedEars.de> <ad593911-0b87-4e09-8349-e443390e7d88@googlegroups.com> |
| Followup-To | comp.lang.javascript |
Followups directed to: comp.lang.javascript
Michael Haufe (TNO) wrote:
> Thomas 'PointedEars' Lahn wrote:
>> Michael Haufe (TNO) wrote:
>> > Thomas 'PointedEars' Lahn wrote:
>> >> Having reviewed these two solutions (see below), I still prefer
>> >> mine...
>> >
>> > I would have preferred my second solution mentioned to be evaluated,
>> > which was added to the jsperf website:
>>
>> The disadvantage of Google Groups postings to the interested poster is
>> that I do not see them (which is an advantage to me in most other cases),
>> except when they are followups to my postings and the poster was not
>> killfiled. Since I am not alone in this, I strongly suggest you switch to
>> a more responsible Usenet access provider.
>>
>> > function padLeft(str, ch, len){
>> > return str.length >= len ? str : padLeft(ch + str, ch, len);
>> > }
>>
>> I do not think this recursive solution is very efficient or compatible
>> either. Instead of a fixed number of 2 function calls, there are now
>> len - str function calls. And the greater the difference between
>> original string length and desired string length, the more likely a stack
>> overflow.
>
> Any argument with regards to compatibility concerns is not
> very useful without explicit constraints.
Yes, it is. We are talking about a scripting language, where the runtime
environment defines the implementation.
> Even if they were presented, they would be debateable anyway.
Of that I am sure. It would not end up to be a overly logical debate,
though.
> I am of the belief that such concerns are best left to an ES current ->
> ES legacy compiler. Many defensive programming techniques
> are also better left to this methodology as well.
If you are talking religion instead of logic now, EOD for me.
> Your efficiency argument is valid in part. I could make an
> argument in reference to brevity and network traffic,
I was referring to the potentially increased number of function calls
necessary to compute the result. We do know that function calls are rather
expensive, don't we? So we should avoid them when not necessary and when
there is a risk attached to using them, shouldn't we?
> […]
> I doubt you were refering to anything beyond time/space
> with the efficiency criticism.
Correct.
> IRT speed, JSPerf demonstrates that this is not an issue in
> relationto the other approaches presented there.
Be wary of basing design decisions solely on benchmark results of today.
Especially when you are not certain of the method behind the benchmark.
> IRT to memory, it is indeed plausible (however unlikely)
> that a string which needs to be padded to a significant
> length could consume more memory than is desirable
It is not only plausible and likely, it is certain that a longer string of
characters requires more memory than a shorter string of characters.
> but if memory was a concern, I find it unlikely that the developer
> would be padding a massive string in the first place.
Argument from probability.
> Even so, I think it is also worth noting that strings are constructed
> lazily in more than one current browser.
Name two.
> It is also well known that tracing JITs do quite well with such code as
> it is type stable and easily converted to loop
References?
> (which is probably what is demonstrated on the test page)
Maybe. Maybe not.
> Stack overflow probability? I believe the worst offender would
> be Safari 3.2 which has a 500 level limit.
There is that word again. You should like to *know*. And never limit
yourself to *desktop* *browsers*.
> So what is the probability that a developer is performing a left pad of
> 500 characters for a legacy client?
Argument from probability.
> I wouldn't pretend to know without more information.
That's the point. You never know. So be slow to take the risk of not
working code when it is not necessary. It is more important to have working
code than fast code, because it does not matter that code could be fast when
it does not work in the first place, and as you say yourself, with working
code internal optimization is still possible.
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Placing 'zeros' in front of a number ? "Mel Smith" <med_cutout_syntel@aol.com> - 2012-06-21 18:37 -0600
Re: Placing 'zeros' in front of a number ? Gene Wirchenko <genew@ocis.net> - 2012-06-21 18:59 -0700
Re: Placing 'zeros' in front of a number ? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-06-21 20:18 -0700
Re: Placing 'zeros' in front of a number ? "Mel Smith" <med_cutout_syntel@aol.com> - 2012-06-21 22:51 -0600
Re: Placing 'zeros' in front of a number ? Gregor Kofler <usenet@gregorkofler.com> - 2012-06-22 10:34 +0200
Re: Placing 'zeros' in front of a number ? Scott Sauyet <scott.sauyet@gmail.com> - 2012-06-22 04:49 -0700
Re: Placing 'zeros' in front of a number ? "Mel Smith" <med_cutout_syntel@aol.com> - 2012-06-22 08:39 -0600
Re: Placing 'zeros' in front of a number ? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-06-22 13:05 -0700
Re: Placing 'zeros' in front of a number ? Gene Wirchenko <genew@ocis.net> - 2012-06-22 14:10 -0700
Re: Placing 'zeros' in front of a number ? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-06-22 22:58 +0000
Re: Placing 'zeros' in front of a number ? Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2012-06-23 18:47 +0200
Re: Placing 'zeros' in front of a number ? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-06-23 21:44 +0000
Re: Placing 'zeros' in front of a number ? "Mel Smith" <med_cutout_syntel@aol.com> - 2012-06-23 16:48 -0600
Re: Placing 'zeros' in front of a number ? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-06-23 16:56 -0700
Re: Placing 'zeros' in front of a number ? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-06-23 19:47 +0200
Re: Placing 'zeros' in front of a number ? Gregor Kofler <usenet@gregorkofler.com> - 2012-06-23 20:52 +0200
Re: Placing 'zeros' in front of a number ? Gregor Kofler <usenet@gregorkofler.com> - 2012-06-23 21:01 +0200
Re: Placing 'zeros' in front of a number ? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-06-23 17:05 -0700
Re: Placing 'zeros' in front of a number ? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-06-24 03:51 +0200
Re: Placing 'zeros' in front of a number ? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-06-25 20:19 -0700
Re: Placing 'zeros' in front of a number ? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-06-26 09:04 +0200
Re: Placing 'zeros' in front of a number ? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-06-26 08:32 -0700
Re: Placing 'zeros' in front of a number ? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-06-26 22:12 +0200
Re: Placing 'zeros' in front of a number ? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-06-30 13:41 -0700
Re: Placing 'zeros' in front of a number ? Dr J R Stockton <reply1226@merlyn.demon.co.uk.not.invalid> - 2012-06-27 19:34 +0100
Re: Placing 'zeros' in front of a number ? Dr J R Stockton <reply1225@merlyn.demon.co.uk.not.invalid> - 2012-06-23 20:00 +0100
csiph-web