Saturday, 27 June 2009

When agile goes bad, slides and pointers

I’ve given that talk quite a few times now, and always forget to give the full material. So here goes.

The slides can be downloaded at http://svn.caffeine-it.com/mug/agile-goes-bad/when-agile-goes-bad.pptx

A couple of references that I mention in my talk.

A couple of points I hammer constantly, so let me repeat them once again:

  • Becoming agile is a journey, not a goal.
  • The goal is to adapt to change, and deliver value
  • Change cannot happen smoothly if quality is not at the core of your development practice
  • Becoming agile takes months (some say years), not weeks.
  • Don’t start adapting an agile methodology before you have a thorough understanding of it. Otherwise, you’ll adopt the easy bits (daily stand-up, wall) and ignore the hard bits necessary for your project to succeed (continuous integration, regular deliveries, short feedback cycle)
  • Get yourself a proper coach for enough time, at the beginning three days won’t get you much at all (notable exceptions are putting in place CI / builds and helping organize workshops). If you adopt a new methodology while starting a new project, you’re doubling the risks of failure. Do it with inexperienced people (and this includes freshly certified scrum masters) and you triple your risk.
  • Done is not done until the task is complete and doesn’t need to be changed. At all. Ever. That includes testing, code reviewing, documenting, etc etc.
  • Delivering at the end of the iteration means delivering to your customer, not to testers.
  • Your testing should be done per-story, tested in real-time. If you have a UAT phase, you have a problem.
  • Each feature gets deployed as it becomes Done. Not at the end of an iteration.

And to answer a question that was asked in Cork, where do you start when you have none of the agile practices, I’d do it in the following order:

  1. Source control! If you don’t store your code (and this includes database schemas and everything else) in source control, you’re putting your company at risk.
  2. Start with OOP, practices, BDD (then TDD if you’re so inclined), continuous integration, code analysis (coverage and dependency analysis), a couple of necessary concepts to produce well-factored maintainable code (Dependency Inversion principle, Inversion of Control, dependency injection).
  3. Once you’re comfortable with the principles (which you should after an intense couple of weeks of trying hard), start a project with a simple methodology. I’d recommend adopting Extreme Programming and Scrum at the same time, because they fit together fairly well. Focus on writing your user stories and your tasks, and tracking them down in burn down charts. Get customer involvement from day 1, buy trust by sticking to regular time-boxed deliveries.
  4. if you get there, you’ll have enough opinions about the process of delivering great software to decide on the next move yourself.

Friday, 12 June 2009

In how many ways can the Microsoft Ajax 4 syntax break XHTML?

[Update: Added example pages from aria]

For the answer, see the points below.

I was going to email the comments below to some people at Microsoft that have shown an interest in opening up a conversation, but after a comment I left on Hanselman’s blog, and Bertrand Le Roy, a PM at Microsoft, responded by saying “I really wish we could concentrate on the fantastic features in Microsoft Ajax 4 instead of discussing dogma.”, I think it’s in the public interest to highlight some of the incompatibilities the Microsoft’s proposed syntax for AJAX 4 is going to induce in your code. Not that it’s the first time either that a suggestion for MS Ajax takes liberties with standards. See my previous post from their original idea of xml scripts that were also breaking stuff last year.

So what is it that AJAX is providing in the visual studio beta 1? Here’s a partial example taken from Hanselman’s entry.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>AdventureWorks AJAX</title>
</head>
<body xmlns:sys="javascript:Sys" xmlns:class="http://schemas.microsoft.com/aspnet/class">
<h1>Customer Directory</h1>
<table cellspacing="0">
<tbody id="customers-template" class="sys-template">
<tr sys:command="select" class:odd="{{ $index % 2 != 0 }}">
...
</tr>
</tbody>
</table>
</body>
</html>

The state of affairs with the html family

