Friday, 22 June 2007

Refactoring your Editing with Resharper 3.0

Jetbrains have release a new version of Resharper.

 

This is simply a fantastic tool!  Though, if you are new to resharper it can be hard to see why its so good.   It's not until you see a Resharper Jedi  at work do you really understand why people rave about it.

 

The real trick to it is learning / customizing the keyboard bindings and then letting them become second nature.

The second major trick is to go through all of the resharper goodies and all  the options and customize the settings.  Make your own live templates, your own file templates, bind it all to keys.  

Now you can refactor your editing.  Any time you duplicate any kind of action / typing, then chances are you can automate it with resharper.  Never type a for loop again, learn the magic of Alt-Ins

 

It also helps with XML and XAML.   Nice for WPF type development, though there's a heck of a lot more Resharper could do for XAML.

Thursday, 21 June 2007

WPF Goodness

I've been actively playing with WPF and we are currently converting a "machine simulation"  ( www.compacsort.com )  over to WPF.  I really like it!  It's not perfect, but its definitely a big step up from winforms.

I was browsing through...

http://www.orbifold.net/default/?p=713     (need a free ribbon like toolbar?) and he mentioned only around a 1000 people had downloaded kevins bag of tricks and that he was seriously worried about the future of WPF. 

 

Well, I was one of those people to download it a while ago and was impressed with what you could do!  so if you haven't already (only 1500 odd people at the time of this post), download from http://wpf.netfx3.com/files/folders/10297/download.aspx

 

If anyone else has links to good wpf resources, can you point me in the right direction? :-)

Thursday, 14 June 2007

Resuming MSDN subscription downloads

If you quit the Microsoft File Transfer Manager in the middle of it downloading all your goodies from MSDN. Before you do so.... Go to the Options in the transfer manager and select "place application shortcut on the desktop".

Or, if you forget to do that, look in your \WINDOWS\Downloaded Program Files\TransferMgr.exe

Which won't show up in a search or in explorer by default, so simply run it from the command line or your run box.

Wednesday, 13 June 2007

Mixing WPF into WinForms

Just came across this today.  I was just seeing how easy it is to mix winforms and wpf (completely simple).  The only issues was it came up and said it didn't know what InitializeComponent() was.     This is because it wasn't compiling the XAML.   So...you need  :-

<Import Project="$(MSBuildBinPath)\Microsoft.WinFX.targets" />

in the project file (near the other similar looking import)

Wednesday, 6 June 2007

Explainable Design

I was reading a blog post called "Four Factors of Agile UX" and one of the "factors" is

"The ability to explain a design efficiently is vital to the success of a project".

I think this is a fantastically good design principle. Anything you design should be explainable in a reasonably straightforward way.

One of the tell tale signs of smelly design is when you do try and explain it and you start doing.... "And then the Widget puts the......oh...hmmm....hang on, that's a bit strange, hmmm, wonder what that's doing?....hmmm....". Suddenly things are not quite as you thought they were. Complexity is pretty sneaky and often sneaks into designs when your not paying attention.

It is important that its explainable in words you say out loud and not inside your head. So you can't cheat and look at a design and say to yourself "yep! makes sense to me! I could explain it!". Of course the best way to do this is to discuss your designs with someone else.

Tuesday, 29 May 2007

Gavin is blogging

One of my coworkers, Gavin Lambert, has started blogging at http://lambert.geek.nz/

One of the great things about Gavin is he likes to get inside the guts of things and consequently digs up some real nuggets of information.

Monday, 14 May 2007

AlligatorEggs


from the maker of Magic Ink.... http://worrydream.com/MagicInk/

http://worrydream.com/AlligatorEggs/

This is a cool little game with cutout alligators and eggs that demonstrates lambda calculus!

Tuesday, 1 May 2007

I Like Microsoft today :-)

I've been watching a bunch of blogs about the Mix event by Microsoft ( couple of local blogs http://www.syringe.net.nz/ and http://turtle.net.nz/blog/ ).

