Sunday, March 21, 2010

Why don't we have a StringBuffer in Apex ???

Dream 20

I used to wonder why don't we have a class like StringBuffer in Apex?? I have used String Buffers in Java (not so long ago) and we have debated a lot those times as to whether we wanted to do a (a+b) operation or a. append ("b"). Let’s review the importance of StringBuffer once again ...

1. Code written using a StringBuffer for concatenation is technically proven to execute faster than the code that uses String for concatenation. It’s all drilled down to the less number of byte codes getting executed when we use StringBuffer.

2. Code written using StringBuffer is easier to debug/maintain. Particularly, when we have those large dynamic SOQLs in our triggers or apex classes.

3. The underlying language for Apex is Java. This being the case, it should be an easy step for Salesforce to expose the StringBuffer API.

I have also put this as an Idea on the IdeaExchange. I would appreciate if the people reading this blog can vote for this Idea. Click here to help me & other fellow Apex devs realize this dream :)

No comments:

Post a Comment