Monday 28 February 2011

Just a quick fix, just a quick fix, boom! Game Over Man!... Game Over...

What are these quick fixes? Are they the start of the end? Or is it already too late, as when you've found there are a few quick fixes, does that mean there are thousands of them in already, more than likely yes!

What causes them?

  • Friday afternoon? 
  • No time as other things are important to get done? But what is more important than the current fix you are doing, if you have to rush it to get onto something else, then don't do it!
  • Because it doesn't break any unit tests? Are then the tests written correctly, if they are stopping quality being writing?
  • Is it the lack of pride and care in what one is doing, or any thought for one's colleagues as one is not going to be around long enough when these fixes come back to bite you in the ar!*e!

All these questions and no answers, not sure I can give any answers yet, but if I find some I will surely post back here.

Is this what agile is? Do a fix in the first place you can see the easiest place? Or is it to refactor code into the correct places to fix the issue, maybe its neither?

What do the sum of these quick fixes add up too? I tell you what! A bloody mess of looking at random, undocumented code here, there and everywhere, slow down of progress, and skewed estimations. Code spread, where these fixes are not structured in the correct layer! More than likely more fixes will be required to fix the fixes! Superb! That's some special mess!

Are developers being continuously squeezed to write code to be “finished” rather than “completed with quality”? Or do developers wear blinkers and only see progress as a happy product owner? Is there a way to prove this?

Time is always squeezed and quality drops! This will inevitably get worse over time ‘Mr Anderson’…
Well commented code, we hopefully don’t need too most of the time (well you shouldn't so much) as the code is readable (isn't it, you good coders you), but the more quick fixes (I suspect highly uncommented)… ...who knows what randomness is being produced.

I guess there is a time line where the quick fix is fine, for a small, completed, un-evolving project. Are there such projects, really?


I recently came across an interesting article and I haven't looked into it yet, but could be very interesting. Convincing team members that something is a good idea.

Saturday 26 February 2011