There's tons of stuff being announced that just cool.

Extensions to the CLR for Dynamic languages, IronRuby, Silverlight, Expression....and more!

This stuff is all great, and pretty much what I've been expecting from MS, though I didnt know the Dynamic Language stuff was so close! The other cool thing in Microsoft is F# but there are no major announcment around this, but I think its an important development.

Anyways, all up, it means anyone developing on a .NET platform is going to have some really awesome tools!!

Well done Microsoft.

Thursday, 26 April 2007

XAML

I'm in the process of playing around with WPF. XAML is the markup language for creating WPF based UI. But, its actually more generally useful than that.

It can be used for any objects. Which makes its reasonably good for any kind of object creation / dependency injection / configuration.

I haven't had a chance to play with this much yet, I'm still on the steep part of the learning curve for WPF and the underlying architecture. I'm looking at how MVP/MVC and TDD fit in with it all.

Wednesday, 18 April 2007

As little Unit Testing as possible

When you first start learning TDD. It's all about creating unit tests. However, very quickly you learn its actually all about making as few unit tests as possible.

One of the traps people can fall into when doing TDD is testing lots and lots and lots of stuff. This means when you change your design you break lots of tests.

Ideally what you want is tests that test your intention. Tests that show what the code has to achieve. It doesn't matter too much how the code achieves it, and you don't really want to test how it achieves it. That way you can vary how it is implemented without breaking lots of tests. ie, Encapsulation.

Of course there are going to be plenty of things that may break tests as they slice through a layer of encapsulation.

However, if you test things pretending that the thing will magically do what you want without worrying about how, then it can be a heck of a lot easier to get good tests. When you test with a particular implementation in mind, you often get very concrete tests that fall over as soon as you try changing things.

Monday, 16 April 2007

Architecture Camp Finished! + My Powerpoint presentation

Architecture Camp was really good! It was great to see people really interested in the content presented and activelly discussing ideas.

Some interesting things to me...

Quite a lot of people were using mindmaps to take notes, great stuff!

There was quite an agile theme to many of the talks.

Martin Fowler is quoted a lot!

Integration / Deployment Architectures are hot topics.

No one had any idea where one would go to buy yellow camo

---

Heres my Slides from my talk. Most happy to answer any questions or discuss any ideas related to them!

Wednesday, 11 April 2007

Pearls Before Breakfast

There's a great article in the Washington post called Pearls Before Breakfast. It's about how a top classical violinist in America (just voted Americas top classical musician) went to the Washington DC Metro and started busking.

Most people walked on by.

What does that mean? The article explores some of the possibilities. But, there's a couple of things I take from it, quite often things of beauty (music, art, design) need to be presented within a context for you to appreciate it. Relating this to software design, this means unless we stop and look at good design and appreciate it for what it is, we are most likely to pass it by never realising it was good design.

The next point to take away is also really interesting. It's also really odd, because I was talking about exactly this with a co-worker yesterday! That is Immanuel Kant (philosopher) said that beauty cannot be truly experienced unless we have a sense or morality. or, Without a sense of whats right and whats wrong, we can't appreciate beauty. Appreciating beauty is not the same as liking something either. I think theres an element of objectiveness to beauty and whether we like something or not tends to be quite subjective. Having said that, Kant didn't quite say this at all, he painted a fuzzier picture of how beauty and morality tend to interact. Kant's most famous moral idea is "The Categorical Imperative". This a set of 3 basic "rules", however, most of interesting discussion is based around the consequences of those rules and what they mean.... Anyways! How does this relate to software development? It means we really need to spend some time understanding what good code is and what bad code is. The tricky thing is that what's good and bad is not carved into a rock anywhere. However once we start developing a sense for what good and bad is we then tend to recognise beautiful designs and why they are beautiful. With a bit of luck we can hone our sense of "Code Morality" so finely that we won't walk by a Masterpiece out of context.

