Tuesday, April 28, 2009

Comments are the true revealer of a bad coder

Comments that are in the code of the application that you have inherited maintenance of can sometimes very quickly reflect the quality of the codebase. In this case there is obviously a bit of confusion around the subtlety and use of the cast, as and is C# operators. Yes, there is also a grammatical error. And no, I have not removed any code from inside the if block - that is all there was.


if (payment is CreditCardPaymentDto)
{
// For some reason casting this outside the if statement throws and exception
CreditCardPaymentDto creditPayment = (CreditCardPaymentDto)payment;
}

kick it on DotNetKicks.com Shout it

Tuesday, February 17, 2009

Quotes that may indicate your workplace practices waterfall methods


The functional specs will be released to the development team once they are signed off later this week. You can start development next week.

To be fair it was Monday, so I would potentially have up to 4 days as development team lead to prepare the team. </sarcasm>

I guess I'll have to spend the first couple of weeks of development time working out what we are developing...

kick it on DotNetKicks.com Shout it

Monday, January 12, 2009

Don't take shortcuts on script tags!

This problem annoyed me for longer than I would have hoped recently - even though I have seen it before and spent a frustrating time 'fixing' it. I added a script reference (the first for the page) to the head of a html page and lazily wrote it as

<script type="text/javascript" src="scripts/jquery-1.3.1.js" />

Well this broke the ScriptManager, which couldn't hook up the postback methods for the UpdatePanels on the form. Hmm that's odd, even an empty .js file included this way cause a javascript error on page load such as "this._form is null" or "__doPostBack is not defined". And then something twigged from a not-so-distant project and there it was

<script type="text/javascript" src="scripts/jquery-1.3.1.js"></script>

Lesson: Don't take shortcuts when writing script tags!

More explanation of why http://ajaxian.com/archives/why-doesnt-script-work

kick it on DotNetKicks.com Shout it

Wednesday, August 13, 2008

Dynamic Data Changes - EnableQueryStringSelection

With the release of .Net 3.5 Framework SP1, the Dynamic Data tools have changed slightly. If you setup a site with a pre-SP1 version of Dynamic Data then this issue may have bitten you.

Runtime error - "Type 'System.Web.DynamicData.DynamicDataManager' does not have a public property named 'EnableQueryStringSelection'."

This flag on the DynamicDataManager enabled that manager to ensure that when a control such as GridView is associated with another control such as DetailsView that one would update when the other changed and vice-versa. One of the downsides of this behaviour is that your associated control had to be supported by the DynamicDataManager to be able to participate in the synchronisation - so many 3rd party controls missed out. Also all registered controls participated in the synchronisation from the Url.

To reenable this behaviour in SP1 use the DynamicDataManager.RegisterControl(Control control, Boolean setSelectionFromUrl) overload when registering the controls. When true is specified that control will get its selection from the Url. So there is now a lot more flexibility in defining which control is managed from the url, instead of all registered controls being managed.

kick it on DotNetKicks.com Shout it

Tuesday, August 12, 2008

VS2008 and .Net 3.5 SP1 released

Today Microsoft released the RTM of Visual Studio 2008 and .Net Framework 3.5 Service Pack 1.

What a great milestone! Hopefully this signals a new level of maturity and stability in these two technologies. Some organisations that I have associated with have been somewhat reticent to embrace .Net 3.5 as it is still perceived as too bleeding edge.

That aside, .Net Framework 3.5 has a great uptake in developer participation due to the exciting new framework and language features that it introduces. There is great buzz in the development community around MVC, Linq-To-Sql, Dynamic Data, Lamba expressions, ASP.Net AJAX, support for Astoria, ASP.Net Entity Framework, partial methods and so on. The speed at which these new technologies and frameworks are appearing is very rapid. What's more is that these features have led to whole new areas of application and platform design options that are easier to implement, reuse and maintain.

I believe this is a really exciting time to be involved in using these tools to develop applications. It reinvigorates the community.

What changes in SP1 do you think will be most beneficial to you?

.Net 3.5 SP1 Overview
ASP.Net Debugging

Combined Visual Studio 2008 and .Net Framework 3.5 Service Pack 1
.Net Framework 3.5 Service Pack 1 (no VS2008 SP1)

kick it on DotNetKicks.com Shout it

Thursday, July 31, 2008

When RAD is just cool

Problem:
Recently faced with an application that is deep in maintenance I was asked to de-identify some demographic data for a new training environment. One aspect of the data in the database is stored in a decent sized XML blob of ~10Kb. The XML blob had some of the data that needed to be modified - names, addresses, phone numbers etc. This data is also spread out to other reaches of the database in relatively harmless tables.

Solution 1
Do data manipulation at the data store with SQL scripts. To be honest, 90% of the work is done in SQL scripts to remove unwanted data, shuffle names and addresses, randomly change DOBs etc. When doing bulk deletes and manipulations the flexiblity to easily disable indexes and triggers lends itself to TSQL and intimate database relations. However when facing the data in the XML blob and things became a little cumbersome in TSQL. So I looked to finish the job with...

Solution 2
The current application has a data model and data access, surely that can be reused. The option of taking the XSD and load/save methods of this old (Vb.Net 1.1, 1 assembly (!) ), monolithic ASP.Net website and wedge it into a console app to manipulate the data seems good on first glance. It really only took about 5 minutes of going down this path to feel a pain that really shouldn't be felt. (Think Datasets, SqlCommand, SqlDataReader and friends). Spaghetti code like this just can't be plied apart from the in-tree custom framework that it lives with. So in comes...

Solution 3
Enter RAD. I opened up VS2008 and took the following steps - new console project, register database in Server Explorer, new Linq-to-SQL designer, drag the database table to the designer. Then it was a simple case of creating a database context, iterating the rows, using XPath to manipulate the Xml and submitting the changes to the database. The end solution was less than 30 lines of code and took less than 15 minutes.


So what was cool about this? Well, I didn't write a single line of 'grunt work' - no database access, domain objects, readers or mappers - it was all done for me. I distanced myself from the mechanics of the task at hand and focused on the heart of the problem, which was updating the data.

What I learned came back to the old adage of 'using the right tools for the job'. RAD tools don't fit every application or architecture, but in my mind for throw away utilities like I was writing they provide the perfect solution.

kick it on DotNetKicks.com Shout it