Showing posts with label TDD. Show all posts
Showing posts with label TDD. Show all posts

Thursday, November 21, 2013

JQuery Meetup & Unit Testing


Last night was a JQuery Meetup, hosted at Q. I decided to attend; I'm trying to push myself into the whole world of Javascript/JQuery. Which means, for a hard-core Java server guy, that I'm pushing myself out of my comfort zone.

That's always a good thing. TheHackerCIO believes in continuous pushing out of the comfort zone; pushing the edge-of-the-envelope.

The Transcript

I really like these Meetups, regardless of the underlying technology, because of the method of presentation. Natalie MacLees, who runs them enters her sample code and runs it all live. So any errors have to be resolved on the fly. This is amazing productive of insight. I love it. Last nights showed implementation of a slider.

The second interesting technique she uses is this: after the code works, she begins showing variants. For instance, you could have written this line in a shorter idiom, in this way. See the results! It's way cool. Last night she had at least three successively more condensed iterations.

The second presentation was on QUnit, a TDD testing framework for JS. I picked up one point about TDD worth reflecting on, since I don't do that many bug fixes these days, which was that prior to fixing a bug, you should write the test showing the code Red. Only then should you fix the bug and change state to Green. Thus you now have a regression test guarding against inadvertent reintroduction of the bug.

End Transcript

My own problems centered around getting jQuery installed on my follow-along PC. My sublime editor had to be reinstalled, then I had to get jQuery downloaded. So I fell behind in entering the code along with Natalie. But she promised to post a link to the code, which I will add here, when I see it.

I Remain,

TheHackerCIO

Monday, October 28, 2013

Software Architecture



Today, even the notion that there should be software architecture is up for debate! Regardless of what verdict one arrives at,  it is a good thing to examine whether something should exist prior to investing time studying it.

[editorial note: this post commences an occasional series on Software and Enterprise Architecture, in which I hope to collect all the principles into one convenient place. We begin at the beginning: should there even BE a discipline of software architecture? ]

There are a number of "nay-sayers." But I think they can all be classified as variants on the notion of "evolutionary design," which contrasts strongly with the notion of engineering, design, and deliberative architecture. The idea is that design is an emergent property that will manifest itself as the work unfolds. The Wikipeida article puts it this way:

Emergent design in agile software development[edit]

Emergent design is a consistent topic in agile software development, as a result of the methodology's focus on delivering small pieces of working code with business value. With emergent design, a development organization starts delivering functionality and lets the design emerge. Development will take a piece of functionality A and implement it using best practices and proper test coverage and then move on to delivering functionality B. Once B is built, or while it is being built, the organization will look at what A and B have in common and refactor out the commonality, allowing the design to emerge. This process continues as the organization continually delivers functionality. At the end of an agile release cycle, development is left with the smallest set of the design needed, as opposed to the design that could have been anticipated in advance. The end result is a smaller code base, which naturally has less room for defects and a lower cost of maintenance.[1]
As emergent design is heavily dependent upon refactoring, practicing emergent design without a comfortable set of unit tests is considered an irresponsible practice.[citation needed]
I have to laugh at the last line: "practicing emergent design without .. .[snip] ... is considered an irresponsible practice." It reminds me of the Moliere comedy, Le Bougeoise Gentilhomme, where the man finds he has been speaking prose all his life and didn't even know it. Likewise, many a team has been practicing "emergent design" for decades and thought they just hadn't used an architect.

There are a lot of parallels here with methodology pathology. Just adopting an agile or iterative methodology is not a silver bullet.  Process does not automate success! [The Rothering Principle] TheHackerCIO has seen plenty of projects with churning iterations that never seem to get anywhere; just as he has seen Waterfall projects that can't get out of one phase and into another, or that allow phase leakage. Process alone cannot ensure the absence of pathology. The Capability Maturity Model of Carnegie-Mellon seemed like a good thing, and I was a proponent of it, until I worked with outsourcing companies in a particular subcontinent (which will remain unnamed), all of whom were CMM level-5 certified, and none of whom could deliver one useable module of code to our project. I'd love to have seen a post-mortem analysis of how their coding failures made it back into the "feedback-loop" of their CMM program!

One manifestation of this attack is the TDD methodology. Taken rigorously, it directly assails the need for architecture: you are to take your assigned User Story from your Product Backlog, and after coding your first test case -- mind you, not one line of actual code has yet been written!!! -- after coding that test case, you now enter the "red" state, and are to determine ... what?
  • The best way to structure your code to allow for future eventualities? No! 
  • The best approach to code this method, so that you can reuse existing code? No!
  • The most elegant set of methods that will allow for maximal flexibility? No! 
  • A higher degree of generality to accommodate use cases that are going to come? No!
The principle adhered to here is YAGNI!

In contrast to attempting to architect, engineer, or design, one is supposed to take the directest, clearest, fastest path to implement the user story, at least a portion of the user story, and nothing but the user story. You are to "just do it," as the Nike slogan goes, and when your test-case passes, you enter the "green" state. At this point, you are to consider refactoring the code you just wrote, to achieve whatever an Architect or designer might have attempted upfront.

This is a direct assault on the notion of architecture, or on the need for it.  There are others.

Next up: Patterns and Pattern Languages

I Remain,

TheHackerCIO