How to improve as Dynamics 365 developer

Everyone wants to improve but few want to put in the work needed to get better #HoskWisdom

Becoming a champion is not an easy process… It is done by focusing on what it takes to get there and not on getting there – Nick Saban

 

Improving as a Dynamics 365 developer takes dedication and persistence.  It takes years to build up your experience and knowledge but you can speed up the process by learning from the mistakes and experience of others.

This blog post my advice to Dynamics 365 developers who want to improve.  The core message of the post was written to a frustrated junior developer who wrote me an email simply saying “I want to stop making mistakes and get better, what is the quickest way to improve.”

A few posts improving and tips to improve, start by reading those

No shortcuts

Becoming a good Dynamics developer is difficult and takes time, which is why there are so few good Dynamics developers.

 No shortcuts to becoming an awesome Dynamics 365 developer 

It involves focus, effort and learning from your mistakes.  The more focus on improving the quicker you will improve.   It takes time for your skills, knowledge and experience to accumulate and learn from your mistakes.

Aim to finish work wiser about Microsoft Dynamics than you when you started.  Each day learn something new, improve your skills and reflect on your experiences

If you want to be a better coder then commit to being better and start being a better coder now #HoskCodeWisdom

There is no shortcut, only time and dedication.  Warren Buffett talks about Charlie Munger and his focus

“Charlie, as a very young lawyer, was probably getting $20 an hour. He thought to himself, “Who’s my most valuable client?” And he decided it was himself. So he decided to sell himself an hour each day. He did it early in the morning, working on these construction projects and real estate deals. Everybody should do this, be the client, and then work for other people, too, and sell yourself an hour a day.”

Enjoy being a Dynamics developer

 “You must understand the following: In order to master a field, you must love the subject and feel a profound connection to it. Your interest must transcend the field itself and border on the religious.” ― Robert GreeneMastery 

 

If you don’t enjoy Dynamics development you will find the work boring and the days long.  If you are not passionate, you won’t care enough and you devote the time needed to improve.

Want to improve

Development is difficult but rewarding when you do it well #HoskCodeWisdom

Improvement comes from within, it‘s a desire to get better.  You need a passion for development, keep motivated, know why you want to improve if you don’t have a good reason you will give up.

It’s a slow process of continuous improvement, end each day learning something new or improving skills.  This is sucking less each day.  Junior Dynamics developers struggle with the limitations of Dynamics 365 functionality, often creating a customisation only to find due to a limitation the solution won’t work.

Why .NET developers struggle with CRM Development

A student mindset uses opportunities to learn and improve,  the more experience and knowledge you build the fewer mistakes you make.

“Most people don’t have the patience to absorb their minds in the fine points and minutiae that are intrinsically part of their work. They are in a hurry to create effects and make a splash; they think in large brush strokes.

Their work inevitably reveals their lack of attention to detail – it doesn’t connect deeply with the public, and it feels flimsy.”
― Robert GreeneMastery

Visualise your day – plan your day

What will you check? What processes will you follow?  When visualizing the perfect day, remind yourself how you should do everything.

Plan your day, make sure you tackle the important tasks and don’t be reactive to change via email or requests.  Developers need to concentrate and focus on one task, avoid switching between many tasks and losing time through switching.

Don’t let email push low priority tasks to the front of the queue,  Email tasks can be the tasks which shout the loudest but the task you do next should be the most important.

Reflect

Learn from your experiences, review your mistakes you and avoid repeating them.  Inspecting how you work and adapting, keep improving.

Learn from your mistakes, identify patterns, catch yourself from being busy but not productive.

The person who doesn’t learn from their mistakes, repeats them.  Don’t waste your experiences, make the most of them.

Start with the SDK

The CRM SDK is the main tool for a CRM developer, the better a CRM developer knows its capabilities, limitations, and documentation the better they do their job.

Every time you don’t understand something, read the Dynamics 365 SDK, understand it, master it.

Improve code quality

Read Clean Code: A Handbook of Agile Software Craftsmanship.  To write simple code you need to understand design principles are important, they decouple code and avoid making code brittle.

Brittle code with large methods is hard to read and breaks.  When you change one line of code ,it breaks other unrelated parts of the code.  Controlling dependencies and decoupling code allows you to manage the effects of change.

Naming is important, go back over your code and get the names of variables, methods and classes correct.  Like writing a book, developers never give the best names in the first draft, it‘s important to edit, refactor and refine your code.  The first draft gets it working, further drafts are to simplify and improve readability.

Design code

Don’t just write code. Think about it, design it, write it, refactor it, be proud of it #HoskCodeWisdom

Before you start typing, spend time designing your code, find classes and abstractions.  Designed code is easier to read, debug, reuse, unit test, maintain and extend.  All code has an impact, well-designed code minimizes the dependencies

