Gáspár Nagy on software

coach, trainer and bdd addict, creator of SpecFlow; owner of Spec Solutions

TDD Anti-patterns

by Gáspár on December 4, 2008

I’ve just found this very good collection about TDD anti-patterns in James Carr’s blog and also some extensions (and prioritization) for it in stackoverflow. It’s much fun to read it and it is very useful.

Some of my favorites:

The Mockery – Sometimes mocking can be good, and handy. But sometimes developers can lose themselves and in their effort to mock out what isn’t being tested. In this case, a unit test contains so many mocks, stubs, and/or fakes that the system under test isn’t even being tested at all, instead data returned from mocks is what is being tested. (James Carr)

Now you see me, now you don’t — Children at play (Aaron Digulla)

The Nitpicker – A unit test which compares a complete output when it’s really only interested in small parts of it, so the test has to continually be kept in line with otherwise unimportant details. Endemic in web application testing. (Frank Carver)

The Peeping Tom – A test that, due to shared resources, can see the result data of another test, and may cause the test to fail even though the system under test is perfectly valid. This has been seen commonly in fitnesse, where the use of static member variables to hold collections aren’t properly cleaned after test execution, often popping up unexpectedly in other test runs. Also known as The Uninvited Guests (James Carr)

Second Class Citizens – test code isn’t as well refactored as production code, containing a lot of duplicated code, making it hard to maintain tests. (Ilja Preuß)

MVC through StoreFront Videos

by Gáspár on December 3, 2008

When I started with my MVC research, I was very happy to see that there is an end-to-end sample from Rob Conery that shows how to develop an application with MVC. And it even uses TDD… cool.

I admit that I have not watched all of them, but the entire series is about 11 hours long, and based on the titles, the first 13 parts were enough for what I wanted to achieve now (I don’t need a richer client, no OpenID, no WF, Logging, PayPal… at least not now).

Now I know that this video series is not good for learning MVC and not even for learning how to develop a web application. For this reason I would not recommend it to anyone.

It is only good for giving you more self-confidence: the others also suck a lot…

