Article 4J1PN CodeSOD: Classic WTF: The not-so-efficient StringBuilder

CodeSOD: Classic WTF: The not-so-efficient StringBuilder

by
Alex Papadimoulis
from The Daily WTF on (#4J1PN)
As our short summer break continues, this one is from waaaaay back, but it's yet another example of how seemingly simple tasks and seemingly simple data-types can be too complicated sometimes. Original--Remy

The .NET developers out there have likely heard that using a StringBuilder is a much better practice than string concatenation. Something about strings being immutable and creating new strings in memory for every concatenation. But, I'm not sure that this (as found by Andrey Shchekin) is what they had in mind ...

public override string getClassVersion() { 
return
new StringBuffer().append(
new StringBuffer().append(
new StringBuffer().append(
new StringBuffer().append(
new StringBuffer().append(
new StringBuffer().append(
new StringBuffer().append(
new StringBuffer().append(
new StringBuffer().append("V0.01")
.append(", native: ibfs32.dll(").ToString())
.append(DotNetAdapter.getToken(this.mainVersionBuffer.ToString(), 2)).ToString())
.append(") [type").ToString())
.append(this.portType).ToString())
.append(":").ToString())
.append(DotNetAdapter.getToken(this.typeVersionBuffer.ToString(), 0xff)).ToString())
.append("](").ToString())
.append(DotNetAdapter.getToken(this.typeVersionBuffer.ToString(), 2)).ToString())
.append(")").ToString();
}

Note, that it is J#, StringBuffer and StringBuilder are the same thing.

proget-icon.png [Advertisement] ProGet supports your applications, Docker containers, and third-party packages, allowing you to enforce quality standards across all components. Download and see how! TheDailyWtf?d=yIl2AUoC8zA4r693EBSk3E
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments