Yes, that's an important lesson. I learned it some years ago and have worked
hard to use StringBuffer as much as possible in Jmol in situations where a
lot of string processing is to be done within a loop. But I still find a few
of those in the code now and then. So it's a continuing issue.

The real problem is not

x = "a" + "b" + "c"

it's

x = ""
x += "a"
x += "b"
x += "c"

where the overall operation is separated into distinct commands.

There are other discussions of this in terms of Java compilers. For example:

http://java.sun.com/developer/JDCTechTips/2002/tt0305.html

The gist there is that Java compilers optimize your code. When there's a
certain number of + operators in a given command (2? 3?), it doesn't matter
what you do. So it's not quite as simple as "never use + to join lots of
strings."

Bob

2009/11/10 Angel Herráez <[email protected]>

> Dear developers,
>
> You probably know this already, but just in case, I thought better to
> forward it:
>
> ------- Forwarded message follows -------
> Subject: never use + to join lots of strings
>
> While well known, this post nicely shows why concatenating lots of
> string
> shouldn't be using the + operator.
>
> http://www.venishjoe.net/2009/11/java-string-concatenation-and.html
>
> ( Received from Rajarshi Guha via [Cdk-devel] list )
>
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus
> on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Jmol-developers mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/jmol-developers
>
>


-- 
Robert M. Hanson
Professor of Chemistry
St. Olaf College
1520 St. Olaf Ave.
Northfield, MN 55057
http://www.stolaf.edu/people/hansonr
phone: 507-786-3107


If nature does not answer first what we want,
it is better to take what answer we get.

-- Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Jmol-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jmol-developers

Reply via email to