Why StoreFront video series is not good for learning MVC:

  • You should not start watching it from the beginning, because Rob does so much refactoring during the development that you should basically forget everything that has been told in the first episodes… they will be invalidated later. E.g.: In the first MVC related episode (#6), he starts with rules, like: “Use an AppHelper class to get content links, and don’t use hard-coded links.” Practical rules! Cool! But if you check the final source code, the AppHelper class is still there, but it is not used at all, all links are hard-coded. What happened? The answer is somewhere in the 9th video stream between episode #7 and #23, but who knows where?
  • You cannot start watching it from the later episodes however, because they heavily depend on the previous ones. You won’t understand anything.
  • It has too much architecture and TDD, and not enough MVC. I think the back-end architecture is far too complicated for this application, and it is sometimes even confusing (see more below). I’m also not sure whether TDD is efficient in the way he does. On the other hand, the final application hardly uses any features of MVC: no validation, no special routes, no real edit forms, etc.
  • It does not solve the problems that you run into if you want to develop a web application using MVC. At least I could not rewrite my 5-page application based on these videos.
  • Finally, I would not recommend the videos for junior developers who want to learn about MVC, because the application architecture is a screwed-up IMHO. It is not really clear for me.
    • He uses two models: one for the db structure and one for the business logic (ok, he also explains that the business domain model can hide the details of the multi-language db structure. Unfortunately the globalization is finally removed from the db, so then what?)
    • He uses an IRepository pattern to access the database objects, but somehow a part of the business logic sneaks into his repository.
    • In this setup, the business domain model entities should be detached from the database logic. But here, these objects may hold references to the repository.
    • He uses a strange lazy loading mechanism to access related entities in the business domain model. Normally you should have lazy loading in the DB model, and only explicit operation in the business model. This way of lazy loading is much less optimal than the ones that OR/Ms can do, but he still has all the disadvantage of attached entities.
    • He has services for storing the business logic, but the logic is somehow scattered around the different other parts.

But still, it is good that Rob created this video series, and actually I think that he was very brave to start with it. I think it is very interesting to see how others develop applications, how they react on new ideas or suggestions of others. I do the same! I also refactor the code, I also make architectural mistakes (and it is not always possible to fix them). It is just not good for MVC learning.

(Not belonging to the topic directly, but the way Rob does the video feeds is very professional. If I’ll have time, I’ll collect the ideas that I have stolen from it in a post.)

ASP.NET MVC Framework Study

by Gáspár on December 2, 2008

After PDC, I started to investigate the ASP.NET MVC framework more deeply.

Back in 2001, when I joined TechTalk, the company was developing a web development framework called TTIC.NET. I guess there was even a TTIC before, but when I was hired, they were already working with .NET (1.0 beta).

I don’t remember how far we got with TTIC.NET, but we aborted the project in 2002 and as far as I know there is only one application running today that uses this framework (our internal bugtracking application). But interestingly, now as I’m doing some research on MVC, I feel a little bit like in 2001, confronting the same problems and suffering from the same issues. Or at least similar ones. TTIC.NET used MVC pattern to display the data, although there were no generics, ajax, extension methods and such things. MVC is a quite old pattern, with its own problematic points. I somehow hoped that with the new ASP.NET MVC framework everything would be smooth and easy. But it isn’t. It isn’t yet.

In this blog series, I would like to document the way how I learned about the MVC frameworks and what problems I have encountered. Most of them are still unanswered, and as I’m moving on with my research, I would like to find the answers to these questions.

I have started my research with checking out the videos and tutorials at http://www.asp.net/mvc/. After that I tried to rewrite one of our code samples for Genome to use an MVC front-end (keeping the back-end and the UI design) with more or less success.

(In the articles, if not mentioned explicitly, with MVC I’m always referring to Microsoft ASP.NET MVC Beta.)

PDC Summary

by Gáspár on December 1, 2008

With three other colleagues, I attended PDC 2008 in Los Angeles. Here is my short overview about my feelings after that.

Although it was very exhausting to be there, especially after that long flight, I think it was worth. Why? Because I aligned myself to the actual state of the technologies that are currently running or planned in the Microsoft world, and this helps me select what to study more deeply, what can be interesting for us in the near or far future.

I was also interviewed there by István Novák for Channel 9 Hungary. The interview is in Hungarian, but you can at least see me talking in a strange language… ;-)

The topics that were interesting to me:

New CLR version: for me, the new CLR is about loosening the tight coupling between the interfaces defined in different assemblies. Although generally I’m more for the strongly typing, I see this as a necessary improvement. We have also encountered the problem many times that supporting common interfaces between modules defined in different assemblies is hard. And it gets even worse, if you have to support older versions of the interfaces. The solution was there (you can always introduce a new assembly with the common interface parts, and since the runtime checks the existence of the references only when you first try to use them), but it was painful and ugly sometimes. So let’s see what we got now.

New C# version: I have strange feelings about the development of C#. I like the new features (dynamic types, optional and named arguments, and most importantly the covariance and contravariance of generics), but I also see that it somehow does not fit nicely to the hacks that they did in the language in 3.0 (extension methods, partial methods, and partly the way how linq was defined). It will be really hard to understand a C# code without IDE.

Oslo: Yes! I think we have missed such a thing very much in the MS community. Especially together with the modeling tool “Quadrant”. I used the MS DSL toolkit, but it was not the ideal solution for software factories, so now I’m very interested in this project. I think, however, it was not presented well. Maybe the samples were not chosen ideally, or maybe there should have been more explanation about the possible usages of such a tool… I don’t really know. But I talked to many people who were not really in the know, what “Oslo” is about.

