Rounding Up The Result of Integer Division

Here’s a damn useful piece of information which should be in the armoury of every modern codemonkey: In Java, if it is required to round up the result of dividing m by n (where m and n are integers), one should compute (m+n-1)/n Source: Number Conversion, Roland Backhouse, 2001 I’ve used this deliciously elegant result in production J2EE code in the past, but it’s equally valid in C#, as long as you can make the additional assertion that m/n is positive. This is because whilst Java treats integer division by rounding to zero, C# merely truncates the result (in an unchecked context). In my experience, the most frequentuse for this result is the deft answering of questions such as “if I have x items in my dataset and I display y per page, how many pages do I have in total?”, where it is obviously safe to make the assertion of a positive result.

6 September 2005

10 Things That Should Be More Popular

Some days I feel like I’m spitting in the wind. It amazes me that the following ten concepts, websites and applications aren’t more widely used: RSS Feeds – why waste your time repeatedly trawling dozens of sites looking for new content? Let it come to you! Flickr – practically everyone I know has a digital camera, but still relatively few have a Flickr account. Share your photos, don’t keep them unseen on your hard drive! GMail – by far the most effective web-based email. FireFox – if only for the tabbed browsing. But really, it’s so much nicer than IE6, and a myriad of different extensions are available. OneNote – so much better than scraps of paper. Desktop Search – I don’t care which desktop search program you use, but please install one! You’ll find it so much easier to find old emails and other files. del.icio.us – access your bookmarks anywhere, and share them with friends. ClearType – if you have a flatscreen monitor, you should turn ClearType on. Period. Virtual PC – there’s no need to test beta software on your main machine, or keep several differently-configured computers around the house any more! SyncToy – this is a great little app for synchronizing and backing-up folders; it’s really useful for combining media folders, and for synching files with a portable hard drive.

31 August 2005

Computer Games I Have Loved

Isn’t it funny how one’s tastes change as maturity progresses? I used to spend my summer holidays at the sea-side, playing in arcades and seeking the perfect milkshake (lime); more recently I’ve been spending them in the highlands, playing on the hills and seeking the perfect dram (lagavulin).Hmmm… I think I may have mentioned that the wife is away in the States for a while.At the start of this period of solitude, I panicked, wondering whatever I could do with myself, and came to the conclusion that it would be a good idea to buy a computer game to while away the hours.After all, I spent much of my formative years killing time on a variety of computer and console games, so why not rekindle that prior love affair? So it was that I bought The Sims 2, a truly excellent game, and had an enjoyable evening trying to motivate my wee Sims to improve their skills, better themselves, and generally enjoy life.All good harmless fun. ...

22 August 2005

Project Euler

If you like maths problems, and you like programming (and hey, who doesn’t?), then you’ll love Project Euler.

22 August 2005

Aussie Apostle Claimed By Sea

Holy cow, one of the limestone towers at Australia’s Twelve Apostles park has collapsed into the sea! It was the one in the foreground of the photo to the left. Seeing this fantastic set of rock formations (and flying over them in a helicopter) was one of the many highlights of my vacation to Australia in Dec 2002 / Jan 2003. You always hear about coastal erosion and the way landscape changes over time, but never really expect significant changes to occur during your own lifetime ...

5 July 2005

Stopwatch Class for .NET 1.1

Paul Welter has backported the System.Diagnostics.Stopwatch class from .NET 2.0 to 1.1. Handy. http://weblogs.asp.net/pwelter34/archive/2005/07/01/416999.aspx

5 July 2005

New Recommendations for String Comparisons in .NET 2.0

I know it’s a rather geeky and dry subject, but I found this MSDN article on new recommendations for using strings in .NET 2.0 quite interesting. It’s going to be difficult to stop using CultureInfo.InvariantCulture habitually!

4 July 2005

eXtreme .NET

Up at 0500 yesterday and onto the early GNER Mallard down to that London town for the MSDN briefing on eXtreme programming with .NET. It was pleasant not to be driving for a change, and speeding through the Yorkshire countryside early on a midsummer morning was very relaxing – what a stark contrast with the hot crowded tube that I had to catch on arrival to the big smoke. Three stops down to Oxford Circus seemed to last as long as the entire preceeding train journey. How people do this every single day I do not know.. ...

18 June 2005

Tech Books

I succumbed to temptation and bought another book at the MSDN briefing yesterday, pausing only out of concern that the guy who mans the Computer Manuals stand at these events might think that I’m stalking him (or fancy him!). Having determined that I could hand over my Barclaycard whilst flashing my wedding ring, I brought my current reading list up to three: Developer to Designer: GUI Design for the Busy Developer – this was a wedding present from my mother-in-law and is proving to be an interesting, easy-going read so far. My competencies lie in the middle tier and database, and although I’m technically capable of making GUIs, I prefer to leave the design up to others. It’s inevitable though that most coders end up doing some design, and this book is, er, designed (sorry) to help with that process. The early section of the book concentrates on each UI element in turn, whilst the later part of the book looks at putting it all together, and has particular focus on the web – layout design patterns and interaction patterns. It’s a good read, making a nice contrast from the heavier books, and I’m pleased to learn that I’m not alone in hating Outlook’s labyrinthine Tools->Options dialog! ...

18 June 2005

Software Development Books

Elizabeth Keogh has been blogging her advice for software-developer apprentices, and recommends buying and reading a selection of good software development books. I think this is sound advice – personally I felt that my career and abilities starting taking off when I stopped reading tech-specific Wrox tomes that were obsolete within six months of publication and started buying timeless Addison-Wesley hardbacks. Why so many newbie coders insist on rediscovering solutions to well-known problems instead of leveraging the knowledge of our programming forebears is beyond me, but most of us have behaved in this way at some point. Give yourself a leg-up and read some decent software design books. ...

13 June 2005

Framework for Persisting .NET Classes Into SQL Server Image Fields, With Locking Ability

There seems to have been a lack of .NET-related stuff on this blog recently, so let me show you something I cobbled together for work purposes last Wednesday: A common requirement we have in our ASP.NET applications is how to reliably persist object instances for a lengthy period of time. End users shouldn’t have to concern themselves with the concept of Session expiry, and it’s unacceptable for them to return to their PC after nipping off for a coffee to be confronted with the dreaded “Object reference not set to an instance of an object” when they try to continue editing their basket / sales order / timesheet / whatever. ...

18 January 2005

999999999..

Never underestimate the stupidity of users—or the benefits of a little field validation. One of the web-based systems I’ve been developing allows users to enter a customer’s fax number and automatically fax confirmation details (using Zetafax). It’s been working pretty well—until we discovered a flaw today. One user, tired of obtaining valid fax details from customers, had been entering a string of nines and then actually attempting to send the fax to this number. ...

11 January 2005

SQL Server Best Practices Analyser Tool

Via Eric G. Harrison – MS have developed a SQL Server Best Practices Analyser Tool. It’s like a cross between FxCop and Baseline Security Analyser, for SQL Server. Very useful. I just downloaded it, ran it against some of my databases, and it made some useful suggestions. This could quickly become indispensable.

12 December 2004

Property Access Modifiers in Whidbey

Ooh, this is great news: http://nxopinion.robertsoninstitute.org/blogs/rcecil/archive/2004/11/11/167.aspx It’s a little thing, to be sure, but I often find myself wanting to make a setter internal or private while leaving the getter public. So, I’m happy. It doesn’t take much 🙂

15 November 2004

I’m an MCAD!

Woohoo! I just passed MS exam 70-320 with a score of 936, and am now a Microsoft Certified Application Developer!

13 November 2004