Reading Time: 2minutesAsk Toolbar: Nothing to do With Java
I’m calling Oracle out on this.
I spent the first 5 years of my career working with Oracle and I used to like them. Now though the only regular interaction I have with them is unticking the “would you like to install the Ask toolbar?” box every time there’s a Java update.
It does not give a good impression. Installing software isn’t something that’s particularly well understood by the man on the Clapham Omnibus. There is a certain fear that if you don’t do what you’re told then the software might not work properly. So most people just accept the defaults on the basis that this should work.
There is also the factor that software updates often ping onto your screen when you’re in the middle of something else. So you want to get it out of the way quickly. Again this tends to make people just click the defaults.
If you do that here you end up installing a piece of extra software that has nothing really to do with Java other than it being owned by Oracle. What’s more it’s something you almost certainly don’t want.
I have no problem with vendors advertising their other products in an install sequence and I don’t have any problem actually with them offering to install it.
There are two things that I do consider bad practice.
Failing to clearly distinguish that you would be installing something other than (or as well as) the product you initially intended.
Installing the software by default. The default should be not to.
Oracle isn’t particularly bad on the first one, one could say that the dialog looks like you’re accepting the licence agreement for Java but actually it’s reasonably clear. Oracle are a little marginal here for me. There are far, far worse offenders out there.
The second however is a straight red card. No way should an installer by default install something that the user didn’t ask for.
Reading Time: 3minutesTo Finish First, First You Have To Finish
I’ve just been bitten. It’s one of the standard strap-lines of software development teaching – do it properly first time, don’t hack it and think you can fix it later. When the deadline is looming however sometimes we have to make a business decision;
Do we drop the feature (or some other feature)?
Do we miss the deadline?
Do we hack it in the full knowledge that we may be bitten later?
Fortunately for us software developers, technical debt is beginning to be understood by business managers. I explain it to non-techies like this;
I could hack it and get the feature in, but if I do that might be storing up problems for the future. Next time we want to add a feature in that area or even fix a bug we might have to unpick the hack and implement it properly before we even start on new work.
Hacking it now is borrowing time from the future – at some point we’ll have to pay it back and we’ll have to pay a wedge of interest too.
A few years ago I spotted a design problem; we’d assumed that something was always related to a location. In some circumstances however it could actually be related to a vehicle.
We should have changed the database to account for this, but that meant changing pretty much every component of an n-tier system and the deadline was busy whizzing past our ears.
There’s no way we could drop the feature so I had to find a solution. What I noticed was that I could cast a vehicle ID safely into a location ID without any possibility of coincidence. We could then detect in the DAL if it was actually a vehicle and generate a fake location record that actually contained all the information we needed.
A few years later and now we’re noticing that customers are putting a whole load more records in the location table than we’d initially thought and the indexing performance of the ID type is poor. So we want to change the type to something that indexes better. None of the options available allow us to cast a vehicle ID to a location ID any more.
Since those early days the problem has been exacerbated by the fact that more and more code has been piled in on the assumption that you can safely cast a vehicle ID to a location ID.
So we’ve now got a considerable amount of code to unpick, we’re going to have to do the redesign and reimplementation work that we (perhaps) should have done in the first place, then we can start looking at improving the index performance.
In situations like this it’s easy to look back and curse the past decision. Go into any software development office and you’ll almost certainly find a developer (or several) swearing at the screen, decrying previous decisions as “stupid”, “short-sighted”, etc.
I know I’ve made mistakes, I know there are situations where I’ve chosen to incur technical debt where there were better alternatives available. On this occasion though I made the right decision – we have time to repay this debt now. Back then we most definitely did not.
So “never hack it” isn’t a rule, it’s a guideline. But you have to be aware of the business consequences if you choose not to follow it.
Not a Fan of the Empty Catch
We’ve been having a bit of trouble with a small piece of software on a customer site. It’s just not working and there are no indications of why. So I cracked open the source and found a light dusting of these…
try
{
SqlConnection = new SqlConnection(connectionString);
//the rest of the Sql code
}
catch (SqlException)
{
}
Oh look, it’s an empty catch. An empty catch is about as justifiable as a goto – I’m not saying that you should never use one, just that you need to have a good hard think about what you’re actually doing and consider carefully whether or not you’ve got the structure of your code correct.
The case against is easy to see above; although it may be normal for one type of SqlException to be thrown and ignored (perhaps as the result of a deadlock), you can’t guarantee that every SqlException is thrown for that reason. In the deadlock example your code should more follow this pattern.
try
{
SqlConnection = new SqlConnection(connectionString);
//the rest of the Sql code
}
catch (SqlException ex)
{
if (1205 == ex.Number) //deadlock (see http://technet.microsoft.com/en-us/library/cc645603.aspx)
{
//we ignore deadlocks
}
else
throw;
}
This tests the SqlException to see if it’s a deadlock and ignores it – if it’s not a deadlock then it re-throws it.
I would argue however that this doesn’t go far enough. Exceptions should not be used for flow control which means that the very fact an exception has been thrown indicates that something has gone wrong. If you’re not going to handle that in code then the very least you should do is enable someone to find out that it happened.
There are many logging and debugging gizmos out there (such as log4net) and they usually contain a concept of levels of information. It would be a rare circumstance indeed where an empty catch was preferable to a minimal debug log, e.g.
try
{
SqlConnection = new SqlConnection(connectionString);
//the rest of the Sql code
}
catch (SqlException ex)
{
if (1205 == ex.Number) //deadlock (see http://technet.microsoft.com/en-us/library/cc645603.aspx)
{
log4netInstance.Debug("SomeOperation caught Sql deadlock => {0}", ex.ToString());
}
else
throw;
}
If this exception is normal and the app is expected to cope then you can turn the “Debug” level of logging off in configuration. If the app starts having problems then you can turn the “Debug” level back on and see all the exceptions that are being thrown. A subtle little thing like this can make a big difference.
On the one hand we have a quick phone call to one of the customer’s IT pros to explain that their recent security audit has resulted in them accidentally revoking the app’s authentication to the DB and that perhaps they’d like to reverse that.
On the other hand we have you, the developer, being sent to the customer’s site where you have to explain to some very senior people why your application has stopped working and what you intend to do about the poor quality, unreliable piece of software that you’ve supplied.
Never underestimate what can happen to your app on a customer site: Murphey’s Law is one of the fundamental underpinnings of computer science.
Reading Time: 5minutesSurface RT: It’s a Nice Idea.
I was on campus at Hull last week and pretty much as I walked in the door the ICT dept. jammed a Windows Surface RT into my hands. “It’s useless,” said a man in a Where Would You Think t-shirt, “enjoy!”.
I was quite excited about getting a Surface RT however, mostly because a lot of our customers do significant amounts of business when out-and-about. Developing for Android and iPad is a bit of a pig for Seed as it’s basically a Windows software house (although we do do it). So having something based on an ARM processor but that runs Windows must be a pretty major innovation for us, right? I mean most of our apps are pure .NET so you’d think it would be child’s play to get them onto the Surface RT right?
Now I understand, from a technical point of view, why Microsoft may want to do this; Windows is still in a transition. Microsoft don’t really want anyone fiddling with that old Win32 stuff because it’s dangerous, but a lot of legacy apps still need it. Whilst Microsoft continue to provide access to the Win32 interface those applications aren’t going to stop using it. So they need to break the chain.
The reason it’s dangerous – indeed something that’s bugged Windows from the start – is that they’re trying to retrofit security. Basically Unix-like operating systems, of which iOS and Android are, start with the premise that as a user (or application) you’re not allowed to do anything. You are then granted permission to perform certain tasks. You can’t get at the soft underparts of the operating system unless you’re a superuser and in the case of iOS and stock Android devices they’re not letting you do it (although you can “root” most Android devices to get such access if you really want).
Windows however started life assuming that the user could do anything they wanted, so security simply wasn’t included at the start. This means that Windows has a heck of a lot more holes to plug than the other two platforms, and they’re not there yet. To clarify, we’re not just talking about hackers and viruses, but a lot of legitimate programmers have been using stuff in Windows – often because there’s no alternative – that can actually destabilise the system. Opening up the device to anything that would cross-compile for the ARM processor would mean they had exactly the same problems on the tablet as they do on the desktop.
Essentially we’re all still paying for a cock-up that Microsoft made in 1981.
There would be a half-way house though, as I mentioned before most of our apps are pure .NET which in theory can’t do anything nasty. The fact that RT is not open to pure .NET apps makes me scratch my head a little. I can’t help but wonder if perhaps the current .NET runtime (for desktop) isn’t quite a clean as it ought to be.
So, as a software developer I find the Surface RT frustrating, it has a desktop that I can’t use, I can’t write Windows Services (even in .NET), the only thing I can do is write store apps and even then it’s subtly different to writing a Windows Phone app.
Microsoft themselves have done a reasonably good job of getting their own apps onto Surface RT (e.g Skype, Lync) and there’s a smattering of the top apps that you’d expect to find – Facebook, Twitter, Kindle etc. but that’s about it. There is a woeful lack of applications for the platform. Not only that but even apps like Facebook and Twitter seem limited compared to their Android counterparts. They’re clunkier, it’s clearly that less attention has been paid to them.
So the big advantage of the Surface RT over an Android or iPad tablet is that it runs full Microsoft Office. That’s it. That’s the advantage and to be honest some of the alternative office packages that are available for Android are pretty good. In every other way it’s a worse platform than Android or iPad.
It even needs its own special charger rather than using Micro USB – although to be fair it uses a 12V supply whereas USB is 5V.
Annoying
What Microsoft have done is to pretty much guarantee failure of the platform.
Still, it must be useful for something, right? I mean it’s actually quite a good piece of hardware. They detachable keyboard thing works really well too.
It’s certainly better (hardware) than the cheap Chinese Android table I got a couple of years ago. So why don’t I run Linux or Android on it? Well I can’t because Microsoft have locked the bootloader. Before you scream “no fair!” almost everyone does these days, Android included. Some Android manufacturers however release unlocks for their bootloaders. HTC for instance generally do when the device is a couple of years old (via htcdev.com). I can’t see Microsoft doing this.
In conclusion, the Surface RT is not the platform for development that I’d hoped it would be; it’s not very useful for us to develop apps for. Yes it has Office which makes it a useful device to have around for meetings etc. and it’s a lot easier to get in hand luggage than a laptop. It lacks the I/O though to make it a useful presentation device and there’s no chance of running up Visual Studio even if I could put up with it running terribly slowly. For me it cannot replace a laptop for anything other than the most basic business use.
There are cheaper Android devices that are far more capable – and the lack of Microsoft Office on them isn’t really much of an issue. There are x86 based tablets that run full Windows and, whilst they might be a bit slow, are actually viable as a travel alternative to a laptop. Microsoft themselves even produce the Surface Pro series.
To cap it all off the lack of apps puts it way behind the competition as a social and media platform so I’m really struggling to find a use for it. I’ll let you know if I find something a little more involving of technology than this…
I’ve noticed a lot, particularly in Windows 8, that I get phantom windows. Perhaps the application wanted to create an invisible window but for some reason it gets displayed. This is very annoying, especially when it sits permanently on top of other windows like this little example here.
Thankfully there’s a quick and easy way to get rid of them using the rather handy Process Explorer from TechNet.
At the top of the app are several buttons, one of them looks a bit like a targeting system and is labelled "Find Window’s Process"
Simply drag that button onto the offending window and drop. Process Explorer will then highlight the process responsible, which you can deal with.
In this case it was Outlook and simply restarting the application fixed the problem.
I end up using the IP Webcam Android application for all sorts of things. It’s really easy to prop or jam an Android device pointing at something you need to keep an eye on or even push the device somewhere where you just can’t get your head. Then fire up a web browser and monitor the output stream.
Today’s issue was that I forgot to boil some eggs for lunch, so I propped my Wildfire S against a spare pan and went back to the office. There I monitored the webcam and started the timer when I saw the eggs boiling. They were ready in perfect time.
…British APCO, or simply BAPCO is the Association of Public-Safety Communications Officials. At Seed we produce not only communications systems for the emergency services but many of the applications that use them: in-vehicle systems, hand-held systems for mobilisation and data capture and our Command Control mobilising system.
So being represented at BAPCO’s large annual event is important for us. In previous years we’ve piggy-backed on some of our partners’ stands but this year we decided that our portfolio was significant and mature enough that it warranted its own stand.
The results were pretty amazing, there was a real buzz around the stand with people from all over the emergency services and public safety spectrum coming to talk to us and find out more about who we are and what we do.
It was a lot of hard work though; it’s nearly a week later as I write this and I’ve just about finished tidying up all the admin. For the other guys it’s been a much longer road. I was able to simply turn up to the stand on the first day. There were weeks’ worth of preparation effort before that – design and planning. Then the guys had to put everything in the van, drive it to Manchester and get the stand set up. We don’t have people to do any of this for us, so it was great experience for our young software developers to be part of the process right from the graphical design to screwing shelves into the wall.
They were also in the front line on the stand, talking to people and demonstrating our software. In the average business only very senior technical people get to do this, so to be able to give them that kind of experience – and just the experience of being at such an event – is a great benefit.
It wasn’t all work and no play though. We had some fun, such as the reaction training (computer) game at the official dinner – well there was only ever going to be one winner of that! We now know who plays the most shoot-em-ups too, and it wasn’t who we thought.
As a business, BAPCO 2014 gave Seed some great opportunities. Firstly we were able to connect with our existing customers and partners. As we don’t have any customer relationship managers every opportunity to spend time with the people we currently do business with, to talk about openly about their needs and where they see those needs going is really important. Getting those discussions out from drab meeting rooms and into an environment of seemingly limitless possibility is also important because at Seed we’re always looking forward, trying to work out ways that we can use technology to benefit our customers and our society.
We were also able to get the message of who Seed are, what we do and why we’re different to a much wider audience. Sure just about everyone in the Fire Service has heard of Seed but not many knew that nearly a third of England’s Fire Services have a Seed system. Not many realised that we started back in 2005 and that since then we’ve grown a lot; we’re not just in-vehicle terminal (MDT) providers any more, we have a full portfolio ranging from data capture to our own Command and Control mobilising system.
Seed is not limited to the Fire Service either – some of our products are as applicable to other emergency services as they are to Fire and further even that that. Our mobile forms product for instance is applicable anywhere where field workers have to fill in forms that need to be centrally collated.
Being able to stand in a room where most of the UK’s public safety organisations are represented and give those messages loudly and clearly is a hugely positive thing for us. We’re all very glad we did it. I enjoyed it too, sure it was tiring but it was very definitely worth the effort.
It’s no secret that I am not an ORM fan. Actually that’s a little harsh, ORMs bring some significant advantages and it’s not just having an object orientated view of a database – a lot of junior developers just don’t know SQL and they can save a massive amount of development time. They also discourage people from infecting the code-base with SQL which can prove a real maintenance headache. So in many ways ORMs are a good thing.
Unfortunately using an ORM can result in serious database abuse. Not so long ago I profiled some of the LINQ-to-SQL that one of our products uses and I nearly had kittens (some of that’s mentioned in this article). It was making thousands of unnecessary round trips to SQL Server to pick up individual records when one query could have got everything we needed.
A project that my team have just inherited demonstrates a different kind of database abuse rather neatly. There’s a web service that basically just provides a view of the DB. One of the methods does this…
Which is fine, apart from the fact that it transpires that it’s perfectly legitimate to have duplicate keys in the database (it’s not our DB). The Web Service is consumed by our remote client and we’d rather not be sending that any duplicates – so I modified the LINQ to eliminate them. The situation is slightly more complex than just using .Distinct() because in the case of duplicates what we actually want is the later record, according to the Added datetime field.
The .GroupBy groups the records by the key, then the following select only returns one record, the one with the highest “Added”. The result of this is an IEnumberable<Street> so the .OrderBy etc. will work just fine. It doesn’t work though, it throws a SQLException because the SQL that the Entity Framework generates contains the “Added” column in the order by clause twice. So I thought I’d profile the SQL Server an see exactly what it was trying to do…
SELECT TOP (500) [t4].[test], [t4].[GUID], [t4].[ParishGUID], [t4].[Name], [t4].[Active], [t4].[Added], [t4].[Created]
FROM (
SELECT [t1].[value]
FROM (
SELECT UPPER([t0].[GUID]) AS [value]
FROM [dbo].[Street] AS [t0]
) AS [t1]
GROUP BY [t1].[value]
) AS [t2]
OUTER APPLY (
SELECT TOP (1) 1 AS [test], [t3].[GUID], [t3].[ParishGUID], [t3].[Name], [t3].[Active], [t3].[Added], [t3].[Created]
FROM [dbo].[Street] AS [t3]
WHERE (([t2].[value] IS NULL) AND (UPPER([t3].[GUID]) IS NULL)) OR (([t2].[value] IS NOT NULL) AND (UPPER([t3].[GUID]) IS NOT NULL) AND ([t2].[value] = UPPER([t3].[GUID])))
ORDER BY [t3].[Added] DESC
) AS [t4]
ORDER BY [t4].[Added], UPPER([t4].[GUID]) DESC, [t4].[Added] DESC
Holy Truffle Oil Batman! That’s bonkers! What makes matters worse is that even if I correct the SQL the query times out and there are only 30,000 records in the DB. Because it’s bonkers.
So I started to think about how I’d actually do it in SQL. This is my first attempt, now I’m not saying it’s optimal. I think there may be ways I could improve it but it works and with 30,000 records it returns pretty much instantly.
SELECT [GUID]
,[ParishGUID]
,[Name]
,[Active]
,[Added]
,[Created]
FROM
(SELECT *, ROW_NUMBER() OVER(ORDER BY [GUID]) RN FROM
(SELECT *
,RANK() OVER (PARTITION BY [GUID] ORDER BY Added,NEWID()) RK
FROM dbo.Street
WHERE @takeAll = 1 OR Added >= @added) DEDUPE
WHERE RK=1) CHUNK
WHERE RN > @start and RN <= @start+@take
The Entity Framework is kind enough to provide a generic ExecuteQuery<T> method on the DataContext so I’ll be writing a new method in the DAL effectively to override Entity Framework’s toxic SQL generation in this case. I suspect my new method won’t be lonely for long.
Reading Time: 2minutesOne thing about C# style that I get asked quite a lot is why I tend to write if statements like this…
if (null != args)
{
It’s not how most people think. It seems far more logical written this way round…
if (args != null)
{
It’s actually a hang-on from my days as a plain old C developer, most of the time it’s not relevant to C# but there’s one particular instance where it is.
bool someBoolean = false;
bool someOtherBoolean = true;
if(someBoolean = someOtherBoolean)
{
Console.WriteLine("The if condition evaluated to true!");
}
Console.WriteLine(String.Format("someBoolean is [{0}], someOtherBoolean is [{1}]", someBoolean, someOtherBoolean));
So when we run this, we might not get the result we expect.
This is because in C# assignment operations have a result. Instead of comparing the two items in the if statement (==) we assigned the value in someOtherBoolean to someBoolean (=). Basically we just used = where we should have used ==, it’s an easy mistake to make and in this instance it compiles and runs, it just doesn’t do what we want, at all…
I actually wrote about this in an article some time ago, but back then I was talking about doing it deliberately, and as part of a work of extreme evil.
OK, so that’s a convoluted example and in reality you’re unlikely to cause yourself serious problems in C# because C# is very strict about the result of whatever’s in an if statement being Boolean. So if you did accidentally write this, it wouldn’t compile.
if(someObject = null)
{
someObject = new someType();
}
This is because the result of assigning null to someObject is null, which is not a Boolean.
However in C the equivalent will compile and will run. In C anything that evaluates to zero is treated as false and anything that evaluates to non-zero is treated as true.
This will crash every time, because we’re actually assigning NULL to the value someStruct. The result of that assignment is zero, which evaluates to false, so execution skips the contents of the if statement and goes directly to where the structure is accessed – the structure that we’ve just assigned to NULL.
This is my mobile phone, or cellphone if you will. It’s a HTC Wildfire S running cyanogenmod 9. Sure it was never an expensive phone but I didn’t get it because it was cheap, I got it because it was small.
I am notoriously hard on kit. Something like a mobile phone just gets shoved in my pocket and ends up doing whatever I do. Scaling roofs to find mobile phone signal is perfectly normal in my world, as is climbing into the loft, crawling into tight gaps and running out in a howling gale to rope the remains of the fence to something a little more stable.
Amongst my friends, many of whom have the same attitude to life as me, there is a catalog of broken phone screens. My little Wildfire S has lasted a few years now without any serious damage.
It is however getting a little long in the tooth. It never had even remotely enough memory to start with and fiddling it to make it think that a portion of the SD Card is actually internal memory isn’t the most reliable. It’s also suffering a bit with a lot of modern apps which are a getting a bit slow.
So I’m in the market for a replacement – I figured this should be easy as there are a lot of new “mini” phones on the market. Only they’re not, the new “mini” phones are only mini compared to their tablet-size counterparts.
The look of horrible confusion on the face of a mobile phone stores salesperson is one I’ve got well used to, “sorry, I’ll just repeat that. I’m looking for a small, tough smartphone. Not a 6 inch mini-tablet that will break as soon as I attempt to climb a ladder with it in my pocket.”
I’m never far from a PC, a laptop or a tablet. I don’t need a mobile mini-tablet, what I need is a smart-phone, something that fits in my pocket and allows me to check social media and run a few tracking and navigation apps and maybe listen to Buddy Guy.