From: "Kroeger, Simon (ext)" Date: 2006-06-22T16:48:29+09:00 Subject: Re: The difference between s=s+"a" ans s<< "a" > From: Robert Klemme [mailto:shortcutter@googlemail.com] > Sent: Wednesday, June 21, 2006 11:04 PM > > 2006/6/21, Simon Kr�ger : > > I think > > s = s + "a" # > > or > > s += "a" > > > > should be the norm as long as you do not know that using it > will cause > > you problems (really only performance problems come to my mind) > > I use the rule exactly the other way round: usually use << unless that > might cause problems. There's a lot of code out there that does += > while all it wants to do is appending. += is less efficient and with > my C++ background << more looks like "append". Well, if you realy know what you do and if 'that might cause problems' there is of course no problem with <<. '+= is less efficient' smells like premature optimization. > > you will get what you expect if you use += > > It depends on what you expect. If methods are expected to get > something that they append stuff to then the observed behavior is > exactly what you expect and want. :-) Hmm, I (but that may be just me) wouldn't write a method that 'get something that they append stuff to'. I would write a method which will return the stuff and let the caller append it to whatever he wishes. (I like it a bit functional style and do not like side effects) > For example, if you write a method that should append info about the > current instance to something then you should use << because then even > an IO object can be passed and the code still works as expected. Yes, if I would write such a method, yes. If appending is exactly the operation I want, I use it. sure. > As generally, you should know your tools and be knowing what > you do. :-) That sums it up quite perfect. > Kind regards > > robert cheers Simon