Azure: Hm… this caused the biggest confusion for me when I wanted to rate how much I like it. Generally I like the idea to build a platform for really distributed and scalable applications. And I think MS is strong enough to provide the technical background of such a platform (based on .NET, and the data storage and sharing experiences they have). But the idea that MS will be the only provider, who can run this platform… it is a little bit frightening for me. But we will see (and of course MS is not different from the competitors in this regard… they are frightening too…). The other concern I have currently about Azure, that they don’t have data centers in Europe yet… But this one will change for sure. Until that we should get familiar with the platform.

ASP.NET future: As Christoph says: “classic ASPX Development will die”. Although I’m sure that this will not happen in the near future, but it is true that the new features do not really bring in anything new. Everybody is either talking about MVC or simple asp.net pages powered up with Ajax (or the combination of these). The new features? Possibility to specify the client ID of the rendered html controls, possibility to influence the routing, enhancements of view state handling (can be switched off more accurately :).

ASP.NET MVC: This made me the most excited. After PDC I thought that now it finally gets usable. Now, when I am writing this summary, I have already dug deeper into the topic, I have a lot of unanswered questions. I will write separate posts about them. But I still believe that this is a platform that should be seriously considered for larger web applications. Maybe for shorter ones too…

ASP.NET Ajax: Sooner or later MS also realized, that an Ajax framework should be something more than the UpdatePanel (which is a wrong concept IMHO). Now we have the way to write dynamic applications that can communicate with the back-end asynchronously, load the data (json), and render them out on the client side, with client-side templates. And of course, let the users benefit from the existing ajax codes, written in jQuery. The direction is good, but I still have to see a real-world sample to see the pain-point of it (there are for sure). The first question: how client side templates will be maintainable for a complex case, and how can I extract and reuse them?

Open XML SDK: A minor session, but I worked with the previous versions, therefore I was interested. I think with the new SDK, the manipulations of the OpenXML documents will be really easy. There is a nice DOM wrapper around the XML structure, that you can use to operate on the document parts easily and without loosing too much performance. (You can switch back to XML, if that’s more easy to accomplish a task.) They even created a LINQ provider to query the documents using the DOM in an efficient way. Nice!

Entity Framework: As an ORM vendor, it was a little bit funny to see how proudly the EF team announced new features that had been existing in other products for ages. And the audience applauded… it seems that you have to be MS to reach massive crowds with the idea of object-relational mapping. The new version will come out in fall 2009, with lazy loading, attributed/automatic mapping, complex types and model defined functions.

WCF: I think WCF proved that it was really designed for future extensibility. The new features (to support REST) just fit seamlessly to the design. Not a surprise, Azure used the WCF architecture almost as it is as service interface.

REST: I have been against REST for a long time, but with the nice support on both client and server sides (WCF, Ajax, Silverlight, ASP.NET Data Services), this seems to be much more useful as a communication platform for communication between the different tiers of an application. This is again something that has to be tried out in a project.

Windows 7: I don’t have too much to say. It is a usable Vista. I have already installed it to an old laptop, and it is working (except IE8, that sometimes does strange things, but Firefox runs fine on it).

Parallel programming: There were many sessions about parallel computations. And to tell the truth, I don’t see yet the relevance of it in our applications (server applications with web front-end). I think I really have to dig into this to see the full picture, and maybe I’ll collect my thoughts in a separate blog.

Visual Studio 2010: The new VS is in a very pre-beta stage, it did not survive any session without restarting it a few times. But the new features are good IMHO. There is a new project type for UML diagrams (we don’t have to sweat with Visio to include a simple diagram to the project). Code structure reverse engineering – a nice tool to have a visual overview about the project/code structure and the dependencies. Ideal for code reviews and to continue working on existing projects. And yes! A nice WPF editor, including data binding expression editor, and data binding expression intellisense in the xaml file. Interestingly, there was hardly any session about VS extensibility. It was only mentioned in the keynote, that VS2010 comes up with a new WPF code editor that has new extensibility points.

WPF: Three new controls: ribbon control (like in Office 2008); date time picker control (finally); grid control – nice and seems to be usable even in a little bit more complex scenarios (like an additional expanding detail row under the selected row).