This blog contains reflections and thoughts on my work as a software engineer

onsdag den 21. januar 2009

Subsonic - not so good enough

For a week or two I've been researching the market for ORM-tools. I know quite a few by name but never tried any of them except Linq2Sql - and with the change in strategy by Microsoft (they've decided to go with Entity Framework instead) it doesn't look like a choice for the future so I went looking for something else. And Entity Framework isn't one of them - for obvious reasons.

I have tried SubSonic on a project I've been working on for the last two evenings. I was thrilled after watching the screencast and made it work within an instant in a demo application I made while watching the video the second time.

So - I fired up a new VS solution, added a website project and another class library in which my DAL abstractions would live - like this:

image

And then I was soooo disappointed to learn that once I hit a method in ErrorLoggerAPI which encapsulates Subsonic controller classes I would still need to have a SubSonic section in the web.config of my ErrorLoggerWeb project! There is a workaround to this where you programmaticly initialize your connection but it requires extra work and all your SubSonic controller classes has to be modified to make this work. I wasn't exactly thrilled by this discovery - the maturity index dropped quite a lot uncovering this flaw (I call it a flaw - so sue me... I'm a bit grumpy right now)

Of course one could download the source files from the SubSonic project, make the changes and call it a day... Until a new version comes and the problem persists in the new version. Or one could contribute to the SubSonic project and solve the problem for the entire community for eternity. Or one could just get it off one's chest by writing on his blog and conclude that nothing never is as good as it seems. SubSonic looks promising and there might be a better way to solve this problem but it was a showstopper on my current project. I don't want to pollute my web.config file with configuration stuff about persistence - why should my website be concerned with issues like that? It should be handled by configuration stuff elsewhere - in business logic and persistence layers where stuff like that belongs.

Regards K.

onsdag den 14. januar 2009

How to resize IE with just a click of a button