Calling all Devs, Calling all Managers (if that's what you can call them)

Seriously! The guys in my links need to be followed by all Devs and Managers especially. I've only just started doing this reading myself, but quickly realising that these guys are well worth reading.

Just read them, they are not big articles. They make a lot of sense and are very experienced people, so why wouldn't we want to listen to them absolutely confuses me.

Its probably wise to be spending some time, reading at least one article a day, and/or learning one new feature of a piece of software that we use every day/week. Visual Studio or Resharper or maybe some software framework you are using, automapper, nhibernate, etc. I am trying to do this but not religiously yet. I will get there.

I have also just been recently told that  looking at somebody elses source code once a week, also helps. I have not done this yet but I think I am going to start. I'm going to start with Jimmy Bogard's Automapper. Take a look around see how he does things, learn any ideas from it hopefully and also how he writes his code and his unit tests, especially his unit tests as I'm finding this difficult to understand how these are meant to be written at the moment.

If I learn something I will report back on my blog some where hopefully.
I think I hear you ask where the hell do you get the time to do any of this, well don't worry I am also asking myself this question, and now I am writing a blog too! I still want to do all the above and more...

I'll be adding more links to articles I find in here and to 'My Links' also.

Hope you find something useful from this, or if you have any more useful links, let me know and I'll have a read and add them :-)

Some links...

Stand Up Meetings
http://codebetter.com/jameskovacs/2011/03/28/stand-up-meetings-are-about-more-than-standing/

Martin Fowler
http://martinfowler.com/bliki/TradableQualityHypothesis.html
http://martinfowler.com/bliki/TechnicalDebt.html

Friday 25 February 2011

42, 1, 0, temp1, fred, squid, WTF!

STOP IT! STOP IT! STOP IT!

Seriously what do these numbers mean to anyone else looking at your code, or in fact to yourself when you come back in a week or two (in my case a day)?

Damn magic numbers and random variable names, awesome tactics if you want to spend time looking at the same code day in and day out trying to figure out what they mean, especially when the same number means two different things in the database or even three. Genius!

Use an enum damn it! Give those numbers meaning! Tell me what they are! Tell yourself what they are! Rather than me/you hunting through the damn code to try and work out what they mean!

Name your variables something useful, and your methods too!

not so nice way...

   15         public void CheckEngineManagement()
   16         {
   17             //Call something to get the data of the engine.
   18             var engineData = GetEngineData();
   19 
   20             if (engineData.State > 0)
   21             {
   22                 if (engineData.State == 1)
   23                 {
   24                     //Do some engine checks for oil,
   25                     //seatbelt checks etc, blah blah,
   26                     //or something else
   27                 }
   28             }
   29         }

I seem to be stuck in the car world at the moment, I will have to think of some better examples.
So there are the different types of EngineData coming back from the database, all in the same table with a column to state the different type. Maybe bad maybe not, but I am trying to find an example.

I get my engine data back for a particular car, ferrari engineData, superb, then I do a check on the State if it's less than zero don't do anything, if it's 1 then do something. IF IT'S 1, IF IT'S 0 WTF does that mean? The door is open, ignition is on, car started, what!? Especially for different engine data 1 could mean something else and it probably does when written magically!

nicer way hopefully...

    8     public enum CarState
    9     {
   10         CarLocked,
   11         PassengerOpen,
   12         DriverDoorOpen,
   13         KeyInIgnition,
   14     }


   23         public void CheckEngineManagement()
   24         {
   25             //Call something to get the data of the engine.
   26             var engineData = GetEngineData();
   27 
   28             if (engineData.State != CarState.CarLocked)
   29             {
   30                 if (engineData.State == CarState.DriverDoorOpen)
   31                 {
   32                     //Do some engine checks for oil,
   33                     //seatbelt checks etc, blah blah,
   34                     //or something else
   35                 }
   36             }
   37         }

Ignore the nasty if nesting, I will have to think of a better example, but I can't at the moment I am fuming!
I have taken away all the nasty numbers, now you can read that the car is locked or the driver door is open and see what its trying to do and why its doing its checks for oil, seatbelt checks etc. not having to spend a larger amount of time understanding the whole code to work out what the numbers are and why they are there!

Sooner or later those ifs would have ended up all over the place nested like crazy with a mix of the engine data type amongst it all no doubt, can you imagine trying to read all that lot with just numbers?

Give me a slap for nesting if's like that, probably could have used a switch or probably even something else. Or suggest a better idea for my demonstrations. Or just a slap anyway. I am just trying to get some of the simpler things across at the moment.

Thursday 24 February 2011

Polymorphism, really... what's that...? omg you need a slap in the face!

Well it begins...
Before I start I have to admit I am also guilty of this but it needs to come out.

Why the hell do I have to see code with 4 million if and switch statements, especially when its switching or if'ing on an enum called <some name>Type and of course to get me more mad, yes its in the base class too, what a genius, what the hell are you doing!

Yes that's right, it even has the postfix of "Type", surely that has to give some kind of clue, that hmmmm, maybe this enum your switching on, shouldn't be there, and yes you can do it without having to switch, that's what polymorphism helps with, let me try to demonstrate...

Its not a superb example, but its the first thing I could think of, hopefully I can change it to something better when I can think of something, but for now I am hoping I can get some of the point of polymorphism across.

not so nice way...
    8     public enum CarType
    9     {
   10         Ferrari,
   11         MorrisMinor,
   12         SomethingElse
   13     }
   14 
   15     public class Car
   16     {
   17         public CarType CarType { get; set; }
   18 
   19         public void StartCar()
   20         {
   21             switch (CarType)
   22             {
   23                 case CarType.Ferrari:
   24                     //Car Senses key fob.
   25                     //Car starts.
   26                     break;
   27 
   28                 case CarType.MorrisMinor:
   29                     //Key fob turned.
   30                     //Car starts.
   31                     break;
   32 
   33                 case CarType.SomethingElse:
   34                     //Some random stuff to get this car to start
   35                     break;
   36 
   37                 default:
   38                     //Do some default stuff to start all other cars.
   39                     break;
   40             }
   41         }
   42     }
   43 
   44     public class Ferrari : Car
   45     {
   46         public Ferrari()
   47         {
   48             CarType = CarType.Ferrari;
   49         }
   50     }
   51 
   52     public class MorrisMinor : Car
   53     {
   54         public MorrisMinor()
   55         {
   56             CarType = CarType.MorrisMinor;
   57         }
   58 
   59     }
   60 
   61     public class SomethingElse : Car
   62     {
   63         public SomethingElse()
   64         {
   65             CarType = CarType.SomethingElse;
   66         }
   67 
   68     }
   70 
   71     //Some code somehwere to start the car you have.
   72     var ferrari = new Ferrari();
   73     var morrisMinor = new MorrisMinor();
   74     var somethingElse = new SomethingElse();
   75     ferrari.StartCar();
   76     morrisMinor.StartCar();
   77     somethingElse.StartCar();

So this has the 3 types of cars, and they all should start in a different way. When you create an instance of these cars and call StartCar they all call the same method, which then switches on some dodgy enum to distinguish the types, pffff.

OK it works but a car doesn't need to ask itself if its a ferrari, or a morris minor. What happens if a new car comes out does that mean all the other cars then need to be upgraded to then ask itself if its the new car on the market? Therefore, increasing the switch/if statement every time. Sounds like that could be a nightmare to me.

a nicer way...

    8     public class Car
    9     {
   10         public virtual void StartCar()
   11         {
   12             //Do some default stuff to start all other cars.
   13         }
   14     }
   15 
   16     public class Ferrari : Car
   17     {
   18         public override void StartCar()
   19         {
   20             //Car Senses key fob.
   21             //Car starts.
   22         }
   23     }
   24 
   25     public class MorrisMinor : Car
   26     {
   27         public override void  StartCar()
   28         {
   29             //Key fob turned.
   30             //Car starts.
   31         }
   32     }
   33 
   34     public class SomethingElse : Car
   35     {
   36         public override void  StartCar()
   37         {
   38             //Some random stuff to get this car to start
   39         }
   40     }
   41 
   42 
   43     //Some code somehwere to start the car you have.
   44     var ferrari = new Ferrari();
   45     var morrisMinor = new MorrisMinor();
   46     var somethingElse = new SomethingElse();
   47     ferrari.StartCar();
   48     morrisMinor.StartCar();
   49     somethingElse.StartCar();        


Ok here I have completely removed the enum, as its completely not needed. We already have the type, its a Ferrari, or MorrisMinor, the base class (Car) doesn't care.

I have made the StartCar method a virtual method so all the base classes can now implement their own implementation, they have the knowledge on how to start themselves. So if a new car comes along they can then implement their own StartCar method, and no other car needs to know about it. If StartCar isn't implemented then the default one in the base class will be used.

Look no more switch or if, its all gone. You now don't need to read complex code, well it wasn't complex as it was but when new types start appearing it will creep in there.

I hope my explanation makes some sense, if you like, don't like, or would like to suggest something, let me know either way, or of course just slap me! I am learning here too :-) I think I can probably go into some more depth on how it works but at the moment I think I will leave that for now, hopefully there is enough there to understand the basics of getting rid of them nasty if's and switches.

I am not sure if there is any kind of excuse to have to do the "not so nice way...", maybe I am missing something, but I know its easily done, done it myself. Maybe its a lack of time and pressure and your brain only thinks like a 'C' coder in straight lines (sorry 'C' coders out there I used to be one too, very long time ago, and if I am wrong there, please tell me and give me a slap!). I really don't know as I am sure the second way is actually less code and thinking.

That's another thing what gets on my tits too is seeing OO code written like 'C' (before I explode screaming, I will have to save that for another blog)

Hmmmm, I wonder if its possible to write code without if's, yes ban them, maybe bring a flag out in the compiler you can turn them off! I think that's another post rant too.

I can't believe I keep generating new ideas for a blog post without having even thought about it before. This bloging/ranting is superb! I recommend you try it.

Hopefully I will get to some more complex things in the future, but I guess I am learning to write too at the moment.

Tuesday 22 February 2011

More why's and how's...

Well it has to be said a big thanks to a couple of new colleagues I have worked with recently as to why I am doing this. That is to a Justin Blackwell (I am sure Justin will have something somewhere to link) and a Simon Lovely

With the introduction to Skills Matter and heading off to only a couple of free talks, this started to get my taste for really understanding things and bettering my skills, thought nothing of it really as it was only a little tingling.
Only been to 2 of them, that was

  • with Udi Dahan and a talk on CQRS, was bloody brilliant! really got me thinking about a few things, really interesting.
  • and the other was with Ayende Rahien with a kind of talk on how to go about making software that people want, the WOW factor!
Both of them superb! But also makes you realise the ton of crap that is out there!

Then talking to Simon and Justin more they introduced me to a lot of new blogs (well I say 'new' what I really mean is my first blogs and people to start following and read up about). 


Unbelievable I was in this cloud of denial for so long, the stuff I started to learn from a few of these posts... well... that tingle became a bit more than a tingle, now my passion started to grow more for learning and picking up new things, what people were up to out there and what was about and around the corner.
I still can't find something these guys don't know about yet, will do one day ;-) lol