Before we go any further, let’s clarify what the state of affairs is. The HTML family exists as follow:

  • HTML4.01 is based on SGML and allows empty elements without a closing />, and doesn’t support namespaces
  • XHTML 1.0 and XHTML 1.1, which are XML languages and fully support the xml namespaces, with a caveat: they don’t validate as XHTML. Full stop. See below why this is an issue.
  • HTML5 family, which has two serializations:
    • HTML5, a derivative of SGML that is not SGML anymore (so yes, we do have a third serialization format to contend with), and that only supports 3 fixed namespaces (namely html, svg and mathml). None others are recognized.
    • XHTML5, an XML serialization, that supports namespaces.

That’s the serialization formats. Now all those formats end up in a DOM, an in-memory representation of the components of an html page

  • The html 4 DOM is the DOM level 2, and doesn’t support namespaces declared in HTML. The scripting itself can however use namespaces.
  • The html 5 DOM, that supports xml namespaces (see below for caveats)
  • The XML DOM, that supports xml namespaces

Defining the language used by the example

So this is where the fun begins. As everything is lowercase, this language could be HTML4.01, HTML5, XHTML5 or XHTML 1.x. In effect, HTML4 like HTML5 are case-insensitive, while any xml language is actually case sensitive.

The absence of an HTML4 doctype means this document cannot be a valid HTML4 document. It could be an html 5 element, or one of the XHTML languages. We’ll see why it’s important later, and it all comes down to the DOM.

So, let’s move on to the attributes used in the tbody element. How would a browser parse this element to build a DOM?

  • In HTML 4.01, HTML5 or XHTML (1.x or 5) served as HTML (the only mode IE supports), the use of a colon on an attribute is allowed but is not attached to the concept of a namespace, it’s just an opaque identifier. Aka the element name would be xmlns:sys.
  • In XHTML served as XML (aka XHTML 1.0, XHTML 1.1 and XHTML5), they’re allowed and understood to be part of a namespace. Aka the element name would be sys, with a prefix of xmlns.

So now we start seeing where the problem lies. HTML languages *do not* support xml namespaces. At all. Ever. Not even HTML5. The DOM however supports namespaces in XML-based languages and in HTML5, but not in HTML4.

Ok so I mentioned that introducing xml namespaces in such a way broke a bunch of scenarios. Let’s review them.

XHTML 1.x isn’t conforming when used with xml namespaces

Bertrand Le Roy highlighted that all was fine in xml, because surely xml supports xml namespaces. While this is true, XHTML does not allow using other xml namespaces within the XHTML specification. Here’s the relevant quote from http://www.w3.org/TR/xhtml1/#well-formed.

The XHTML namespace may be used with other XML namespaces as per [XMLNS], although such documents are not strictly conforming XHTML 1.0 documents as defined above. Work by W3C is addressing ways to specify conformance for documents involving multiple namespaces.

What this means is that a document may well be well-formed xml but not be conforming XHTML 1.0 if it uses xml namespaces. That is why validators will refuse XHTML+RDFa or XHTML+MATHML are different specifications with their own DTDs.

Character entities are breaking

As it happens, without a DTD for XHTML served as xml, Firefox and any other xml-enabled browser will ignore all the character entities everybody has been scattering for too long in their pages. Yes, that even includes the sacrosanct &nbsp;

The only way for those character entities to be recognized, including in scripts, is to include a DTD.

In this scenario, the format proposed by microsoft would be a compound XHTML language requiring its own DTD in order to validate at all, unless you agressively prevent people from using DTDs.

HTML5 is broken

As I’ve highlighted before, the HTML serialization of HTML5 specifically ignores, and will not generate namespaced DOM elements, any element and attribute that is not part of either the mathml, svg or html namespaces. More than that, the xmlns attribute is ignored and allowed only for convenience.

What this means is very clear: if you’re doing an HTML5 document (as opposed to XHTML5), you cannot use namespaces.

DOM is broken in most scenarios

For those of us that use scripts, and I assume AJAX 4.0 is for scripters, this gets better. In the case where the document was served as HTML, be it that it was HTML 4.01, HTML5, XHTML5 or XHTML 1.x, the method you’d use is the getAttribute(“sys:command”).

