which is best?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

sb = New StringBuilder
sb.Append(vbNewLine)
sb.Append("function init() {")
sb.Append(vbNewLine)
sb.Append("ModuleMenu = new TRMenu.TRMenu();")
sb.Append(vbNewLine)
sb.Append("ModuleMenu.Add('Modules',0,'ModuleMenuList');")

Or

sb = New StringBuilder
sb.Append(vbNewLine & "function init() {" & vbNewLine & "MMenu = new
Menu.Menu();" & vbNewLine & "ModuleMenu.Add('Modules',0,'ModuleMenuList');")

I've been told that the first method of joining a string is definately a
better way of programming. Is this correct? To me it seems like more work to
for the same result.
 
Jimbo,

I find definitly the first way much nicer, however the compiler optimizes
the second way.

I hope this helps,

Cor
 
Jimbo Jim said:
sb = New StringBuilder
sb.Append(vbNewLine)
sb.Append("function init() {")
sb.Append(vbNewLine)
sb.Append("ModuleMenu = new TRMenu.TRMenu();")
sb.Append(vbNewLine)
sb.Append("ModuleMenu.Add('Modules',0,'ModuleMenuList');")

Or

sb = New StringBuilder
sb.Append(vbNewLine & "function init() {" & vbNewLine & "MMenu = new
Menu.Menu();" & vbNewLine &
"ModuleMenu.Add('Modules',0,'ModuleMenuList');")

I've been told that the first method of joining a string is definately a
better way of programming. Is this correct? To me it seems like more work
to
for the same result.
I wouldn't use a string builder for the second case ( unless you were going
to continue to append ). The string builder becomes efficient when append
is used repeatadly
 
Thanks for your reply.
So for instance:
s = New StringBuilder
s.Append(vbNewLine)
s.Append(vbNewLine)
s.Append("function init() {")
s.Append(vbNewLine)
s.Append("MMenu = new Menu.Menu();")
s.Append(vbNewLine)
s.Append(vbNewLine)
s.Append("MMenu.Add('Modules',0,'MMenuList');")
If something Then
s.Append(vbnewline)
s.Append("and add this:")
s.Append("then this")
End If

Runs better like this:

s = New StringBuilder
s.Append(vbNewLine & "function init() {" & vbNewLine & "MMenu = new
Menu.Menu();" & vbNewLine & "ModuleMenu.Add('Modules',0,'ModuleMenuList');")

If something Then s.Append(vbnewline & "and add this: then this")

The reason I ask is that our .Net programmer had created a program that I'm
guessing has way to many ".Appends" when they are not needed. I could
probably reduce the amount of code by a few houndred lines.
 
Jimbo,

The used time is almost the same and in think that the best is in the
middle.


Just my idea

Cor
 
Back
Top