They then mentioned to me DDD9 was coming up, well of course me sitting there in my cloud "What the hell does that mean?". Of course found out off them what it was and I think I actually managed to register before them, in the end I had to remind them to apply ;-) (Check me out!) Well went along and absolutely thoroughly enjoyed what I saw and the guys delivering the talks. (Probably will try and talk about this day in another post if I remember between my angry rants)

Unbelievably I think I have learnt more in the last several months than in the last 10 or so years career in  software development. I noticed with these guys they seemed to know hell of a lot about all sorts of fields of programming and there I am, well I know C++, I know .NET C# (I thought I did at least) I know databases and to layer stuff nicely so code is grouped nicely, all the kind of OO around it all to make it lovely and maintainable. (well it was a bit more than that I hope...).

OMG when I started to have words thrown at me like:

  • ORM's (I actually started doing my own ORM as I thought it would be an awesome idea, but I didn't know that it was an ORM I was actually creating), what a nugget...!
  • DI, IOC, 
  • Document DB's, 
  • Automapper, 
  • Linq, 
  • CQRS, 
  • patterns(which I used without realising they were patterns already), 
  • I am sure there is more, but can't think of any at the moment
then all the names of software that can handle all this stuff, my brain pretty much exploded and I was blocked with all this information overload. I was then curious on how the hell these guys knew it, done it, learned about it, etc..