Understand SOLID principles

SOLID principles are the building blocks of good code.  You will produce better quality code, fewer dependencies, and fewer problems later.  SOLID principles help developers recognise good code.

Help yourself

Don’t suffer in silence and sit frozen in front of the code, don’t waste time not making progress.  Don’t look give me the answer, I want to be pointed in the right direction.  Software development has lots of dead ends where to solve a problem you must rule out options and clarify assumptions.

Resolving your own problems is time-consumingbe pragmatic and know when to spend the time learning it yourself and when to get help.

A useful tool is to describe my problems to a toy/cardboard developer,  explaining the problem to the toy and myself I can uncover the solution and I avoid wasting other peoples time.

Why all developers should be friends with a cardboard developer

Understand how Dynamics CRM works

He who knows the most, get’s paid the most #HoskWisdom

Take every opportunity to understand how Dynamics 365 works. A greater knowledge of Dynamics 365 allows consistent choice of the right customisations and enabling quicker trouble shooting.

Dynamics 365 error messages point you in the right direction

Seek out what you are weakest

Improve knowledge and skills, build up your experience.  Don’t hide from these, focus and improve.  Use weaknesses and mistakes as triggers for learning.

Its better to learn functionality before it’s needed on a customer project, where the pressure is on and deadlines are looming.

How to cope when you are out of your Developer comfort zone

Learn from colleagues

Fellow developers are walking, talking troves of knowledge and experience,  learn from their experience.

Colleagues might be useful sources of knowledge but don’t ask them for help without trying to solve problems yourself.  Solving problems yourself gives you the solution and the learning.

The goal is to create customisations delivering the required functionality but it‘s the journey which improves your skills.  Create customisations and get senior developer to ratify your solution.

All developers have tips, tricks and shortcuts which can help you, if you ask and talk to them.

Write unit tests

Know how are you going to test the logic of your code, understand every line of code is doing what it should.

Test your code with unit testsit‘s best practice and encourages you to write decoupled code which is easy to unit test.

A good framework is Unit Testing Microsoft Dynamics CRM using FakeXrmEasy Framework

At Capgemini we structure plugins to separate business logic and repository layer (CRM SDK CRUD) to make testable.

Unit tests are a vital part of emerging code design 

When manually testingDonjust test the happy path

Talk Dynamics 365

Talk Microsoft Dynamics 365 with your colleagues and you will learn something or at worst give information to someone else.

Share knowledge with the team and work together to create a broad knowledge of Dynamics 365 bringing in your differences experiences and thoughts.

Be organised

Don’t waste time looking for files, projects and code.  Be professional, be organised and minimise distractions.

Get Certified

Certifications gives a more rounded and in-depth knowledge of Dynamics 365.  Investigating functionality in Dynamics 365 which they no practical experience of.

Dynamics 365 is the developers main tool, they should know it inside, outside, up and down.

Studying for Dynamics certifications helps to understand the limitations of Dynamics 365 functionality.  Limitations are key factors when deciding the right customization for a requirement.

Average is not good enough

Developer skills are like a snowball, they start off small and quickly pick up speed as your knowledge and skills grow #HoskWisdom

Don’t do average work, do great work.  Customers and other developers can quickly tell if someone is delivering quality work.  Good developers code works well and anticipates the needs of the users, it contains fewer bugs and when bugs are fixed they don’t bounce back.

Developers who work too quickly often don’t fully understand the requirements, don’t clarify them and deliver what they think the users want.  The code contains assumptions and bugs and never seems to be finished

Deliver code you are proud of

Don’t put non-supported customisations

If you write unsupported customisations Microsoft will not support your Dynamics 365 customisations.  A detailed explanation below

Why you shouldn’t put unsupported customizations in Microsoft Dynamics CRM

Know why things are not working

Errors and functionality not working is an opportunity to learn.  Don’t just find the solution on the internet, make sure you take the time to learn what the problem was and how/why it’s fixed.

Microsoft Dynamics CRM not working? check these common causes

The next problem you might get could be different and the better your understanding of Dynamics 365 the quicker you will be able to diagnose the problem.

Read CRM blogs

There are lots of great Dynamics 365 blogs which will help you keep up to date with the latest functionality in Dynamics 365, you can find a great list of them here

https://community.dynamics.com/crm/b

I also recommend follow these hashtags on twitter

  • #MSDYN365
  • #Dynamics365
  • #HoskWisdom and #HoskCodeWisdom 🙂

Finally here are some of my other favourite blog posts I have written

Advertisements

Are you a Dynamics Craftsman or a CRM developer?

“Don’t comment bad code—rewrite it.” ― Brian W. Kernighan, The Elements of Programming Style

The quality of your work is related to the standards you set yourself #HoskWisdom

 

A few months ago I joined Capgemini and people have been asking me what attracted me to join the Capgemini CRM team and what it‘s like to work for Capgemini.  What attracted me is Capgemini’s want to bring software development principles to Dynamics CRM development and focusing on delivering quality enterprise Dynamics CRM/365 projects.

What I really like is Capgemini Dynamics CRM projects have DevOps who setup automated deployments, Continuous integration,  one of the greatest gifts to dynamics developer because it allows more time in creating customisation

Are you a Craftsman?

When interviewing developers I like to ask them if they are Craftsmen or developers, this question finds if the person being interviewed is driving the quality of their work, if they have pride in what they are creating.

Creating quality code like motivation comes from within and can’t be forced using standards or rules.

Dynamics developers need passion – CRM Developers need Passion and joining Capgemini is a good fit because we shared many beliefs.

It‘s importance to keep the quality of CRM projects high and manage technical debt, these principles are even more important on large projects where poor quality code can slow the project and maintaining code can become a nightmare.

I experienced a project where it took 1 day to add an easy fix because a plugin had one method with 2000 lines of code

I can recommend the book

I recommend a few other books in the post – Why isn’t code reused in Microsoft Dynamic CRM projects?

My experience of CRM development

I started out as a Java developer and learnt traditional programmer principles.  Learning about programming and I remember being iinspired by code craftsman and reading Effective Java : Second EditionHead First Design Patterns, Object orientation programming and other books listed on Recommended Books for Developers.

There was a story about a developer learning to become a craftsman, it was featured in a magazine and was a regular column. It talked sbout problems newbie programmers walk into without realising.  (it was called something like the woodcutter or craftsman)

When I moved from Java/.netdevelopment it seemed many CRM development companies didn’t follow good software development practices or good coding standards.

  • CRM code often put all the code into one method in the plugin
  • Lack of classes
  • No unit testing
  • No automated builds
  • No code reviews or static analysis

There are a few reasons for this

  • Microsoft Dynamics CRM made it difficult for automated builds (before solution packager)
  • Companies were not interested in invested in
  • Many CRM projects were small with no budget for automated builds and unit testing
  • CRM developers often didn’t have programming experience or knowledge of SOLID principles
  • Timescales were short in projects – focus on short term gains

Dynamics CRM and developer principles

When I interviewed with Capgemini they wanted to know my opinions on unit testing, code quality.

Capgemini wants to bring software developer principles to CRM but what does this mean?

Capgemini CRM projects are big enterprise integration projects where code quality is important when creating lots of code, which means you will be maintaining lots of code.

Enterprise projects are long projects, technical debt must be kept low and members of the development team adhere to high standards (high standards are a habit)  Here are some of the methods we use to keep quality high

  • CRM DevOps help developers do their jobs
  • Automated deployments/CI environment
  • Solution packager can import data
  • Solution packager splits up customisations to XML file and stored in source control
  • Code check ins to master have to be reviewed and accepted by senior developers
  • Static analysis on code
  • Static analysis errors and warnings must be removed
  • Capgemini hire good Dynamics developers and make them better (join us here)
  • Minimum 90 percent unit test coverage on Business logic code
  • The Quality code message comes from the top
  • The standards implemented on a Capgemini Dynamics project are higher than developers implemented

Regrets I have a few

After working on a project with automated deployments I think this should be a priority for all Dynamics projects to setup on a project, it offers so many benefits which I discuss in the post below

CRM 2016 – Release management, Solution packager and why you should automate your deployment

I wish I had pushed for higher quality on Dynamics projects I had worked on earlier in my career because if you are not writing high quality code you are adding to the technical debt of a project.  I have seen many Dynamics CRM projects start adding technical debt straight from the first line of code because they used poor standards and practices, these projects get harder and harder

It’s great to work on a Dynamics CRM project using software principles.

Capgemini aim to take good CRM developers and make them better by delivering hard projects with well crafted solutions

You can join the Hosk at Capgemini by applying here

CRM 2013 – Javascript null setting oddity

I had an odd error where I was trying to null a lookup field in Javascript in CRM 2013 Service SP1.

When the user changed a lookup field, I wanted to blank out a few fields to make them select those fields again.  The fields being nulled were dependant on selection of the first lookup field and the options and values they could pick changed.

It’s good practise to reduce the number of choices users have by filtering out values in option sets and lookups, hiding/showing fields.  This makes the forms more cohesive, less noise for the end users.  Read more about CRM Form design in the article below

Good CRM design should not make users think

