Hosk Cowboy Coder – YEEHAW


In yesterday’s blog post which had a bit of a cowboy theme with the Good, the Bad and the ugly, it was about the Bad for..in loop in Javascript

One of my twitter followers, posted today I was a cowboy coder which I found funny but then someone just retweeted that to 2346 followers

Cowboy Coder


I love the thought that 2346 of @recuweb twitter follows will just see the tweet @BenHosk Cowboy coder, no explanation, it’s awesome

Below is the twitter conversation


Embrace your bad code

There are two types of CRM Developers

  • Those who know they make mistakes
  • Those who think they don’t

I’m not saying you should all rush out and write cowboy code but I am saying be ready to admit you will write code that can be improved or even thrown away.

I was going to use the subtitle of “Embrace your bad code and then strangle it”.

The point I’mmaking is you will make mistakes, you will write bad code, create customizations which could be improved but these present you with opportunities to learn and improve.

Everyone makes mistakes and sometimes your code gets peer reviewed and slammed.  Don’t take it personally, use it to find out what’s wrong with it and why you shouldn’t do it a different way.

Make it work and then Refactor

When I write code my first goal is to make it work and do what needs to be done (what ever that may be).  The next stage, which is a stage many poor CRM Developers miss out (the word contractor jumps into my mind) is the refactoring and tidying stage.

Everyone is under time pressure, but not cleaning up the code will only make it harder for you to maintain and fix the code later.  Fixing code now, when you understand how it works and what it is supposed to do will take a lot less time than trying to find a bug in messy code 6 months down the road.

Talk/blog about it, learn from it

Talking to CRM Developers or blogging about your coding experiences you will learn where your mistakes were madimportantly you will understand why they wrong.  I always find when I understand the logic of something, I am creating more mental pathways to that information and increasing my chances of not repeating my mistakes.

When ways make logical sense to me it makes me want to do them.

In yesterdays blog, I found a bug and fixed it

CRM 2011/2013 – What does setSubmitMode do? and how does it work?

I then talked about it with a developer and learnt there was a bad For..in loop in Javascript

Beware of the Bad Javascript for loop

Today Guido from the excellent CRMAnswers blog left me a comment on how to do the code in one line

for this specific case the forEach method of the collection can be used:

Xrm.Page.data.entity.attributes.forEach(function(attribute, index){attribute.setSubmitMode(“never”)});

just 1 row, no bad loops 🙂


The one bug has lead me on a journey and I have learnt

  • Javascript for statements can return functions
  • isNAN will only return numbers
  • How to open a page impersonating IE8
  • There is a bad for loop and a good one!
  • The solution to the bug
  • A one line solution to the bug
  • That lots of people think I’m a cowboy🙂


Suck a little bit less everyday

My goal is to keep learning, continuous improvement and suck a little bit less every day and become a better CRM Developer.

I view every mistake I can avoid making, hopefully means I have replaced the mistake or poor code with some good code


Finally – Don’t forget there are some good cowboys out there

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s