In the case where you actually care about processing using Xhtml and serve to browsers that support this language, you’d have to use getAttributeNS(“javascript:Sys”,”command”);

For an example of the kind of trouble this provokes, see this code snippet: https://developer.mozilla.org/en/Code_snippets/getAttributeNS

So DOM is broken when using namespaces, as you now have to know in your script if you’re with a DOM that supports xml namespaces, if the page was served as an xml serialization or an html one.

CSS is broken

Because of exactly the same reason, CSS selectors don’t work in scenarios where you’re served as xml and html, or across versions of HTML.

Let’s try to write a CSS selector for the element specified above. In the scenario where the document is parsed without xml namespaces, aka HTML5, HTML4.01 or XHTML 1.x served as text/html.

Sys\:command { background: red; }

The backslash, as per the CSS specification, is used to escape a character that would otherwise be recognised. Here, I style an opaque element name with the value of “Sys:command”

So what happens when you deal with xhtml?

Sys|command { background: red; }

The syntax is different because xml namespaces are expressed that way in CSS.

jQuery may be broken

And if you think the CSS syntax is a problem, you’ll have to remind yourself that jQuery is using CSS selectors, and doesn’t support the xml namespace syntax. See the problem above.

Learning from the Aria experiments

Rather than write code myself, I’ll point you to two tests that were written when the debate on the aria extensions was all the rage. Note that the first one may be flawed because of firefox parsing the content as html. In either case, none of those scenarios have consistent results across browsers as it stands today.

  1. http://simon.html5.org/test/aria/colon-vs-dash/
  2. http://www.w3.org/XML/2008/04/ARIA-Testing/colon-test.html with description from Henry Thomson http://www.w3.org/XML/2008/04/ARIA-Testing/#three

Conclusion

I made the point, on Scott's blog, that entering the field of using xml namespaces in non-xml languages was a grave mistake that had major compatibility issues with xml languages. I was brushed off, on that blog and through twitter, with the argument that dogma was the root cause of my argument. I hope that this entry addresses this concern, and that we can start discussing a way forward that doesn’t break anyone attempting to use application/xhtml+xml as it was intended.

To recap why using xml namespaces for this scenario is a bad idea:

  • Mixing HTML and XHTML is a mess, because of the various DOM levels, the absence of namespaces in HTML, and the different resulting DOM trees.
  • Arguing that xml is extensible when Internet explorer doesn’t understand any XHTML format served as xml is just a very strange thing to do.
  • The Aria guys had the same issues and settled on a different extensibility points for those exact reasons.

My point here is not that the whole concept is wrong, it is right in a few scenarios, and comes with a lot of baggage. If Microsoft intends to deliver those features to a wide audience, and knowing their track record at warning developers of the tradeoffs of not respecting standards (and to be fair, the track record of Microsoft developers not giving a f*ck about standards and eating whatever comes from the hosepipe), they should take a responsible approach and warn prominently of those incompatibilities.

So, how to move forward? Here’s a few ideas thrown against the wall, to see if it sticks:

  • Adopt a custom style group using a CSS-like language with its own media type. Compatibility is high and it doesn’t break anything (and would degrade very gracefully across languages).
  • Rely on the class attribute and rely on JavaScript for attributing templates.
  • Enclose any template as a CDATA block that can be processed manually through the DOM by a JavaScript library. This wouldn’t break anything and would be a valid way to enclose xml-valid documents.
  • Support Sam Ruby and the TAG in pushing industry-wide adoption of xml namespaces in HTML languages, aka HTML 5 or 4.2 or whatever is going to come out of the working group.
  • All failing, put big red-letter warning signs explaining all the incompatibilities they introduce by implementing xml features when their flagship and only browser doesn’t support xml.
  • Don’t be defensive when points about your frameworks are made by the community. Don’t ask me to cheerlead you by making me look like a drag on your creativity. It’s really unnecessary if not borderline derogatory.

