Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news2.arglkargh.de!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: =?UTF-8?B?Sm9zaHVhIENyYW5tZXIg8J+Qpw==?= Newsgroups: comp.lang.java.programmer Subject: Re: A good article on java.lang.String best practices Date: Tue, 29 Jul 2014 10:24:03 -0500 Organization: A noiseless patient Spider Lines: 36 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 29 Jul 2014 15:24:27 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="8cedddb29338592f734c41b16a68fadc"; logging-data="8476"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+6ngroM/d0lC7tIou29xDHQiieWJFOjzE=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.0 In-Reply-To: Cancel-Lock: sha1:e7Hkx1p9AoN4ct8rjfE+yvPGdo8= Xref: csiph.com comp.lang.java.programmer:29428 On 7/28/2014 10:50 PM, im.manoj.tripathi@gmail.com wrote: > Here is good article on Strings in Java, of you are a Java developer > then this article could be helpful to write good and optimized code. > > http://www.groupkt.com/post/5bcd8475/javalangstring-tips-and-tricks:-best-java- > coding-practices.htm On point 1: Your discussion of when == works is wrong, completely ignoring interning or reference equality. Points 2 and 4 both lack an explanation as to one variant might be faster, and perhaps reasons why that one may be slower. Point 5 contradicts its own pithy title. Point 7 says "we saved multiple string concatenations." Gee, what do you think String::format does internally? Point 8 is so devoid of content to be useless. (Would it really hurt, to, I don't know, give examples of utilities, or link to documentation in the first place?) Microbenchmarks are difficult to write properly in the best of conditions, and even the best performance experts would hesitate to write one. The vibe I get from the post is that so little effort was put into establishing a reasonable microbenchmark that the information content contained within is worse than useless. And there's grammar mistakes up the wazoo (sentences should start with capitals; "their" is the third-person plural possessive pronoun, not "there"; several sentences are missing connectives; "flyweight" is a single word, not two words). -- Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth