Showing posts with label IMO. Show all posts
Showing posts with label IMO. Show all posts

Tuesday, April 26, 2016

LIMO - LeastInMostOut methods

I've been experimenting with different guidelines to help me construct better code. In particular I've been pondering 'how to decide the best arguments for a method'. I started to consider this question a little more, while reviewing another colleagues code. I was struggling to understand what I didn't like about their code, and why. Finally I think I have a 'reason' why their code has a bad flavor to me.

The code was simple enough, but it took large, full agg-roots as parameters. What smelt funny was, only one little VO was needed, yet the class was now coupled to the full AR, without much reason.

As a result the class method was now coupled to the full AR, though it could have been much more reusable, simply by taking just the bit(s) needed. After some googling, and asking other seniors, I couldn't find anything to 'point at' and say, see this guy recons it's better not to couple the classes like that.

So now, here a post to 'point at'.

Guideline:

Methods should take least in arguments to do their job. They should return most out to callers (LIMO).

Why?
Taking the Least-in reduces coupling by only requiring the information needed by the method. It also improves readability by making it clear what the method needs. 

Return the Most-out data you can, this improves re-use of the method while reducing the need for change in the future (Open-closed principal).

Notes:

This does not mean every argument should be a string or some other native type. An arguments type help describes the constraints. For example a method "GetDataFromAServer()" should take a URI rather than just a String.

Another Trick I find useful is to look at how a method argument is used directly inside the method. If the argument is immediately converted to something else, then sometimes this is a clue that some refactoring may be needed.

I tend to return the 'most-data' so the caller can decided what is relevant to them. Some might think this leads to exposing internal class-structure, and I would agree. In my code 'returning the most' helps with unit tests, it also reduces re-coding. If / when I want to return less information, I generally have an interface to express this.

One last trick; at the moment I'm returning this on methods which would normally be void-return. The idea is that by returning this, I'm providing some info to the caller and making caller code flow more. I'm not wed to the idea, this does have a down-side. I now have some difficulty knowing if a method returns a new instance, or the same instance.


Saturday, September 25, 2010

OS; Change in the wind

Context:
I have been a (proud) Windows fanboy since Win3.11.
At Uni I studied physics, by the end of my masters, I knew I wanted to be a developer; so I learnt C, and started building a career based on developing software for Windows. Back in the day, Windows was brilliant, it dominated desktops, gave me a single popular platform so I could build skills and get work. Sure there were challenges, but that's software development.

I just received a 'disturbing' email from my dad.
I received the email via gmail (Google). I gave up on Outlook about 3 months ago, too many problems trying to look after .pst files, could never find old emails in outlook.. it all got too hard so I imported everything to GMail.
The email was popped up on my iPad (Apple), using Google mobile-sync.
Yesterday I gave up on windows-live in favor of Blogger (Google), a close call, nearly went Wordpress.

So, the subject of this email:
Bought a Mac.
And the content:
Well I finally got so sick of Vista I bought a Mac. 500gig 21.5" screen.
Vista was the cause of my not being able to access Bigpond (4 weeks of Technical support) by doing something to the usb ports and it also again stopped the disc drive from working so I couldn't install Windows 7
Installed the wireless Broadband onto the Mack and away it went no problem.
This time last year, I knew one person with a Mac; the wife's boss.. he's in the 'creative' music industry, so I forgave him because he has to be 'hip'.

Today: My dad, and 2 of my sister-in-laws' use Mac's.
I don't have a big social circle; so in my little corner of the world, this is a massive change.

This is one of those; things that make you go hmmmm....

P.S Gah, trying to write this blog; IE keeps crashing???... looks like I'm going Crome.

Friday, September 24, 2010

A new day, a change of blog

Ok, firstly; I'm a lurker.
I lurk here, I lurk there... I lol, but rarely contrib.

Ever since getting an iPad a few months ago, my lurking has almost reached a professional level.

In a possibly futile attempt, I'm going to try blogging. If nothing else, I'll have my own little corner of the net to post in.

What you (should) find here:

1. Unstructured ramblings about software development.
2. Bad spelling, bad English bad punctuation.
3. The occasional curse words
4. Posts that are nothing but likes to stuff.
5. Lists... I like lists.

A short list of C# coding issues.

Injecting services into entities It been bugging me for a while now that to use services in a entity can be a bit of pain. It usually starts...