I'm won't take credit for this one - but I nevertheless want to spread the word:

  • Create a shortcut in your IE Favorites or in you Links folder.
  • Rename this shortcut/favorite to "Resize Window to 1024x768".
  • Edit the properties of the shortcut and place the following line of javascript in the URL property.
    javascript:window.resizeTo(1024,768)
    Note:
    You will receive a warning prompt. Simply proceed.
  • Save the properties and then click your new favorite Resize Window to 1024x768.

    You should give Mark Wagner a pad on the shoulder next time you see him - :o)

    Regards K.

    P.S. - It only works if you have only a single tab open - nothing happens when multiple tabs are open at the same time


    UPDATE: Download the Internet Explorer 8 Beta II and use the bundled Developer Tools to resize your browser window - regardless of how many tabs are open.

    tirsdag den 13. januar 2009

    Teach yourself X in Y days

    Did you know it takes about 10 years to become good at something? Read the following paragraphs:
    You probably know them - "Teach yourself X in Y days" - let X be Java, C#, Webforms and Y could be anything ranging from 7 to 30 days.

    I read a post today on Coding Horror - you really should subscribe to his writings if you don't do already. He has quoted from Peter Norvigs "Teach yourself programming in Ten Years" - basicly, he says, it is old news that it takes time to become a superstar in anything:

    Researchers have shown it takes about ten years to develop expertise in any of a wide variety of areas, including chess playing, music composition, telegraph operation, painting, piano playing, swimming, tennis, and research in neuropsychology and topology. The key is
    deliberative practice: not just doing it again and again, but challenging yourself with a task that is just beyond your current ability, trying it, analyzing your performance while and after doing it, and correcting any mistakes. Then repeat. And repeat again.

    There appear to be no real shortcuts: even Mozart, who was a musical prodigy at age 4, took 13 more years before he began to produce world-class music. The Beatles seemed to burst onto the scene with a string of #1 hits and an appearance on the Ed Sullivan show in 1964. But they had been playing small clubs in Liverpool and Hamburg since 1957, and while they had mass appeal early on, their first great critical success, Sgt. Peppers, was released in 1967.

    I don't know much about Norvig (I heard about him but never read anything) - I need to visit my favourite online book-pusher in the nearest future... :o)

    Regards K.

    P.S. - Actually I think this Mr. Norvig is a bit of a geek (a major one actually) - who would ever get a kick out of a "world's longest palindrome contest"?

    onsdag den 7. januar 2009

    Different roles in a SCRUM team - how to do?

    A few months ago we decided to extend our team with a new role - the design role. The reason for choosing to employ a designer rather than another serverside developer was to improve our ability to guide and reason our Product Owners about the layout and design of the systems we're working on. Being serverside guys the layout and design process incorporated the de-facto It's-Ugly-But-It-Works standards seen worldwide. So - a designer was employed in Mid-October and has worked with us on a project that began 1. of October.

    Today after a Sprint Planning One our new designer raised concerns about the stories we are to work on during the sprint in February. We realized that questions such as "What's the identity of this new website we're launching February 1st" had never been answered properly so the stories we created before the October sprint and up until today didn't reflect any thoughts about layout and graphics. What we had was a lot of functionality (a feed-reader, data-standards, a Lucene index for searching etc.) which reflected what the user was supposed to be able to retrieve... Not a single story about design of the markers on the Google-map which is a vital part of the new website. Nothing about what the logo should try to express or if the site should have a visual pattern or layout which would enable a user to recognize it as a subsite of our main website. It has resulted in our new designer working on tasks not directly related to the stories we've created and estimated - some times she's been working completely on her own without anything being reflected on the task board which breaks our SCRUM process in terms of visibility and ability to provide feedback to our Product Owner.

    We knew before hiring a designer that bringing in a new role to our consolidated team of serverside developers would be a challenge - we couldn't really point our finger to how it would show itself but It struck me how used I've become to think in terms of functionality when reflecting upon stories in our backlog - for example: "I need to know where data is coming from before I know when it's done". That's what I think about when reading a story description - I never come to think about how it is supposed to look and feel on the website. I consider it to be similar to my wife at home who once every three months points a finger at me and tell me that I mess a lot at home. I do - because I don't see my three jackets hanging over three different chairs in the living room instead of resting on a coathanger in the hallway. I don't see that all the pillows are stacked in one end of the sofa - it's not that I don't want to I just don't see it. I guess it's the same way when I read a user story - it's not that I don't want to see the design challenges and issues - I just don't see them and I could imagine that the same rule applies to a lot of serverside, hardcore .NET developers with a hang for unittesting, automated builds using CruiseControl.NET, deploymentscripts etc. etc. It's hard to see things or problems you don't know exist and that's the challenge we're facing right now.

    The way we're trying to overcome this challenge right now is to implement the following:

    • This sprint will have a story called something like "Design and identity of website". The tasks are to be defined during Sprint Planning II (this afternoon). This story is not estimated so it will act as a placeholder for the design tasks requested prior to launching February 1st. The main goal is to improve our understanding of the tasks related to the design process.
    • Upcoming projects will have stories focused on design and identity during the first sprint(s).
    • Working in Adobe Photoshop shouldn't be regarded as "Design" tasks. We're a team (swim or sink as one) so at least one of the remaining teammembers should at least have a clue about where to find PSD files and be able to navigate in them.

    We had a discussion about the fact that if you're working in a team everybody is working on the same story always. Is this always true - is it impossible to have a Design role working on future project's identity and wireframes while the rest of the team are working on implementing features on the project which is up for release? I think it is like having a Tester role - they should be able to work on enhancing i.e. test suites for the entire suite of projects regardless of what the Software Programmer role is doing. If you define a role as being what are most likely to be doing on a daily basis - is it wrong to even think in terms of roles in a SCRUM team? Note: the Product Owner and ScrumMaster are SCRUM roles - I'm talking about the different roles within the role SCRUM Team.

    We have committed ourselves to be doing SCRUM by the book so I'm curious to know how other teams are integrating different roles in their daily work using SCRUM. Please leave a comment if you have something to share - I'm all ears  :o)

    Regards K.

    mandag den 5. januar 2009

    Definition of SOLID

    What's SOLID? I've came across the acronym a few times but never took the time to look it up (I guess a Google search would have taken no longer than for you to read these two sentences...)

    Anyway - I came across it again while reading a post submitted to DotNetKicks and found a link to Pablo's topic of the month. Basicly SOLID is an acronym built upon five acronyms (no, it's not April 1st) - and they are:

    • SRP: Single Responsibility Principle
    • OCP: Open/Closed Principle
    • LSP: Liskov Substitution Principle
    • ISP: Interface Segregation Principle
    • DIP: Dependency Inversion Principle

    That's what SOLID is. All in all five architectual best-practice design principles which are good to know in order for you to get things "right" in the design of whatever system you're working on. Agreed - I'm really only paying attention to the first one since so I won't preach the importance of all five of them to you.

    There are numerous links to a detailed explanation of each of the five acronyms so I won't repeat them here - go check it out for yourself :o)

    Regards K.

    søndag den 28. december 2008

    Buy it - just buy it.

    The best thing about Christmas is the days off from work. You get to spend a lot of time with your family and that's great. You also get to see a lot of movies in the TV - which is nice because I like to see a good movie. I don't see a lot of TV basicly because I choose otherwise - my life probably goes on even though I don't know who got voted off the island during the last episode of Survivor / American Idol / Big Brother / (insert any mediocre TV-show here)...

    You also get to read a lot so I've finished the book I blogged about three days ago - Michael Feathers Working effectively with legacy code. The short story is: Buy it - I was completely sold on his final appendix where he goes through all the various ways of decoupling dependencies - each example is followed by a codeexample and each example and explanation covers about two to four pages. Extremely nice setup and well thought.

    One of his examples is the "Extend and subclass" refactoring. I never thought of that one but it is so obvious and offers lots of advantages with only a few minor disadvanteges so I'll share it with you here:

    ...(and 15 minutes passed...)

    No excuses: I have failed to come up with a decent coding example on my own - the code just turned against me once I looked at the time and found out that one of the three "Lord of the Rings" are beginning in 5 minutes... Not that I haven't seen all of them at least 3-4 times but this is Christmas and about the first vacation this year which doesn't include a lot of work on our house or trips to far-far-away family - so watching a movie I've seen before and NOT get up from the couch and get some work done is really a new sensational feeling..... I could probably learn something by doing a bit of coding on the issue I'll just find a perfectly good example written by Jimmy Bogard for you  :o)

    I'm off to see some orc bashing. Happy New Year to all of you - see you in 2009  :o)

    Regards K.

    torsdag den 25. december 2008

    TDD on untested code - why does the first test take so long?

    Most software developers have at some point in time been assigned a task with the following description: "We need to extend report X with a new column which sums up all the other columns in each row" - or something like that. Even if you don't know anything about the codebase tasks like this one in most cases don't cause too much trouble because you extend already something which is already working and in production. Even if you like to deliver this new functionality with shiny tests with 100% coverage of the new functionality it isn't a big deal because you don't have to touch the existing armageddon of untested code.

    Worse - much worse is the task assigned to you the next day which says "Well - we have this bug in our invoicing system which causes all sales on the 1. of January to never show up in our reports. We need you to fix it". Even if you know that the invoicing system is a pretty decent working piece of software without a lot of maintenance - you also know that it has a mere code coverage of about 2%... When asked "How long will it take" what do you respond?

    If you and your team are on the TDD side of things I have always been astonished how long it takes for someone to take the first step towards TDD-enabling untested software. However after having read the first 10-or-some chapters of Michael Feathers Working effectively with legacy code I am beginning to put words to my gutfeeling of "This will probably take a while..." when I see a change request to a system I know doesn't have a decent testsuite attached.

    You've been assigned the task and you need to write your first test - why does it take forever to write it? Michael Feathers goes deep with numerous code examples but from a birdseye view it all sums up to the fact that before you refactor the dependencies in your untested code you can't write a suite of good unittests. Unittests must be kept as short as possible - I've heard the "No test should be longer than 15 lines of code" and it is a good best-practise to follow. Of course it doesn't always happen but if you have to write 20 lines of code to set up your test you need to look for design smells - most notably violations of the Single Responsibility Principle on the class or classes you are testing.

    What I've recognized after reading these chapters are that code which have been developed without testing in mind have lots of dependencies to other classes. I've whupped up quite a few of myself - no doubt about it. When all you do is write code and never actually use your own code in a test you'll never get to see how your code "looks" from the outside. You basicly just make things work - and whoever is left to use your code after you have signed off on a task are pretty much on their own. This is how i.e constructors and methods with 10+ parameters are being born - I've seen them in my entire professional career wherever I've been - if you are "coding away" and need an extra parameter, you change the signature of your method, change the caller to use your new signature and everything is fine - from your perspective. What happens is that the more parameters you pass into a method the more state you will have to set up in your "Arrange" section of a unittest. Given that the more parameters a method or constructor takes the more state is injected your tests of that method will also be bigger in terms of lines of code - and long "arrange" sections in your tests are as much of a codesmell as any other codesmell you can think of.

    The first test you write on untested code will have to take into account the time spent refactoring all the intertangled dependencies you dig up trying to get to those precious three lines of code you want to test on. It's a fact of life - get used to it. You might have to split up large classes, move object creation to constructors, extract interfaces to be able to mock dependant libraries etc. before you can actually make the single test that solves your problem turn green... The next time somebody has to write a test on your refactored code it will be easier - but the first test takes the longest - and the first test is also the one people fear the most because there is no other tests around to back you up when you begin to alter working code.

    I agree with him on most of his writings - not everything though. He actually promotes writing "characterization tests" for already existing code "to be able to test for the existing behaviour". I disagree with him. The time you spend writing tests on existing code could be better used focusing on solving the problem you have before you. It's a mere waste of time in my opinion - when do you know enough and have written enough tests to conclude that the core existing behaviour is covered and documented in your tests? No sir - Keep It Simple Stupid, just get the job done. Use some of the many useful techniques he has documented but please - don't write tests for existing code. He means it well but honestly - it's just not valuable work to write code for existing functionality.

    Even though I'm not finished with the book I can highly recommend it to anyone who just wants to be able to navigate through untested code without causing too big waves in the pond. It's a good book with quality stuff in it - definately one I will use to plan my attack on codebases that I've never touched before

    Regards K.