The initial code was in a function and looked like this

        if (Xrm.Page.getAttribute("field1").getValue() != null) {
            Xrm.Page.getAttribute("field1").setValue(null);
        }


        if (Xrm.Page.getAttribute("field2").getValue() != null) {
            Xrm.Page.getAttribute("field2").setValue(null);
        }
        

Oddly field1 was correctly set to null but field2 refused to be set to null.

To add to the annoyance of not setting the field to null, the not nulling triggered the OnChange event for the lookup which set other values on the previous not nullable value!!!

This made me angry

Stepping through

When bug fixing the goal is understand exactly what is happening, once you understand what is happening it might be possible to work out why or work around it.  There is a big difference between

  • Knowing what is happening
  • Your assumptions about what is happening

Assumptions are dangerous because they can easily be wrong.  When bug fixing don’t assume anything and prove everything.  I have wasted plenty of time with assumptions and investigating the wrong section of code.

I started debugging and stepped through the setting the values to null.  The handy part of debugging JavaScript is the console allows you to integrate the values.

The values on the GUI looked like fields1 and fields2 were both not being set to null.

I debugged and stepped through the code, field2 wasn’t being set to null but the OnChange event was running for field2 which was setting field1 and field2 to the values based on the previous field2 value.

One change at a time

One of the golden rules when debugging a problem is to change one thing at a time, monitor the effects of the change.  This rule is particularly inportant if the change is a configuration change which will be changed on multiple environments (DEV, TEST, PREPROD, PROD).

When changing values or code, making a solitary change will show you the effects of the one change.  If you change 5 things at once which resolves the problem, you don’t know what change has fixed the problem.  In the multiple change scenario you would either need to go back and change one variable at a time or make all the changes in all the environments.

When making changes to code/config it’s good practise to minimise the changes, which minimises the potential unknown effects of these changes and reduces bugs coming from these changes less likely.

I tried

  • removing field1 change
  • swapping the order, changing field2 before field1
  • double checking javascript
  • Asking fellow CRM developers

Asking fellow CRM developers did bring a few mumbles of maybe having seen something like it before but no one could remember what is was or what they did (if only they wrote a blog post about it!!)

None of the other changes did much.

To the Internet

 

Searching the internet didn’t bring up anything directly relevant (how often does that happen!), it did lead me to this page

Javascript, onChange events no longer work on an empty field

This wasn’t the problem I was experiencing

I just noticed that if you have a form field that triggers a Javascript function on the onChange event it no longer triggers the function if you clear the field, but ONLY when you change the field data. For instance; if you have a Name field populated with a name, and you remove the name – the function isn’t triggered. It’s left empty. You have to change the text inside the field.

 

The problem being talked about here is setting required fields to null didn’t trigger the onchange.  I had this reverse of this problem I was setting field2 to null, it wasn’t setting but triggering the OnChange, which means Microsoft fixed the problem report (the forum posts were Feb 2014).

The forum post go me thinking, lets change the field requirements and see what happens.

Setting field requirements using Javascript

Fields have three levels of requirements

  • none
  • required
  • recommended

For some reason accessing these programmatically seems quite different from setting/adjusting them using the GUI.  Looking at the list what is the point of recommended, it should be required or none.  Why you would want to change a field to have a requirement level of recommend?

The code is string based, which seems a little odd and prone to syntax errors.  To find all the Javascript methods use this page on the CRM SDK

Xrm.Page.data.entity attribute (client-side reference)

Here is an example using the trusty field2

  • Xrm.Page.data.entity.attributes.get(“field2”).setRequiredLevel(“none”);
  • Xrm.Page.data.entity.attributes.get(“field2”).setRequiredLevel(“required”);
  • Xrm.Page.data.entity.attributes.get(“field2”).setRequiredLevel(“recommended”);

I changed my code to set the required level to none, set field2 to null and then reset the required level to required.

//I had to set required level to none because assign null wasn't working, might be fixed in future roll ups
	if (Xrm.Page.getAttribute("field1").getValue() != null) {
            Xrm.Page.getAttribute("field1").setValue(null);
        }

        Xrm.Page.data.entity.attributes.get("field2").setRequiredLevel("none");
        if (Xrm.Page.getAttribute("field2").getValue() != null) {
            Xrm.Page.getAttribute("field2").setValue(null);
        }
        Xrm.Page.data.entity.attributes.get("field2").setRequiredLevel("required");

Leave a comment

If you have written some unusual code as a work round for a limitation in design or a known bug, it’s good practise to leave a comment explaining to other developers (and maybe your future self) why you have put the code.

Reasons why you should comment unusual code

  • A developer could easily delete the code without realising what is meant to do
  • It could be confusing for other developers to read and understand
  • A rollup/service patch might fix the code and it could be safely removed
  • The developer reading the code might know the solution to this problem
  • It’s good practise

