1

I am on an ASP.NET MVC project where we use Razor to define pages. One thing I like to do is to use Razor's @helper to DRY up pretty much any duplication in HTML (i.e. formalize even small UI patterns). To give an example. At the top of the page there are 3 "quick links" buttons at the top of the page, titled A, B and C. That take user to pages A, B and C respectively. I could type out three times:
<a href="/a" title="A" class="btn btn-default" target="_blank">A</a>

but I do:
@Link("A", "a")

Please note, my question is not weather this approach is right or wrong. The question is not about benefits of abstractions for maintenance. I have a very specific question here.

What I am often faced with is this desire (not an argument) to "see raw HTML". I want to understand where does this desire to see "raw HTML" comes from. People often say "maybe it is the anguish back from the days of WebForms where all that abstraction was painful".

Why do people yearn to grind through noise to get to the relevant data?

closed as primarily opinion-based by user40980, Bart van Ingen Schenau, Robert Harvey Nov 18 '15 at 16:59

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    I want to understand where does this desire to see "raw HTML" comes from <--- ask them? We're not capable of mind-reading your coworkers. It seems like you already have the answer to your question and I'm not sure as currently written anyone can answer your post. – enderland Nov 18 '15 at 14:51
  • It is not just on this team. I see this resistance quite common. I did ask them, I don't think they can explain. Perhaps those of you who share their sentiment, can offer an insight. – user93422 Nov 18 '15 at 14:56
  • I read this as a mix between a rant (though you're not trying to focus on that) and a poll of opinions. While it may be common, you should ask the people who use it. If it is common, you are in danger of getting too many answers here for it to be practical and useful to others - ironically forcing people to grind through the noise to get to the relevant data. – user40980 Nov 18 '15 at 14:59
  • @enderland: I took a good crack at it anyway. – Lightness Races in Orbit Nov 18 '15 at 15:10
  • On topic: I suppose that abstracting bits of HTML template can be entirely reasonable. I also suppose that the ability to see the raw HTML that comes to the browser is important, too, because any layout glitches, DOM performance problems, etc have to be troubleshooted against the raw HTML. A way to make it visible is important to have; usually developer tools in a browser allow for that, though. – 9000 Nov 18 '15 at 17:31
4

Why? Well, think of it this way - you're happy with this situation because you're the one putting it in there, so you already know what @Link means. Your colleagues probably do not. This is the pain point of abstractions.

Imagine you come across a new page someone else has created and all it has is @Page_7 at the top. You'd be annoyed that so much information about the creation and layout of the page had been abstracted (and I'd agree) but this extreme example shows what the problem is - in order to use such abstractions you all need to know they are being used, and understand where and how much they will be used. Maybe if you came across @@header@@ and didn't know the tooling used to turn that into code or even where to find the raw code, then you'd be complaining too.

I've seen too much code that disappears into a black box and pops out the other end with no way of knowing what happened in the middle (which is where it usually goes wrong).

Now this may not be the case with your team and they just want to see raw HTML. If that's the way the team wants it though, that's the way it has to be. You cannot arbitrarily do something different if they don't use such techniques. Not only is that not good teamwork, but it introduces artefacts that they will not understand because they don't use them.

  • I would personally look for the definition of @Page_7, problem solved ;-). +1 for the last paragraph, even though it seems contradictory to not use templating techniques when wanting to work with a templating system. There is something we don't know here. – coredump Nov 18 '15 at 17:04
  • @coredump cheers. I was thinking more of code generation where it is in a template that's not necessarily pulled out as part of your code because its in a different 'resources' project or .. well, you get the idea. Such things can be a right PiTA, especially when 1 team member decides to use a template engine without bothering to properly inform everyone else first..... – gbjbaanb Nov 18 '15 at 17:27
1

Because they are intelligent, experienced and professional software developers.

Separating abstraction layers is an absolutely crucial part of isolating any problem. One of the very first steps in producing a testcase to reproduce a bug (be it physically, or virtually in your head) is in taking your multi-layered application and examining its layers one at a time.

So, for example:

  • does the information on the screen look correct?
  • does the HTML that your browser uses to render it look correct?
  • do the Razor directives look correct?
  • does the data in the database look correct?

This is why questions on Stack Overflow that are about all of MySQL, PHP and HTML at the same time really grind my gears. The OP should be narrowing down the problem to one technological layer before posting: that may very well involve finding out what the "raw HTML" is that's sent to the browser for rendering.

I cannot fathom what pain you must endure trying to understand, maintain and debug an application without performing this basic step. Divide and conquer!

  • tl;dr abstraction is great but you have to break it apart sometimes otherwise you're going to be sad – Lightness Races in Orbit Nov 18 '15 at 15:12
1

HTML is a perfect fit for abstractions, and that is why there are many templating systems. The problem with your example is maybe that you are hiding too much information: target and class attributes are implicitely defined, and @Link, as a name, is too generic. If the link is a quick-link, call it @QuickLink.

If your team already use Razor, it seems that learning and maintenance costs have been deemed acceptable by your colleagues, so I doubt they are strongly opposed to the approach in principle.

I am afraid you would have to ask more questions to understand the pain that is felt by your colleagues. Ask them how they would rewrite your example and what they would do to mitigate the problem of having duplicate code. I don't use this particular technology, but how difficult is to debug? How difficult is it to run a test and see the generated HTML?

Not the answer you're looking for? Browse other questions tagged or ask your own question.