3 ms·
The point about string concatenation is, umm, I don't want to say "wrong" because wrong sounds argumentative so I think I'll pick a circumlocution like "contrar
by patio11 17y ago
The point about string concatenation is, umm, I don't want to say "wrong" because wrong sounds argumentative so I think I'll pick a circumlocution like "contrary to fact" or "a bedtime story to scare CS101 students with, second only to 'use left shift instead of dividing by two, it is faster'".
Also in modern Java (and Ruby) projects you can typically write:
logger.debug("This is a stupidly expensive calculation: " + stupidlyExpensiveCalculation())
and it will get executed regardless and logged only if your logging settings, which are configured elsewhere and can be toggled with a mouseclick, are set to log the debug level.
Now, don't get me wrong, Arc's solution of defining a macro which checks to see whether your debug setting, which is defined elsewhere and can be toggled with a mouseclick, is on or not is a good idea. Its just not a revolutionary new idea for us wizened Big Freaking Enterprise App Ugly Language Programmers. Nor was it really that new in the halycon days of yore when Log4j crawled out of the primordial ooze.
- gaius 17y agoWe get this for free in Haskell.
- klipt 17y agoNot exactly free ... laziness and the resulting thunks do use up extra processing time and memory. But in many cases it is a price worth paying. http://www.cs.chalmers.se/~rjmh/Papers/whyfp.html http://www.cs.chalmers.se/~rjmh/Papers/whyfp.html
- smikhanov 17y agoAgree. isDebugEnabled() method is used to scare people since 2001, probably around the time when it came out of common use. Macro that is being used for exactly that is not a distinguishing feature of the language. Java proponents may come out with, say, accessing array in constant time (how many car/cdr pairs you need for that?) Important is that neither of the described facts add something to the value of one language against another and usually serve only as a basis for speculation. Edit: when I'm saying "went out of common use", I mean that elegant alternatives like logger.log("Expensive calculation is going to be: {0}", objectWithExpensiveToStringMethod); have emerged.
- asmosoinio 17y agoI am not sure if I understood you correctly, so let me check: Did you mean that stupidlyExpensiveCalculation() will be always executed, regardless if debugging is enabled? Seems to me you say this like it's a good thing. Or I am misunderstanding...
- TJensen 17y agoThe real problem is not the string concatenation, it is that stupidlyExpensiveCalculation() will evaluate, regardless of whether debugging is on or not (at least in Java, not sure about Ruby), since Java doesn't do lazy evaluation of arguments. In this case, that just slows things down. Worse yet is when it is stupidCalculationWithSideEffects(). And I have seen that before. :(
- stcredzero 17y agoThe reason is that logger.debug(...) should really be logger.debug { ... } Which can be done trivially in a language with convenient blocks/lambdas. Then the debugging expressions will not run at all with debugging disabled. Yes, having a meta-syntax as your syntax is very useful.