Monday, 26 March 2007

Architecture Camp registrations now open!

If you haven't heard already, you can register for Architecture Camp. I'll be talking about Evolving Architectures. I'll be waffling about thinking tools, refactoring, patterns and ways to try and create good designs!

Also, I realise I suck at blog posts! my last post didnt mention that I got the link to TED from Allen Holub, and secondly, I didn't even put the link in the post!

so here it is....

http://www.ted.com/tedtalks/

Tuesday, 20 March 2007

TED - Technology Entertainment Design

Continuing my pasting interesting links rather than formulating my thoughts into blog posts.....

But, this time I will make a bit more effort to ADD value by hyping the link and explaining why its worth having a look at!

So, I received a newsletter email from Allen Holub. Allen has some great ideas on software design and at the very least all software developers should read his article on why setters and getters are evil. (also continuing from the last post concerning the social psychology that software developers tend to bump into, he has a good link to "Unskilled and unaware of it". Which also feeds into a great link I got from 37signals which is Judo quotes which are applicable to any pursuit really).

Anyways.... So TED... This is a conference in California where they get a bunch of people who have interesting ideas in the areas of technology entertainment and design. I downloaded several them earlier today and watched them. They are good! The one I found especially interesting is the one from Neil Gershenfeld. He talks about whats beyond the digital revolution. His talk focuses on computability entering the physical world. Things that can make themselves. Programming Biology. Creating and building real things customised to the individual. He talks about Fab Labs all around the world where kids / adults are creating devices and technology that solve local problems. He makes references how 3 MIT students are doing research papers on designs 8 year olds have come up with from these labs. Really quite interesting stuff! It also is quite related to a post Rod recently made.

What I'd like to know is what we are doing in New Zealand with these ideas... with our so called #8 wire innovation we should be eating these ideas alive!

The other thing I like about these talks is that the idealistic "feel" about uniting humanity through technology and understanding comes through quite well. Some talks deal with the problems of technology and the modern world and some paint a picture of a future based on these emerging ideas.

Monday, 19 March 2007

A Group Is Its Own Worst Enemy

I came across this http://shirky.com/writings/group_enemy.html on the lua mailing list. Makes for a good read!

Nothing to do with designing code though....

Wednesday, 7 March 2007

Design Culture

I've been pondering over the last few months the notion of a "Design Culture" as the underpinning to software development (and more generally, product development).

This idea embraces design in a philosophical, social, and practical sense. The process you use, the techniques you use, the team, the values, etc all feed into a "Design Culture"

This means your software, your selling, your marketing, your customer service, your environment, etc all are done within a "Design Culture".

The reason I want to try and capture this idea is so that I can explain what the motivation is to do something a particular way. For instance, refactoring. It is one of the key ideas of TDD. But often it is not done "extremely" enough. Simple duplication gets removed, but really striving to separate concepts and name concepts with good names is neglected. The motivation to make a simpler design can be missing, especially once you have code that works. But this is only one tiny tiny example of a what I would imagine one *kind* of "Design Culture" would entail.

I'm not quite sure how to define it, I think I'm trying to find something beyond "You should strive for simplicity" etc. I think I want to know what makes people happy about the things they have created. Which sounds a bit wishy washy but I think it gets at the heart of what really motivates people to create good designs.

Which if we look at the idea of simplicity and my experience of creating simple designs, I really enjoy the intellectual challenge of taking something complex and finding the simple building blocks that create that complexity.

Then applying that back into the "Design Culture" we would have some notion of intellectual challenge. Which in turn has implications about techniques and skills for comprehending problems, expressing solutions, trying ideas, etc etc.

Tuesday, 27 February 2007

Katana

Random non software related post!

For years and years I've had a practice katana (not a sharp blade) since it's generally far better for keeping your body parts attached to the proper places.

However, I just bought a hand forged katana from http://www.gengswords.co.nz/



