Programming

JavaScript Short Tags and XHTML

Posted on

Here is another JavaScript question I was asked yesterday, which was catching out a developer using XHTML and an external JavaScript file. Users of XHTML will be highly familiar with the use of the “short tag” (this isn’t when you sell a load of tags you don’t yet have, speculating that the value of the […]

Programming

JavaScript Includes and Rewritten URLs

Posted on

I recently answered a question on a forum about JavaScript includes in ASP.NET MVC and as the question came up again today, I thought I’d share the answer with the world. The issue that people are coming up against is that they have a script include with a relative path to their script file. Because […]

Programming

Always Use Those Curly Braces

Posted on

I write a lot of code in a lot of different languages – but there is one common rule I apply to all of them… when you use an “if” block, always put in the curly braces even if you don’t need them. Many errors are related to violations of this simple style rule. I […]

Programming

Get NMock2 to Return Out Params

Posted on

There are plenty of mocking frameworks out there, with Rhino Mocks and Moq leading the way. Personal preferences aside, I am currently working on a project that is using NMock2 for mocking and found that the following feature isn’t very well known. In the process of adding unit tests to some legacy code, before I […]

Programming

AJAX Ready State Codes

Posted on

If you are hand-cranking an AJAX request, you’ll be looking for a Ready State of 4 and a Status of 200. But what other Ready State Codes are there and what do they mean? request.onreadystatechange = function () { alert(“readyState: ” + request.readyState); }; 0. Uninitialized 1. Set up, but not sent 2. Sent 3. […]

Programming

Auto Load Your PHP Classes

Posted on

In PHP you can create classes to organise your code and represent objects that you want to pass around. This has long been a feature of other languages and was a fundamentally important step forward for PHP. There was one thing, though, that I didn’t like about PHP classes. If I wanted to instantiate a […]

Programming

JavaScript and Noisy HTML

Posted on

I was answering a question on a popular coding forum and it once again highlighted the age old problem of terribly bad JavaScript. This was the HTML code in question: <a id=”image1″ href=”#”><img src=”image.png”></a> And there was a bit of JavaScript adding an onclick event to the anchor tag. An innocent looking example. An anchor […]

Programming

JavaScript Namespacing

Posted on

This is just a quick article to demonstrate a quick bit of JavaScript namespacing. Why would you do this? Well, this allows you to put functions and variables inside of an identifier. It acts like a “box of stuff” and prevents variable and function name conflicts. It also supplies a neat way to organise and […]

Programming

TransactionScope and WCF Services

Posted on

The problem I encountered was that, while I had started a TransactionScope in my calling method (and could even see a current transaction in my services) – an error in a second WCF service call was NOT rolling back the changes made in a previous WCF service call. The behaviour was as if each service […]