Blog

Avatar

When best practises collide

Best practises are methods and techniques for achieving a certain goal. By their very nature they set the standard for us to follow, and form a mechanism by which developers can be judged.

ASP.NET is my platform of choice when developing applications, but it gets a bum rap from developers on both sides of the open source debate, for its creators’ inherently arrogant approach to Web standards.

While working on a new project I thought I’d have to bite my tongue when I saw some of the .NET markup that was being used, but after a while it dawned on me that what was being written wasn’t incorrect, it was simply following Microsoft’s best practises rather than, for example the W3C.

Under ASP.NET, the tools that allow developers to change the styling for Webpage elements (font faces, sizes, colours, etc) are very close to hand. When adding a text box control to a form, the user can specify its border style, font size and colour aswell as the usual stuff like maximum length and validation functionality. Now as part of the XHTML and CSS methodology, which encourages the separation of content and styling, this type of customisation is abhorrent: it’s simply not the done thing. However, when developing the .NET Framework (and specifically ASP.NET), Microsoft were simply following a pattern.

Some people actually don’t realise, but the .NET Framework in and of itself has nothing to do with Web development: it is simply a software framework. Programmers can build desktop and console applications, libraries and games with it. Now in desktop application development it is very common for developers to be given the option to change how a form looks by hard-coding the window styles directly into the application. There is no CSS technology for desktop applications, and so programmers pick colours from a specific palette (which include system colours) and fonts from a dropdown list, to suit their needs.

Not only can you build both desktop and Web applications with the .NET Framework, you can also use the same software (Visual Studio) to build both types of application, so developers could make the transition from building Windows Forms apps to producing Websites. Microsoft even took care to give the Web versions of their controls (like textboxes and labels) the same or similar name as their Windows Forms counterparts, with the same abilities to change styling that programmers had grown used to.

So I think it’s unfair to rail at Microsoft for not embracing W3C, when this isn’t actually the case. As a standards-conscious developer I’m not forced to use the hard-coded styling method that I would use with Windows apps: I can apply CSS classes to my controls just like I could in HTML.

So hard-coding your “look and feel” doesn’t make you a bad Web developer: just one that’s following one set of practises. Problems only arise when developers pick and choose elements from different methodologies to create their own which makes picking up someone else’s project that bit more difficult.

This realisation has made me a more forgiving programmer: now I just have to learn to resist the urge to force my ideals onto others.

David North

I actually disagree. Yes the options to change font size etc. are close to hand but the option to change CssClass are just as close. Microsoft have to provide all options as they are all available in HTML - no difference really between the two.

Microsoft do make it easy for applications developers to move from the desktop to the web. However it isn't and never will be best practice to develop like you are describing. It shows a lack of understanding of the medium and disproves the myth that a lot of programmers seem to believe developing for the web is simple. You never know how little you know until you learn more.

If you are developing websites without CSS then you aren't a web developer. There are best practices for a reason - not just online either this applies thoroughly to Windows development too. Just because there is another way of doing something doesn't mean it's what you should be doing.

I'm not saying you should go around beating people with sticks about it, that doesn't encourage people to try and improve their practice but sell the benefits because best practices are always there for important reasons. And in a business sense it usually saves time and money.

Also it is the case that sometimes it not always possible to follow these best practices. You've got to be a realist and if a website has been developed in not the best way sometimes it just doesn't make sense to go back to the drawing board for the job your tasked to do.

However hard-coding your "look and feel" does make you a bad web developer. I'm not telling you to force your ideals on others but spread the good word! ;-)

Mark Steadman

I’m not saying that I agree that the hard-coding method is a Web-based best practice: far from it. I would always encourage Website owners to ensure their front-end code uses XHTML and CSS so that their designs can be edited and updated with ease. What I’m suggesting is that we shouldn’t necessarily demonise software developers for using hard-coding techniques as we often do.

I also have a problem with this idea that we should take a certain body’s idea as gospel. I know that Sir TBL is part of the W3C and that he invented the Web, but the W3C makes bad judgements too. The W3C’s accessibility guidelines are in some cases contradictory, in others actually wrong, so at some stage you have to rely on your own judgement. Not to say you should start combining methodologies, but instead to remember that you have to do what’s best for the project and its user-base.

I think it’s unfair to suggest that developers who do not embrace XHTML and CSS are bad developers. Failing to use best practices does not make you a bad developer: if it did, certain sites with font sizes defined in pixels might have to be changed so their developer(s) could save face... ;)

David North

Maybe I've been a little harsh in my wording. My point is web development is a specialism.

To transfer from software development to web development involves some research which some people don't do.

If I write 1,000 lines of code for a Windows application within one method I wouldn't be hailed as a good software developer so when you do essentially the same thing with inline styles on a web page the same applies.

I'm not saying demonise developers using these techniques but an effort should be made to educate. Again as I said you can't apply best practices to every project - if I'm briefed to update a page on a site I'm hardly going to rewrite the website from the ground up.

As for taking a certain body's idea as gospel - someone has to lead otherwise real problems occur. If you remember the browser wars when Netscape and IE battled it out but the non standard implementation made developing a hell of a lot more difficult for all browsers. By having a standards body you at least have a guide to measure against.

In practice standards have to be used subjectively - there are still differences for browsers but there is a goal.

I've posted on my blog about the slow standards process that W3C follows. It needs reviewing or will lose track of technology but for the moment it is current and should be used.

You've also got to remember there are different levels of best practice. Font size is only applicable when it comes to accessibility and unfortunately some don't care about the advantages this can bring.

Following best practices makes your website available to the widest possible audience in a form that it was designed to look like. There is a business argument as well to these best practices it's not just about doing it properly.

Kevin Rapley

I have to side with Dave on this one and I am surprised that you are accepting inline styles kicked out by using certain control fetures. I don't even feel following the W3C guidelines as best practice, they should be the only practice. Yes they are a guide and there are certain levels of use but using inline styles just because they are there to use doesn't mean they should. We don't apply inline styles to static HTML so why use it in .Net?

We separate styles from content as we separate code from template, there should be no halfway house otherwise the integrity of what we do diminishes.

Don't let your standards slip Mark just because you have seen others being sloppy. Teach them that there is a better way and why it is seen as better. The benefits are much larger.

Mark Steadman

Thanks for looking out for me Kev but I’ve been doing this job long enough to know where my standards are. I can have an opinion and it may not be one you share, but don’t take it as a reflection on my ability or principles as both are unchanged..

Kevin Rapley

Sorry man, I should've read over my comment again before sending it, my bad. Wasn't meant to sound quite so harsh and criticise your standards. Where I said don't let your standards slip just because you have seen others being sloppy, what was meant to come out was don't let your web standards "practice" change to accomodate what is being done by those who are working on the same projects as you. That may still sound a little strong and perhaps I can't find the right words. But showing them that there is a more effective way to uphold W3C standards which I would favour to Microsoft best practices. As you know I am a bit of a W3C standards evangelist.

My lesson learnt is to take more time on my commenting rather than rushing them out quickly ;) Hope I didn't offend too much.

Leave your comments