Are your CRM plugins creating technical debt?

The image above is from the article DEALING WITH TECHNICAL DEBT, which I recommend you read, right after reading this one 🙂

The common method of creating plugins in the CRM projects I have worked on, is putting all/most of the code directly in the plugin class, this creates code which is

  • Complex code
  • Hard to read
  • No code reuse
  • Difficult to debug
  • Writing unit tests is hard so most CRM developers don’t bother

This method of developing plugins creates technical debt to the CRM project instantly and pushes the code towards legacy status and creates spaghetti code

The motivation for writing this blog post is a most CRM projects don’t have enough classes\abstractions in them and the code written is not adhering to good object orientated design principles.

The lack of design and structure in CRM plugins I believe is one of major reasons there is little code reuse in projects and between projects.

I have experienced CRM projects where multiple developers have independently written the same code, not only creating duplicate code (and more code to maintain) but each developer had to spend time writing the code.

CRM developers seem to have an aversion to creating classes and finding abstractions in their code.  A common occurrence in CRM code is the creation of the Plugin Monster method

The plugin monster method is a CRM plugin which has all of the logic, which can be many lines of code.

Technical Debt

Creating CRM plugins without using classes creates a project with lots of technical debt.  The amount of technical debt is increased with the creation of every new plugin.

Creating plugins with classes or using OO principles will lead to CRM project code reaching a legacy level almost before the project is released to the customer.

This type of coding doesn’t adhere to the S.O.L.I.D principles.  This article gives a quick summary of the S.O.L.I.D principles

Most developers (hopefully) have heard of  S.O.L.I.D. principles and the principles of Object Orientated Design.  The best place to start is with Uncle Bob’s Principles of OOD

Below is the Uncle Bob’s list of the S.O.L.I.D. principles with links to his articles on the subject.  The first five principles are focused on class design

SRP The Single Responsibility Principle A class should have one, and only one, reason to change.
OCP The Open Closed Principle You should be able to extend a classes behavior, without modifying it.
LSP The Liskov Substitution Principle Derived classes must be substitutable for their base classes.
ISP The Interface Segregation Principle Make fine grained interfaces that are client specific.
DIP The Dependency Inversion Principle Depend on abstractions, not on concretions.

Many developers have heard of the SOLID principles, fewer developers understand the principles and even fewer put them into practice when creating their plugin/custom workflow code.

You might think CRM development doesn’t need to implement OO principles because plugins are small focused pieces of code.  This view is has resulted in plugin code consiting of poorly written, complex code and explains the lack of reusable code generated by CRM projects.

Code being re-used in CRM projects is seen as often as big foot – Hosk

Common attributes of CRM projects (in my experience)

  • The number of classes is minimal in CRM projects
  • Classes and methods doing more than one thing
  • Most projects have no unit testing and the code would be hard to test due to complexity
  • The S.O.L.I.D principles rarely  implemented
  • Almost no code reuse, even in the same project between plugins

Projects with the characteristics above have little/no code reuse and contain an abundance of technical debt which makes supporting them difficult.  All interaction with the code will take longer and longer.

Code Interaction is

  • reading/understanding
  • debugging
  • extending

Why does poor plugin code get created

I have seen many many many plugins written where all the code is included in the plugin.  This blog is about poor class design but putting all the code in a plugin is not even designing a class.

Putting the code in the plugin and creating one big method is poor coding and results in

confusing complex code which is hard to understand
Very hard to unit test a plugin
zero code reuse

Complex plugin code with poorly designed code leads to these problems

  • debugging is difficult and takes longer
  • bug fixing is difficult and takes longer
  • No unit tests means refactoring is difficult and often avoided

The bottom line is the project which becomes a legacy project and developers try to interact, change and extend the code as little as possible.

Explanations for poor plugin code

Below I will discuss the reasons why I believe poor code gets created most of the poor code could be avoided with code reviews.

Junior developers

Some plugin code is written by junior developers who didn’t apply the principles for designing and structuring classes and methods.   The blame should not be placed on the junior developer, the reason why this code is still in the project is because their is lack of code reviews in CRM development.   A code review would have picked up the poor code and the code would have been rewritten with some guiding advice on the areas to improve.

Poorly skilled developers

There are some developers who don’t enjoy being a developer and they have no passion for developer or pride in what they create.

If you don’t enjoy doing something you are not likely to devote much time improving your skills (despite it being their main source income)

They are different from junior developers because often these developers are quite experienced (in terms of years of development experience).

Developers who have not heard/read about OO Principles

Some developers believe if you write code and it does what is required then that’s all that matters.

Many developers believe designing the code to OO principles, creating classes and methods are not needed and don’t.

This will create the code which delivers the functionality but any further interaction with the code is difficult.

Contractors