I'm also looking at getting a second one from the same place (you can never have too many swords!)

Saturday, 24 February 2007

Interactionary

This looks fun :) We need 1 or 2 people to make a team, contact me if you're interested :)

---------------------------------
The first UPA Auckland event this year is going to be an Interactionary on March 6th.

Interactionary session

Imagine a cross between Theatre Sports and NZ Idol meets User Centred Design.

Want to play?

Form a team of 3-4 people before the night and RSVP your team name, team captain’s contact details and team members’ names to auckland@upa.org.nz before February 28th.
Take the challenge of solving a design problem revealed on the night and design a solution in front of your peers in just ten minutes and scored by 3 guest judges.

You will be scored on the following criteria (although scoring isn’t the primary goal, having fun is):

* Teamwork: * Process: * Final Design: * User focus:

You wont know the design problem until the night. Depending on the number of teams, heats will determine 2 highest scroring finalist teams who then play off in the final design problem.

If you would like to be part of the interactionary but don’t have a team, email us and we’ll match you up.

* RSVP: Please RSVP to auckland@upa.org.nz by 5pm Monday 5th March (for observers, by 28th of Feb for teams)
* Time: 6pm onwards for drinks and nibbles.
* Talks start at 6.30pm. Finishes at approximately 8pm
* Cost: $10 cash at the door. Please bring correct change.
* Location: Bank of New Zealand, 3rd floor, 125 Queen Street, Auckland
* Late entry: Call Mark McLay on 029 222 00 16 if you have difficulty getting in or arrive after 6.30pm

Usability Professionals Association of New Zealand, Auckland cluster Auckland’s UPA meetings are usually held on the last Tuesday of each month.

Monday, 19 February 2007

Lean Software Development

Recently we had Mary Poppendieck give a talk at Agile Auckland

Mary is a great presenter and she really knows her stuff! I orginally met her at OOPSLA in 2004 where she was giving talks and promoting her book Lean Software Development.

Anyone interseted in Agile ideas should have a look at her stuff. Especially if you don't buy into "All" of agile and are more interested in customising "agile ideas" to your own enviroment.

Anyways, the slides for her presentation she gave can be found at http://www.agileauckland.com/Beyond_Agile_Auckland_2007.pdf

Refuctoring

In my continued effort not to have to think too much about my blog posts, the following link was posted to the XP list by Michael Feathers.

http://waterfall2006.com/Refuctoring.pdf

Saturday, 17 February 2007

Conditionals

gotta love this paper from 1960. 47 years ago, a new language concept of conditionals for a new language called "lisp"However, it still shows an elegant way of solving certain kinds of problems that a lot of languages still don't have

Friday, 16 February 2007

Million Times faster Regular Expression matching

This is an interesting article on the state of Regular Expression matching in a lot of "contemporary" languages.

Thursday, 8 February 2007

Multithreading and Lua

There's a cool quote in the paper The Evoloution of Lua (Section 5.4) that says...

"Second, and more important, we did
not (and still do not) believe in the standard multithreading model,
which is preemptive concurrency with shared memory: we still
think that no one can write correct programs in a language where
‘a=a+1’ is not deterministic."


It certainly makes it blimmin difficult to write correct software.

For those who don't know Lua, its a great scripting language that's a good balance between scheme/lisp/ruby etc. Its easy to embed into an application (in fact a number of games use it), its fast, it's simple, nice syntax, and powerful. www.lua.org . One of the interesting thing about Lua is that it doesn't have native support for OO (in the way C++ / Java / C# / Ruby) do. But because of its meta programming approach you can add OO constructs. You can define what a "class" is and how "inheritance" works. Which is more lisp like. This approach is quite good, as it means it's a "multi paradigm" type language, where you can program "functional" or "OO" or mix it all up, create DSLs, or whatever. The disadvantage is that you can end up with a bunch of different approaches that don't mix well.

Monday, 8 January 2007

I'm it

I've been tagged by Alex to tell everyone 5 things about myself that people probablly don't know. It's been interesting reading all sorts of peoples blogs on this. So I guess I'll join in :-)