I found out... well I think I have... could be different for everyone, following blogs, posts, trying a couple of things out, and now to actually to write down what I think, will hopefully imprint it into my brain more.

Inspired and a hunger for knowledge is an understatement, I want to write about so much stuff, so I can get my understanding across to who ever may want to look at it. Knowing deep down I am learning hardcore style. Maybe someone else will learn off me, now that would be awesome feedback!
Maybe I will get the balls and start posting on Stack Overflow but one thing at a time hey ;-)

Actually I have already learned from my first blog, maybe only a small thing but its the fact now I remember who that guy was who wrote that article about something, Jeff Atwood

Well thanks for reading again... who ever is out there
Rants incoming...

Monday 21 February 2011

My First EVER Post!

Well here it is...

Its about time I have started this, I've been putting it off far too long, well I say putting it off, I probably mean ignoring, denying, refusing that these things exist, and that I have actually anything important to say. I then realised maybe its not that I may not have anything important to say, I may do, its more about practising to write better, formulate ideas, maybe be able to provide solutions to problems too, and I guess most importantly if possible to get feedback of any sort, what a great way to learn ;-). 

Two things kicked me over the edge to crack on and start writing:
  • this post by Jeff Atwood, great post! Anyone who is half thinking of or maybe denying the existence of bloging, writing like I was, take a read... let me know how you feel afterwards ;-)
  • and starting to write an angry email about the absolute school boy error code that I seem to have to put up with, and realising maybe I should blog.
...then the idea was formed, AngryWelshCoder, because I was spitting feathers at my computer, I am Welsh and a coder too hopefully.

I am still learning these kind of gadgets and also how to write too, so hopefully my practice will give me a better knowledge on these things and also how to write, I can't wait...

This blog may change about too, as I am still getting used to how all this stuff works. How much shall I write about? Am I allowed to swear? Should I apologise now up front for all my future posts that I will be so angry in? maybe... So much to think and write...
My brain is kind of running away with me at the moment in trying to get all this down...

Should I stop my post now or shall I continue, I have no idea! I actually have plenty below this already that I am going to cut out and stick it another post... again about more why's and how's I got inspired to do this, but I promise after that I will start to get angry!