The quality of CRM Developers contractors is about 60 percent good, 40 percent bad.  I don’t blame the individual contractors because they work to the agreed and existing levels.  If unit tests are not part of the development process then they don’t get written.

I believe all code should be code reviewed but it’s definitely important to review contractors code because you don’t know the quality of their code.  The knowledge a developers code will be reviewed will increase the quality and tidyness before any changes have been found in the code review.

Poor code survives due to the lack of code reviews and lack of Unit tests/code reviews (which often tasks removed when projects deadlines are tight).  Read my blog post Why rushed projects/code doesn’t save time and reduces quality

The benefit of well designed classes offers long terms benefits when interacting with the code.  The long term benefits won’t benefit the contractor who is usually not working on the project after the release.

No Unit Tests

No unit tests leads to the attitude of “if it ain’t broke don’t fix it”.  This is understandable when it’s difficult to test if code changes have broken anything.

When unit tests are written developers can change the code and test their code changes haven’t broken anything.

read more

Easier

It easier to create poorly written code in one or two big methods than it is to create small classes/functions.  Most CRM developers get the code working and then if there is time, tidy up the code.

Quicker

It’s quicker to create code in one big method, the developer has nothing to think about apart from creating the code.

This method of writing code creates technical debt and fragile code.  The debt of the code will start to eat away developers time whenever they need to understand the code, maintain or extend.

Understanding bad code is is like trying to find things in a messy teenagers bedroom, stuff everywhere and in an order only known to the owner of the room.

Changing bad code is like playing Jenga, changing one bit of code could bring down the whole tower

Consistency

If all the plugins in a project are poorly written there can be some pressure on the developer to create the plugin in the same way and some CRM developers can question the adding of lots of new classes!

It doesn’t make sense to create code which is badly structured, it’s hard to understand and it can’t be tested.  Simple plugins can create code with one or two longs methods with multiple nested if statements and end up confusing.

The fact no code can be reused seems plain crazy, particularly when you consider a lot ofthe code is written using core CRM entities which exist in most CRM projects,

Look at your own plugin code

look at the code you have written recently, how well structured is the code, how reusable is it is