1. I did martial arts for 16 years, Karate and Bujinkan (Ninjutsu)
2. I love studying philosophy, psychology, and religion. I'm interested in peoples belief systems, my beliefs, and why we have the beliefs we do. I am intrigued in how powerful ideas can be in changing peoples experience of life.
3. I lived in Italy during my teens as my father was doing research in Turin. I remember we were living in a place with 14th and 17th century furniture and "ladies of the night" patrolled directly below my bedroom window (we were on the second floor)
4. I suffer from insomnia to the mystery of myself and doctors.
5. I've never been to a concert ( rock, pop, classical or otherwise), this surprises many people, I have no idea why I've never been to one, it's not because I dont like music, oddly enough it's never occured to me to go, and there's been lots of times where I almost ended up going to one with friends but for some reason it never happened.

As for tagging other people, I'm going to make a dead end :-)

Design Rules

There are no design rules.

We create software by creating levels of indirection. Design is about having effective ways of manipulating these levels of indirection.

There's no one way of doing this. There are lots of ideas on how to do this. Some ideas are super effective for creating designs that solve certain types of problems but this dosn't mean they will always be the most effective

I think it's therefore a good thinking tool to not categorise oneself as a particular kind of designer, eg "OO", "Functional", "Procedural" etc as it can limit your design choices unnecessarily. I also think categorising your design as "OO" or otherwise can also limit your design options.

This doesn't mean you apply every idea that all the other cool kids are using. Your designs should be reasonably coherent and understandable and not a big messy mish-mash of ideas. Though it does get tricky when you want to introduce new ideas and techniques into an existing system.

So what's my point?

There are no rules. However, coherent and understandable systems tend to have "pseudo" rules. The trick is to not mistake pseudo rules as fundamental rules.

Monday, 18 December 2006

Simple Design

This is such a common idea in any kind of activity that requires any kind of design.

There’s the many time quoted "Make everything as simple as possible, but not simpler." by Albert Einstein.

And at first glance this all makes perfect sense and seems quite wise. The problem is that it doesn’t make for a particularly good thinking tool. It would be great if you could look at a piece of software and go, "ok, let’s make this as simple as possible". This often doesn’t help! It can help for getting rid of some obvious crud, but often this keeps the design the same and simply cleans it up. Finding the simplest possible design out of an unbounded set of designs is a lot more complicated than it first seems.

It can be hard enough generating alternative design ideas, often ideas are constrained by various assumptions, the language your working with, the technology your working with, what you've worked on previously, you knowledge of patterns of design etc etc. How would you feel confident that you found the simplest design?

The more I look into design and see all kinds of alternative ways to design things the more I'm not sure what the exact nature of simple design looks like. Of course there's lots of ideas on how to simplify designs, and there's some great frameworks that make things that were hard to do a lot simpler. But...

I think that there is no absolute simple design. I don’t think it’s even definable given a bunch of constraints (eg, context, purpose, etc)

Not that I think anyone thinks there is an absolute but it is worth keeping in mind that simple design is more about having a "quality" of simplicity rather than being simple or not.

Friday, 15 December 2006

Pretending to have written code

This technique is all about writing code based on code you pretend you have already written. TDD uses of this technique to great effect. The idea is you write a test based on code that doesn't exist yet. So, you invent code that you need in order to express the test. Then, once you have the test, you create the real code for the stuff you pretended to have and make it do what it needs to in order to make the test pass.

Great stuff.

However, the idea of pretending that code exists extends beyond simply expressing a test. It also works well for writing the code itself. Write the body of a method assuming that the objects, methods and variables you need are already there. This allows you to play with solving the problem without worrying about having the infrastructure to actually make the code work. This is powerful.

Some of the problems you see when you don't do this....