And the nitpicker corner, for all the things I heard before, and that I may agree with, none of which changes the result of this analysis:

  • Your css-like proposed language requires a CSS-like parser in JavaScript, it’s slow
  • Firefox, Safari and Opera also have issues with mixed HTML / XHTML scenarios
  • The W3C sucks and no one cares anymore, tag soup has won
  • Internet Explorer is right in not accepting xml languages, but still support xml DOM, cause that makes sense in an alternative reality.

Fighting for ReST, or the tale of the ice-cream maker

I keep on reading things like the following quote from wikipedia’s talk page on the ReST article (a poorly written page at that):

Decide on an unambiguous definition of REST. IMHO, Fielding lost and the engineers won. REST = XML over HTTP

Rather than point out the sheer stupidity of such a statement, let me tell you the story of the ice-cream maker.

Once upon a time, in the age of fairies and leprechauns, an ice-cream maker named Roy Fielding discovered a seed that people have been using in a remote land, called cacao. Keen on using that discovery, he mixed those seeds with sugar, milk, eggs, cream and sugar and got the inhabitants of his village to try it.

Everybody was excited about this new ice-cream. They all knew the ingredients of course, and some of them were using it, but the mixing of all of them in one ice-cream was somewhat a revelation for many. Villagers became very fond of that new ice-cream, and Roy decided to call it chocolate ice-cream. For a long time, many people in Roy’s village consumed chocolate ice-cream, and all was good in the world. That village was named Web and declared chocolate ice-cream it’s local speciality.

One day, a traveller from the village of Soap, that everybody was calling mister Sainsbury, came to the village of Web and saw how much people liked that chocolate ice-cream. You see, in the Soap village, the local dish was made of soap, and people didn’t like soap very much. He decided to bring back the idea in his own village.

Sainsbury tried to reproduce an ice-cream people would like, and put milk, eggs and sugar, but because he didn’t know about cacao, he decided to use vanilla POD instead. And he got his fellow villagers to try the ice-cream, and they all liked the ice-cream very much, all all was good in the world. And it was named chocolate ice-cream.

Mister Sainsbury knew that the rest of the country was still eating soap, and decided, as a good business man he was, that they should all enjoy his chocolate ice-cream. And as mister Sainsbury got so rich from selling soap before, he started promoting his new chocolate ice-cream in the whole country, and soon all were excited about eating chocolate ice-cream made of vanilla.

One day, an engineer from the village of Wikipedia came to Web and asked for the national desert, the chocolate ice-cream. The villagers happily provided him with a wonderful cocoa-based chocolate ice-cream. When the engineer started eating it, he started screaming:

Engineer - This is not chocolate ice-cream! It’s not even the right colour! Do you think I’m a fool?

Roy – This is chocolate ice-cream. It has cacao in it, as it always had.

Engineer – No no no! Chocolate ice-cream is made of vanilla! Everybody knows that!

Roy – No, it’s made of chocolate, if you put vanilla in it it’s vanilla ice-cream, because there’s no chocolate in it?

Engineer – You’re just an extremist, you’re trying to confuse us!

Roy –

And that’s when the villagers of Web decided that it was time for them to travel the country, and explain to people the advantages of putting cacao in their chocolate ice-creams.

I’m a villager of Web, and my mission is to re-educate the masses: ReST is *not* made of POD (Plain Old Data). It has a clear definition. It is time to get the industry back on track.

Wednesday, 10 June 2009

London AltNetBeers #9 – At the glass house

Same as usual, please register, limited space, it’s in Soho, it’s at 6:30, it’s about being a developer and talking about it, and it’s sponsored by ThoughtWorks.

http://ukdotnet.ning.com/events/london-altnetbeers-9

Tuesday, 9 June 2009

Formation nHibernate a Paris

Une fois n’est pas coutume, cette entrée sera en Français.

Vous avez sans doute vu qu’ayende a donne une formation nHibernate à Londres. Vous pouvez maintenant assister à cette formation, en Français, et délivrée a Paris, par nul d’autre que moi-même. Que demande le peuple ! ;)