Look in your current CRM projects, how many classes are there

  • How many classes?
  • How long are your methods?
  • Could the code be split up into smaller classes
  • What is the average size of the classes and methods
  • Are the classes well named? (badly named classes/methods hides code doing many thing not a single thing.
  • Are the CRM queries in separate classes or mixed with other code?
  • How reusable is the code?

 How Fragile is your code?

A great way to test the fragility of your code is to ask yourself a question

  • What happens if the business logic is changed
  • What happens if the a new type is added
  • What happens if I have to change this plugin

If your code is fragile changing one part of the code could break other parts of the code.  If your plugin code is contained in one or two large methods then the code dependency is high, changing one or two lines could break the whole method.

Fragile code is where a change to one part of the code breaks seemingly unrelated parts of the code.

Is your code designed to minimise the effects of change, e.g. low coupling with independent/modular code.

Look at your plugin code, imagine its going to change and answer these questions

  • Is the code easy to change?
  • Could I add another type/business logic?
  • Can I test the code will work after making the change?
  • What is dependent on this code?

It’s an interesting exercise predicting the effects of change on your code and it will provide a warning for areas of code.  You need to factor in the likehood of changes in that area of code.  It’s interesting to do this after the code has been written but very useful to do when you are designing and creating the code the first time.  Which is where the OO design principle came from

Encapsulate What Varies

Here are a couple of interesting articles on the Encapsulate what varies

Find What Is Varying and Encapsulate It

Encapsulate What Varies

Steve Row – Encapsulate What Varies

finally this article on Object Orientated Principles is great

Finally

I shall leave you with these thoughts

Code should be high quality and low in quantity.

No copying and pasting, no duplication.

less code, less places for bugs to hide

CRM Developer Centre gets updated and it looks good

CRM developer centre I noticed the CRM Developer website has been spruced up I thought I would write a quick blog about this because I think new CRM developers should definitely head towards the new site.  The change isn’t huge it is a good move for CRM Developers who are just starting out in CRM development.

What is the CRM SDK?

There is the actual CRM SDK, which you download Microsoft Dynamics CRM Software Development Kit (SDK) for CRM Online and on-premises CRM 2015 This gives you a bunch folders and files with sample code and the all important CRM dll’s and maybe a link to the CRM developer toolkit as long as you haven’t downloaded CRM 2015 (Where is the CRM Developer toolkit for CRM 2015?) CRM SDK download When I talk about the CRM SDK, I am talking about the documentation.  In the download it’s the CrmSdk2015.chm but I use the online documentation because it’s easier to search. Software Development Kit for Microsoft Dynamics CRM The CRM SDK documentation is awesome but I distinctly remember finding it difficult to use when I was learning CRM development.

Why is the CRM SDK hard to start developing with?

The CRM SDK is a huge and when a CRM developer first starts looking at it can be overwhelmed by the amount of information. When a CRM developer first opens the CRM SDK documentation it’s like walking into the British Library (largest library in the world) looking for a book to get started with programming.

The CRM SDK is a fantastic document and the content is some of the best documentation I have read for product/toolkit but in this strength lies it’s weakness.  The amount of documentation makes it very difficult to order and organise so CRM Developers can find the information they are looking for. Many times I have found useful information

  • tucked away in a section I didn’t know existed
  • A section I  have never read before
  • Wasn’t an obvious place to look.

CRM SDK documentation = CRM Developers bible

I view the CRM SDK documentation as the core documentation for CRM developers, it’s vital CRM developers know how awesome it is, how to use it effectively to clarify how CRM works when they are not sure.

Always start with the CRM SDK

The CRM SDK works brilliantly if you are searching for specific parts of the CRM SDK like OrganizationService, plugin variables. The CRM SDK documentation works well for new releases CRM 2015 SDK – Why you should read the What’s new for developers What’s new in CRM 2015 SP1 for developers, customizers and admins The CRM SDK has lots of example code and offers a good way to learn different CRM customizations.

The biggest benefit of the CRM SDK documentation is it’s written by the creators of the CRM SDK and accurately details how the code works instead of how a CRM developer believes the code works. Most times I read the CRM SDK I learn something new.

The downsides of the CRM SDK documentation is it can read like a manual/reference book, this style is excellent for CRM developers who have some experience but can be confusing for new CRM Developers.  There is a lack of screenshots which can be a barrier to understanding new concepts and examples.

Why the CRM DEVELOPER Centre update is good

Once again the Hosk has gone widely off track, the CRM developer centre has been updated and I think it’s a good thing because

  • It’s a front end to the CRM SDK
  • It’s modern and sexy looking
  • It’s built so it can be consumed on mobile devices
  • The search brings back CRM content not all MSDN

The headings give a quick path to relevant sections of the CRM SDK.  It would be great if Microsoft could invest more time trying to visualise the CRM SDK which would encourage more developers to dip in the CRM SDK. The CRM SDK documentation is massive so it’s difficult to dice, slice and display the information in ways to make it easier to find the information you want but Microsoft have already created the information and the challenge is ease accessibility of it.

Hosk CRM DEV Tip – Always filter your queries

Is important to keep good habits and keep your CRM solutions zipping along and in most CRM projects there will lots of queries retrieving records related to the main record.

CRM queries should like Bruce Lee one inch punch.  Mean and Lean with no wasted actions

The one inch punch is so awesome it has it’s own wiki page

The one-inch punch is a punching exercise from Chinese martial arts (kung fu) performed at a range of 0–15 cm (0–6 in). The one-inch punch was popularised by actor and martial artist Bruce Lee. It is designed to improve punching power and technique.

Your CRM code should be as simple as possible 

CRM code and CRM queries should be as simple as possible but not simpler

Last year I was doing some optimization and one of the main culprits of poor performance was due to queries not filtering and returning all rows.  There were examples of no filtering in OData in Javascript and plugins.  You can read more about my investigation into CRM performance here

What to look for

  • new ColumnSet(true))
  • Odata queries with no “filter=”

what are the consequences of not filtering your queries, apart from being on Hosk’s naughty list

Poor performance

The downside of not filtering your queries is you are returning fields you don’t need, this will cause the query to take longer to run and bring down more data for every row returned in your query.

The bottom line is your queries are going to take longer and the more rows you return the worse the performance.

Updating all fields which can trigger more actions

When a query has selected all the fields for an entity another mistake the CRM developer can make is to update the record which updates all the fields in the record.  This can

  • Creating confusing audit trails with fields being updated but not changed
  • trigger workflows and other plugins

I have had some conversations with customers asking why the audit record was saying a field had been updated but no one had changed the field.

The triggering of other plugins/workflows can not only have contribute to poor performance but also trigger new records and values being changed.

Code review shaming

Peer reviews are a great way of stopping poor code like this entering your code.  If the CRM Developer knows the code is going to be code reviewed they are less likely to take shortcuts, write poor code because they know it will be found in a code review.

If a CRM developer does write queries without filters then the code reviewer knows they need to be watched because they are a lazy coder.

Lazy coding

In my blog code Bad code is like a virus, don’t get infected I mention the broken code theory.

If the no poor code had been checked in, the CRM developer would see the code checked in is a high standard, the developer understands the code in this project should be a high standard and will follow the herd checking in high-quality code