You start solving a problem, and you figure you need a method in order to solve the problem, so you go build the method, then you go back and try to complete the problem only to find you didn't really need that method, you actually need something quite different. Basically, when your solving something at the specification perspective write the code imagining you have all the things at the implementation perspective.

You ponder a problem and start putting in a bunch of variables that you think you need in order to solve the problem. This can cause all sorts of grief. Firstly, you tend to build infrastructure that you don't necessarily need, and secondly, and probably the worst effect, you can start constraining yourself about how to solve a problem in terms of the variables you have created. This can be massively limiting and can mislead you for a long time especially if you are resistant to throwing code out. This is one of the more common mistakes I have witnessed.

There is an idea in lean manufacturing that you delay decisions to the last possible moment. Or flipping that around, you leave your options open as long as possible. You want to do this in code also, if you make your mind up too early about something it can constrain your thinking and close out alternative solutions before you need to.

By pretending you can express your thoughts faster which tends to give you quicker feedback about whether you understand an idea or there are gaps in your knowledge. ie, quicker learning. As you learn you conceptulise what you need from the implementation perspective without actually writing it till you have conceptually solved enough of the problem that you need the implementation in order to pass a test.

The counter argument I have heard for not doing this is "It's not the way I think", but I think this is a hangover from when you first start programming. When you first start programming in a language your not entirely sure what's possible and what's not. If you write a "pretend method" your often unsure whether you can build the infrastructure or not. example "I wonder if I can hold arrays of strings?" So you investigate whether you can build the infrastructure you think you need. However, once you get proficient at a language/coding you generally know what's possible and what's not. You know what concepts you can express. Sometimes you don't, so its worth going off and investigating. But in general you know.

The constraint to this idea is that you don't want to pretend for very long. You want to work in reasonably tight cycles of writing tests, writing code. And by no means is this a "rule" it's just a thinking tool that can help you write good code faster. It's possible that pretending can constrain your thinking also, so it's good to have other thinking tools you can use too.

Thursday, 14 December 2006

It's a matter of perspective

