Best Practices

August 23, 2008 at 3:24 pm | Posted in Uncategorized | Leave a comment

My friend Bevan points out a post on NUnit Best Practices by Scott White, and asks whether we agree with them.

Most of my coding these days is in java, so some of Scott’s best practices need altering to my situation, e.g. junit.jar instead of nunit.framework.dll.

For reference, I disagree to varying extents with #1, #2, #3, and #5, and agree with #4, #6, and #7.

However I believe that best practices are often relative to the situation you find yourself in. That situation includes which IDE you are using, and how best to use it, how large your team is, how complex your application is, etc.

I also think that it is an excellent idea to consider which practices consciously or unconsciously drive your coding practice, and whether any of them could be improved. Scott himself says that best practices change over time, and his blog seems to have a long running theme of identifying some of these changes. I commend him for identifying and documenting what he does, providing advice for others to consider, and asking for feedback.

Here are my reasons for disagreeing with some of his NUnit best practices, from my junit in eclipse standpoint:

#1

I primarily disagree since all too often the tests are not distributed with the code being tested. When dealing with some-one else’s code, I don’t have their test cases, so if I have problems with their code, I can’t simply find out whether their test cases still work in my environment, nor whether I’m using parts of their code which are not covered by their tests.

Secondly, I disagree with “don’t be lazy”. We should all be striving to have our best practices also be the easiest things to do.

#2 & #3

These are things that should be integrated into your IDE and dependency management tools. They appear to be workarounds for poor visual studio defaults when you wish to use NUnit to test your code.

#5

I prefer the idea of starting by writing test cases in a style that documents what you want to achieve. That then drives what methods you need, and perhaps how they should be collected into various interfaces. I refer to this as an idea since I’m not particularly disciplined in developing in this way.

Overall though, I’d say that I agree with Scott in that solid unit testing using a tool like NUnit is best practice.

Advertisements

Mathematics of Boxy Numbers

June 22, 2008 at 3:48 pm | Posted in Uncategorized | Leave a comment

I’ve found some interesting mathematical concepts through researching my ideas presented in my previous blog posts on a scheme for representing numbers using Basic Primes, and drawing that representation as Boxy Numbers.

There is a function named pi, (written as the greek symbol), but pi isn’t used in reference to circles’ diameters and circumferences, but is instead (as far as I can tell) P. I. standing for prime index. pi(x) is equal to the number of primes equal to or less than x.

By altering my representation slightly so that the number one is represented as a single box:

    

So that two is the first prime, so two is a box with the representation of one inside it (which is how I previously drew three).

Then the representation of any number n is drawn by producing n‘s prime factors, f0 to fk and each factor fi is drawn as a box with the representation of pi(fi) inside it.

To make the representation slightly more aesthetic, you can fill in all the gaps with the representation of one. This is because everything is multiplied, and you can of course multiply by one as many times as you like without altering the product. Multiplication is also commutative, so the boxes may be rearranged to give a pleasant looking number, so long as the number of boxes within any box stays the same.

Multiplication is simply a case of drawing both sets of boxes for the numbers being multiplied.

Division and rational numbers are probably best drawn with a numerator over a divisor separated by a line. Common factors are easily identified and removed.

By contrast, addition and subtraction are intensely difficult.

Here’s a walk-through of representing your birthday as a bunch of boxes:

You could draw the number for the day, month and year individually, but you’ll probably end up with more a more interesting drawing if you start with one large number n = YYYYMMDD. So for my birthday, 8th September 1972, n=19720908

The first step is to produce the prime factors. There are lots of ways of doing this. The easiest way if you are reading this online is to use an online tool. The one from Maths Is Fun says my prime factors are 6763 x 3 x 3 x 3 x 3 x 3 x 3 x 2 x 2.

So I need nine boxes, containing the representation of pi of each factor.

Though boxes can be arranged in any way you like, in order to demonstrate the technique I’ll stay consistent, showing these vertically, as otherwise by the end of the post I’ll be running out of room. Web pages have a fixed width, but can be infinitely long:

pi(6763)
pi(3)
pi(3)
pi(3)
pi(3)
pi(3)
pi(3)
pi(2)
pi(2)

There’s an online calculator of pi(n) too here.

It reports that there are:

871 primes less than or equal to 6763

2 primes less than or equal to 3

1 prime less than or equal to 2

So our boxes need to be:

871
2
2
2
2
2
2
1
1

We repeat the process for each of these numbers, drawing a box for each prime factor, and writing pi(factor) in each box.

The prime factors of 871 are 67 x 13, so we need two boxes.

2 is prime, so each of the 2s need a single box.

1 has been defined as a box with nothing in it.

pi(67)
pi(13)

pi(2)

pi(2)

pi(2)

pi(2)

pi(2)

pi(2)

    

    

pi(67) = 19

pi(13) = 6

pi(2) we’ve previously seen = 1

So our boxes need to be:

19
6

1

1

1

1

1

1

    

    

Producing prime factors again, 19 is prime, so a single box is needed. 6s prime factors are 3 x 2, so two boxes needed

We’ll replace 1s as before.

So we’ve got:

pi(19)

pi(3)
pi(2)

    

    

    

    

    

    

    

    

Evaluating the pi functions gives:

8

2
1

    

    

    

    

    

    

    

    

Factorising gives:

pi(2)
pi(2)
pi(2)

pi(2)

    

    

    

    

    

    

    

    

    

Evaluating the pi functions gives:

1
1
1

1

    

    

    

    

    

    

    

    

    

Replacing the last 1s with their representation of an empty box gives the final representation:

    

    

    

    

    

    

    

    

    

    

    

    

    

Rearranging this into a pleasing arrangement gives

    

    

    

    

    
    

    

    

    

    

    

    
    

    

    
    

 

Updating Internet Explorer RSS Feeds

May 18, 2008 at 11:12 pm | Posted in Uncategorized | Leave a comment

I tried out RikReader recently, which is one of the class of feed readers which use Internet Explorer’s (and Vista’s) list of RSS feeds. It has its pro’s and con’s, but the lack of the ability to refresh all feeds was initially a surprise.

It doesn’t need that feature though, since using IE’s feeds, it also uses IE’s feed updating mechanism. I don’t really like IE’s feed updating mechanism, since it is a background task that keeps using my laptop’s resources when it wants to, rather than when I want it to.

Investigating how it updates, I discovered that I can disable the background task, and when I want the feeds updated, I can run:

msfeedssync forcesync

I thought I’d blog about it, since there are currently so few mentions (in English) of this.

I created a shortcut to run that on my Quick Launch bar. Can anyone comment on where to find a pre-installed rss icon?

Boxy Numbers

April 16, 2008 at 11:30 pm | Posted in Uncategorized | Leave a comment

My previous post “Basic Primes in Scala” ended with some ideas of how to salvage some use out of the algorithm. I mentioned representing the numbers as concentric circles. Playing around with a text editor, I converted some of the numbers to arrangements of concentric squares.

Continue Reading Boxy Numbers…

What is a good title for a first blog post?

September 20, 2007 at 11:10 pm | Posted in Uncategorized | Leave a comment

This is my first post. It was created automatically by WordPress, but I’ve edited it.

When starting to edit it, I was trying to decide whether to change the title. WordPress had given it the title “Hello world!”, which I had used as the title for the first entry in my son’s blog, announcing his birth. I think that blog post deserved such a title, but this one doesn’t. Such a title doesn’t convey any details about the contents of what I’m writing here. No one is going to have their curiosity piqued by a WordPress blog post titled “Hello world!”. So I changed it.

Blog at WordPress.com.
Entries and comments feeds.