If the code repository has been infected with bad code the CRM developer will see it’s OK to check in poor quality code, the easiest action for the CRM developer to take is the quick and easy fix, which is of lower quality and will cost you more time in the long run and make it harder to change the code in the future.

I believe you need to keep the coding standards of a project as high as you can and ensure CRM developers adhere to best practise.  Once bad code gets into source control then you will soon find it starts to grow as other CRM developers check in similar quality code.

Finally

There is no excuse to not filter your queries so don’t do it.

 

Why all developers should be friends with a cardboard developer

I read an article  about a development team who used a cardboard developer.  The team had acquired a life-size cardboard person who they welcomed into the development team.

If anyone in the team had some code which wasn’t working, before asking another developer to sit with them to look at the problem the person had to first get the cardboard developer, stand him next to them, explain the problem to the cardboard developer, run through the code with him to see if he could help see the problem.
I have also learnt this process is known as Rubber duck debugging from the excellent book
The funny thing about this story is quite often the cardboard developer would help resolve the problem.
How exactly does a cardboard cut out help solve development problems and why aren’t companies deploying armies of them.

Stop! walk through the process step by step

The truth is people can often solve their own problems, once they understand the problem and walk through it.
This is what I would term as
can’t see the wood for the trees
This is a saying which regularly gets said, but I’m not sure everyone understands what it really means
Here is an explanation

Meaning: If you can’t see the wood for the trees, you can’t see the whole situation clearly because you’re looking too closely at small details, or because you’re too closely involved.

In terms of CRM development you can get  absorbed in a problem, the methods you have already tried to resolve it, you can get to a point where the CRM developer stops thinking logically about the problem.  For coding problems in particular you can get too close to the problem you forget to use a systematic process of trying to resolve the problem.

A classic example of the cardboard developer – Grumpy IT person

I’m sure many people have called the IT person in their organisation only to find they have given him the role of cardboard cut out.  You calmly explain the problem to the IT person (who is usually grumpy grumpily) to come and try and solve your problem.

When the IT person comes to your desk you go through the steps and it works perfectly and the IT person grunts and goes back to his warm nest away from troublesome users.

Many times I have asked someone to look at a problem and then as I was explaining it to them I instantly knew the answer.  It’s a similar sensation to not hearing someone, saying pardon and then your brain belated tells you what they said.

Why does the Cardboard developer work?

The reason the cardboard developer or any inanimate object works (it helps if it resembles a person or you feel stupid explaining your problem to an apple) is when you explain the problem to someone/something you

  • You have stepped back from the problem, you have stopped to think
  • Go through step by step
  • Explain what you want to happen
  • Explain what is happening
Developers often have to do the same/similar tasks many times they often
  • Engage autopilot
  • Stop thinking and just do
  • Miss steps/Take shortcuts
  • rush

Why should you use the Cardboard developer?

The main reason you should try using the cardboard developer is so you stop wasting other developers time when you could resolve the problem yourself.

Developers need to concentrate for a prolonged uninterrupted section of time (hours) to create a coding solution, this process involves concentrating on a problem with lots of trial and error.  Breaking this concentration for a developer to come and stand by you whilst you resolve the problem yourself can be frustrating for the developer who you have walked round the office and embarrassing for yourself for wasting the developers time.

To avoid wasting developers time I would advise getting up from your desk, going for a walk at lunch, making a cup of tea.  The act of stepping away from your computer will allow you to look at the problem with fresh eyes.

Make sure you use the Cardboard developer to go through a problem first before asking someone else.  I’m not advocating you sit and suffer with a problem but you should make sure you can’t resolve the problem yourself first.

This blog describes why Developers should not be disturbed

Why programmers work at night

or this graphic shows the process which I got from here

Today I used the Cardboard developer

Everyone has to use the cardboard developer and today I should have used the cardboard developer but instead I brought over Sir Les (senior CRM Developer) over to my desk.

I was creating a new development organisation.  I had imported a number of managed and unmanaged solutions.

The next stage was to import some data, I selected the file, press next a few times but then was puzzled why the entities weren’t in the drop down list?

I couldn’t think of any reason why entities don’t appear in drop down lists for importing?

So I got senior developer over.

The act of having someone looking over your shoulder suddenly gets your brain working with more focus.

Have you guessed the problem yet?????

Yes, suddenly it came to me,  I had imported some unmanaged solutions.  Unmanaged solutions need to be published (managed solutions are published automatically).  To understand the intricacies of solutions read my blog post – Understanding how CRM solutions work

Sir Les of CRM Shire was thanked and sent back to his desk, he helped me resolve the problem without doing anything.

Next time I will try explaining it to the cardboard developer before wasting a real developers time.

Check out the Dando the box man adventures

Here and here