One very useful thinking tool I've used a lot when evaluating code is the concept of "Levels of Perspective". I haven't seen too many references to this concept, I orginally saw it as a simple side bar in UML distilled by Martin Fowler. There's a few people who have picked up on this idea and I find it really good. I have another blog post sitting in draft where I was going to flipantly make reference to this idea but I thought I should blog on it for those who may not of come across it. It's a fantastically useful tool because I find in a lot of peoples code these perspectives get mixed up willy nilly and its a great tool to work out how to start refactoring a tangled mess back to sensibility. When pointing out this idea in relation to code I see people going "Ah!". (hmmm, wonder if I've praised this concept enough?)

The levels of perspective are :-

Conceptual
Specification
Implementation

The conceptual perspective is to do with classes of objects in your design. What responsibility each object has and hence where methods should live. Common mistakes you can make when you get this wrong is methods on the wrong object hence some objects knowing too much about other objects. Names of classes and methods dont make too much sense when trying to explain your design. Abstract and concrete concepts are mixed together ( I'll do a blog post on this one a few posts down the track because this is one of the main causes of bad design that I've seen, but, theres a few other ideas I want to chuck out there first).

The specification perspective is the particular steps you need to take in order to fufill a responsibility. eg a Move responsibility would require a "Remove From Source" and "Add to Target"

Implementation is the actual code that achieves a particular step of the specification.

A common thing I see is that specification and implementation stuff get mixed together. Often this is done innocently at the beginning but can start making the code confusing as it evolves. Simply separating out these two perspectives can make for much simpler methods.

Once you have specification stuff separated out it then gets simpler to pull this out as an interface then you can vary the implementation by simply providing different objects that implement this interface which then allows for any kind of dependency injection (blog post to follow later....). If your using a language which has duck typing then this is even easier. The specification also helps with talking abstractly about how to solve a problem which then helps you rationalise about the closure (blog to follow later...) of the abstractions you have made. What I mean by this is that you create a language where you can fully talk about the concept your working with.

For example if you are working with a stack, the language "push", "pop", "top", "empty" provides a language to play with stacks. If you forgot to put the "empty" method in then you wouldn't have closure and it would get harder to express how you want to manipulate a stack.

So developing a good specification perspective helps you rationalise about your objects, it helps clear up abstractions, which provides good language that helps you write more understandable code.

All of this is nicely summed up with the "Open Closed Principle (OCP)" (bog to follow later...). A fundamental idea of OO deisgn but OCP is almost too simple of an idea that its often hard to appreciate the subtle influences it can have on your design. That's why I think you need a bunch of thinking tools, like levels of perspective, to help you reflect on how all these thinking tools work.

There's a lot more that could be said about levels of perspective that I could be here forever! However this idea overlaps with many other ideas and I'll refer back to this idea in other blog posts which will hopefully shed more light on all of this.

Don't burn your bridges

Just a followup on my last post and reflecting on Alexs blog about when to kill code.

There's a concept of scope that needs to be taken into account. The scope that I had in mind for my previous post is the day to day code your building. If your about to build a bridge and you dig a hole in the wrong place for the foundation. Back out of it! Don't carry on and "just make the bridge fit".

However, as in Alexs case, sometimes the whole "bridge" is in question once its build. There's fundamental changes you want to make. This can be a lot harder. There's a number of options.

1. Modify the existing bridge in a disciplined and engineered way. This often has a lot of challenges and you often have to work within some limiting constraints. But it can be a good option. It really depends on how fundamentally different you need the bridge to be.

2. Build a new bridge near the old bridge that meets all your needs, provide transitioning roads from the old bridge to the new bridge. But this also has problems, the transitioning from the old bridge to the new bridge may be quite difficult.

3. Build another bridge in another location with no transitions and just hope traffic will change over to using this bridge.

4. Burn the old bridge down and start again. This is probably the worst option, during this time no one can cross the bridge, you effectively destroy a bunch of value and take ages to get the value back.

Everything has pros and cons, there's no clean easy "right" answer. Software is a bit more flexible than concrete structures so we can exploit that to some degree, but there are always tradeoffs, especially when your creating platforms that other people build things on top of. However whatever option you take, in general, I don't think you should burn your bridges.

Wednesday, 13 December 2006

Don't throw good code after bad code

One effective technique for writing good code is chuck out code that's not working out too well. This is probablly one of the harder techniques to get to grips with. It's pretty easy to understand the idea, however, when your actually writing code and have created a bit of a mess it is easy to convince yourself to keep tinkering to get it right. Or, alternatively, you figure you can refactor your way to good code. Usually there's something in your head that tells you that the approach your taking sucks but you know you can hack it to make it work.

Don't. Cut your losses and kill the code.

The fact you realise that it sucks means you probablly understand the problem a lot better than when you first started. Thats the key thing, that's actually the hard part, writing code when you know exactly what it has to do is often reasonably trvial once your confident in a particular language.

You might salvage the unit tests, but sometimes its better to biff those out also. This gives you the chance to rethink your approach afresh.

For starters you might just comment out your code "just in case". This is especially true if the code you have generated is quite complex. Your not quite sure if you can recreate it. However this is often a big stinky code smell and most often you will find a simpler soloution when you do it again. So once you get used to backing out of code then you'll just delete it.

Tuesday, 12 December 2006

Separating Command and Query

Separating command and query is an idea that Betrand Meyer came up with. The general idea is that a method should either be for changing the state of an object or querying that object about its state. eg

widget.Add( 12 ); // command

x = widget.Sum(); // query

Calling sum won't change the state of widget. In fact it is referentially transparent, that is, the call to sum can be replaced with whatever the result of sum is without changing the behaviour of the software. ie


x = 12;

Which just means calling Sum has no side effects.

On the other hand, the command Add" can do whatever it likes to the object. There is no result from the add that represents the changed state of widget.

So why is this a good thing? It helps in separating your code into simple methods that are responsible for just one thing. This often simplifies code. One of the mistakes I have seen people make is that if you have some action that returns a value (mixing command and query). eg

int count = widget.Add(); // returns the number of items in widget

And you use this method in one place, everything seems fine. Sometime later you find you really need to know count somewhere else. But the only way to find out the the count is by adding something. Nuts. So you may end up storing the value of count somewhere for later retrieval but then this starts complicating another object with the details of widget, and worse, count may be wrong by the time you use it, or, even worse yet, you may end up doing a hack that Adds something to get the count then immediately removes it again. Where as what you really need to do is separate the command and query and simply ask the widget for its count whenever you need it. This is a bit of a simplified example and generally you fall into this trap when the objects and methods semantics are not so clear. In fact sometimes renaming a method can be all that's needed to show this confusion.

Of course, there are many examples you could come up with as to why you may not want to separate command and query. That's fine. As long as you know you're doing it. Most of the problems come when you don't realise your doing it. It's just one thinking tool that helps you evaluate code and potentially help you name a problem.

One nice thing you can do if you do with commands is return this/self as the result. This then allows you to do command chaining eg.


widget.Add(1).Add(2).Add(3);


For some, this whole command query thing may seem all too obvious and trivial, but I wanted to blog on it since I have seen people getting their code in a mess because they didn't make the clear distinction between command and query.

Monday, 11 December 2006

Award for Kiwifruit blemish

We got an award http://www.frst.govt.nz/Awards/TechCommendations.cfm for our kiwifruit blemish technology this year.

Cool technology! If anyone out there would like a job working with this kind of cool technology we are looking for some absolutely top notch developers. Preferably with some kind of background in product based technical software development. Ideally with fantastic OO, TDD / Unit testing, and C++ skills. However, we are mainly looking for really smart people who understand how to create good software.

If interested, send your CV to keithn (remove this) @ compacsort . com

Thinking Tools

One thing that I think is very important in software development is having good thinking tools. By thinking tools I mean any ideas, tips, insights, philosophies, questions, "rules", approaches, etc that helps you build software. These mental tools then need to be arranged into some kind of coherent structure so that they make sense and you can reason about them.

It is very important to have this coherent structure of all your thinking tools otherwise you can end up limiting yourself unnecessarily. for instance

C++ Macros are bad!
The law of demeter!

There is a piece of wisdom behind these ideas and this wisdom has been encoded into a very digestable rule or "ethic". However the real wisdom is not well represented by this nicely packaged idea. These ideas live in eco-system of thinking tools and should be assimilated into a coherent approach about creating software. This approach needs to be constantly re-evaluated and filtered and re-interpreted. Many perspectives need to be incorporated, experience needs to be gained, mistakes need to be made.

Philosophically speaking we need to take a somewhat post modern approach to software development ideas. The ideas of deconstructionism and hermeneutics are very useful here as we look at some of the"rigid" concepts of software development and as we read various peoples thoughts on software development.

I'm not sure how my next few posts are going to work out, but I want to discuss a bunch of thinking tools I use and also hopefully articulate some of the overall concepts I have of software development.

Saturday, 9 December 2006

Blog Refactored

Well, I used to host my own blog on my own site but I think I over estimated my interest in finding some good blog software and getting it all setup. Instead I went with a basic blogging engine, but I tended to get spamed to death, so I gave up on blogging. However, for a while now, I've wanted a place to write down a bunch of evolving thoughts I have had about creating code, designing, and the overall philosophy of creating software. This is more of a selfish interest thing, I find that if I try to write all this stuff down I have to think things through a bit more thoroughly and reflect more on the sanity of what I'm writing. So, this time round I've decieded to go with blogger. I've used it before for non software blogs and it's all nice and simple and hopefully I will make a lot more use of it!