Si vous êtes intéresses, envoyez moi un email et je vous enverrai les détails.

Looking for help on your project? I’m available.

I’m available for work from now, so if you’re looking for a freelance that can code, coach and teach, pop me an email.

Interfaces with static methods, reducing the cost of extensibility

Someone last week mentioned that Java was now getting static methods defined on interfaces. We’ve had that capacity, through extension methods, since C#3, and is one pattern I keep on reusing.

An interface, at core, is a contract of extensibility between me and other developers: Implement method Bla() and I promise you will be called whenever that stuff is needed. The problem with such an approach is that some functionality is repetitive and makes implementing the interface more complicated.

Let’s take the example of an interface that’s part of OpenRasta

public interface IDependencyResolver
{
T Resolve<T>();
object Resolve(Type serviceType);
}

Because both generic and non-generic methods are needed by the consumer, your initial reaction is to impose the implementation burden on the person implementing the interface.

Using static methods, we can take all that work away, and provide overloads and added funcitonality on any implementation of an interface. And it’s as simple as doing the following.

public interface IDependencyResolver
{
object Resolve(Type serviceType);
}
public static class DependencyResolverExtensions
{
public static T Resolve<T>(this IDependencyResolver resolver)
{
return (T)resolver.Resolve(typeof(T));
}
}

I now do most of the work, and the people wanting to implement the interface only have one method to implement. And everyone is happier.

Saturday, 6 June 2009

Bridging the gap between communities – ColdFusion and SOTR

Earlier this week, I attended the Scotch on the rocks conference. The organizers had the brilliant idea to invite developers from other communities with Amnesty tickets, to come and see what was happening in the ColdFusion world.

I’m very grateful they did, as this event has been an eye opener for me. I arrived with preconceptions of script people afraid of real languages hacking together un-maintainable solutions. I should know, I’m still hosting one of those for one of my clients. But this picture is inaccurate, or at least incomplete.

A community split in two

One of the sessions I attended, presented by Peter Elst, highlighted the source of some of my earlier concerns: an assertion was made that a flex developer could easily pick up ColdFusion and deliver the whole backend, without developer intervention. Without a specific scenario in mind, this assertion makes every warning sign in my synapses go red. I do believe however that this is reflective of one part of the ColdFusion community.

On the other end of the scale, Mark Drew presented multiple MVC frameworks available for ColdFusion, and talked about many of the same subjects we talk about in the .net community, including convention over configuration. The excellent Peter Bell talked about software estimation, in which TDD practices, and even Lean approaches to software development were discussed. And there is a vibrant open source community, through the use of IDE tools integrated in Eclipse (CFEclipse), and even an open-source implementation of ColdFusion, called Railo, presented by the excellent Gert Franz (can’t find a blog to link to).

From my discussions with quite a few developers after the event, this impression is widespread. While there are quite a few terrible developers and code being produced, there’s another side of the community that works on best practices and use modern approaches to software development.

In a word, exactly the same configuration as what we have on the Microsoft side of things.

Components, scripts and best practices

And indeed, I learnt much about the traditional ColdFusion development. Best practices have been described to me as a split in components, for which the signature is described in the html derivative we have all seen in the past, with the implementation being done in CFScript.

One particular thing a developer told me was that, once you add attributes to your java / c# code, it doesn’t look that much different from writing the same thing in html. And while I have a personal issue with the context switch involved, I can’t refute that there is ground to the argument.

We’re not that different

What I’ll take away from the event is the confirmation of something I’ve given a lot of thoughts about for a while: good developers are good, whatever platform they adopt. It is now my absolute belief that it is time for communities to build bridges and share knowledge of their craft, with no regard for the actual framework they use. Good ideas are worth knowing about, wherever they come from.

I’ve invited a lot of people I met to the next AltNet beers, as they are exactly the reason for my dropping the dot from the name. I really hope they accept the reciprocal invitation and help us build bridges between communities.

Footnote

Here’s a video interview done at the end of the conference, after quite a few beers.