views:

80

answers:

2

After spending a not-insignificant amount of time converting a page that used concatenated html, like

string output = "";
output +="<ul>";
foreach(MyClass item in MyItems)
{
  output += "<li>"+item.Name+" - "+item.SomeProperty.ToString()+"</li>";
}
output+="</ul>";

literalPlaceHolder.Text=output;

to use the ListView control, I've just discovered that the original developer went back and converted the page back to using concatenated html. My personal feeling is that listviews and repeaters lend themselves to cleaner, more informative markup that can be edited by someone with less experience with C#, and that they are faster and use less memory. At the very least the page should be using a StringBuilder instead of a string. Anyone have a good argument for this? I have a feeling it's going to cause a major conflict when I bring this up.

+2  A: 

First of all, I think it's not very cooperative for another developer to just replace your code like that, with no discussion. You will definitely have to make a good case for your position if you want to prevail in this one.

I agree that the standard ASP.Net controls are easier for less-experienced developers to deal with, if that is a concern in your situation.

I'm not sure I agree with you about StringBuilder, which has often been the source of raging debates here and elsewhere. If your list is not lengthy, there may not be sufficient justification for a StringBuilder here.

One aspect that a seasoned developer might appreciate about this particular approach is that it is easy to step through and see exactly how each item is being populated. That isn't as easy with a ListView -- you'd have to add an event to catch the items being added, and then put a breakpoint in it.

And finally, I would encourage you to choose your battles carefully. This particular example is not a major design issue. If you foresee other, larger differences of opinion in the future, you might decide to start here with a smaller issue, to establish a way of resolving these kinds of conflicts with your fellow developer. Alternately, you could consider that this is not a big enough deal to fight about, and wait for something of major importance (and I doubt that you will have to wait long). Which way you choose to proceed depends upon the personalities involved.

DOK
Sounds reasonable. The StringBuilder issue comes up because the html output is *very* long. Every string += op creates a temp copy of the string, which seems inefficient when there is an alternative readily available. Thanks!
David Lively
+2  A: 

I disagree with the answer above.

First on a technical point of view. Using concatenated strings in the codebehind is clearly mixing the View with your Logic. If I would browse this application, I would wonder where the output html come from, since when the aspx (or ascx) are empty.

Furthermore, if you use controls like the Repeater and he is concatenating html code and just outputs it to the page, there will be no consistency between the different area of your app, and it will just become a mess to find out where to look at when a bug comes up, or when a feature has to be added.

I would suggest you simply ask him why he prefers to concatenate Html. What are his reasons to switch back your code to his way of doing without asking first.

I also disagree on a team-work point of view. In a team, Communication is everything. Without communication, you're vowed to fail. Don't fear to communicate. when there is a question, you have to ask it and you have to make things clear. whether you win or he win is not the point. the point is to understand eachother and to work as a team, together, not against eachother.

Good Luck!

Stéphane

Stephane