Embrace the extensions mindset with Dynamics 365 for Finance and Operations #2 – SysExtension framework [EN]

In my previous post Embrace the extensions mindset with Dynamics 365 for Finance and Operations we reflected on some of the patterns we can leverage to create our customizations by using only non-intrusive changes based on a real example: Adding a new Number Sequence to a standard module.

In particular, we discussed:

  • Metadata Extensions — to add a new Enum Value in a standard Base Enum.
  • Class Extensions — to add a new method to a standard class.
  • Chain-of-Command — to add a block of code to an existing standard class method.
  • Event-Handler subscription — to subscribe our own method to an existing standard delegate provided as an extension point.

If you still didn’t read that blog post, please take a moment now. If you already did it (thanks!), let’s continue with another pattern we have to consider: SysExtension Framework (also SysPlugin, that is quite similar).

This pattern allows us to create new sub-classes for factory methods without any over-layering or coupling with the original hierarchy. Therefore, we can add new sub-classes in our own packages without any intrusive modifications and replace a very common pattern, widely used all over the application, like this (taken from AX 2012 R3):

static SalesCopying construct(SalesPurchCopy salesPurchCopy)
{
    <strong>switch(salesPurchCopy)</strong>
    {
        case SalesPurchCopy::CreditNoteHeader       : return new SalesCopying_CreditNote();
        case SalesPurchCopy::CreditNoteLines        : return SalesCopyingCreditNoteLine::construct();

        case SalesPurchCopy::CopyAllHeader          :
        case SalesPurchCopy::CopyAllLines           :
        case SalesPurchCopy::CopyJournalHeader      :
        case SalesPurchCopy::CopyJournalLines       : return new SalesCopying();

        //
        case SalesPurchCopy::VoidFiscalDocument_BR  : return new SalesCopying_VoidFiscalDocument_BR();
        //

        default                                     : <strong>throw error</strong>(strFmt("@SYS19306",funcName()));
    }

    <strong>throw error</strong>(strFmt("@SYS19306",funcName()));
}

This pattern has many of problems to be extensible. The most obvious is likely the throw error on the default case, that makes impossible to an extension class to subscribe to the Post event on the method to add new cases. But even deleting this throw sentence (that has been indeed deleted in many standard methods as a quick way to make them extensible), the pattern itself is still a problem. If a new customer or partner customization or even a new standard module needs a new case, this class needs to be modified and the full package compiled and deployed.

 

Read the full article at “Dynamics AX in the Field”, the blog from the Premier Field Engineering team at Microsoft.

 

Libro: Clean Code

Hace mucho que no comento libros. Lo más curioso es que el libro que os traigo hoy siempre fue, en mi cabeza, el primero que debí haber traído. Esa fue la idea originalmente, pero después decidí omitirlo porque, aplicado al desarrollo de puro X++ no tenia tanto sentido. Lo tenía, de hecho, pero sólo podía apreciarse después de leerse el libro, así que era un mal aliciente para fomentar su lectura.

“You are reading this book for two reasons. First, you are a programmer. Second, you want to be a better programmer. Good. We need better programmers.”

Sin embargo me he visto últimamente consultándolo a menudo (y otros que comentaré también) al pensar e investigar sobre Dynamics 365 for Finance and Operations, el nuevo modelo de Extensiones, y el esfuerzo que el equipo de producto está haciendo para hacer el sistema más “extensible“. Os lo resumo: están haciendo el código más limpio, más Clean Code, porque el código limpio es extensible por definición:

Así que me viene al pelo, por fin, hablar de este libro (está traducido como Código Limpio, aunque es más caro que el original en inglés):

La verdad es que es difícil comentar este libro porque prácticamente cualquier desarrollador en cualquier tecnología debería leerlo antes de hacer ninguna otra cosa. Si tienes unas pocas horas de formación al año, leer este libro es probablemente la mejor inversión de ese tiempo, sea cual sea el lenguaje o la plataforma para la que desarrollas, y eso incluye por supuesto Microsoft Dynamics y en particular X++ (y sobre todo en la nueva versión).

El libro trata todos los aspectos de la tarea de escribir código de manera profesional (esto es, código que debe ser mantenido, actualizado, ampliado y rentable), como el propio Martin (también conocido como Uncle Bob) escribe:

“One difference between a smart programmer and a professional programmer is that the professional understands that clarity is king. Professionals use their powers for good and write code that others can understand.

Sobre todo la primera parte cubre todos los niveles de la tarea de escribir código que sea fácil de entender (y por tanto, de mantener). Esto es muy importante porque es la base para que después funcione la técnica de extensiones (que hemos heredado de C#):

“Functions should do one thing. They should do it well. They should do it only.”

Incluye todos los aspectos del código, incluyendo los comentarios:

“Redundant comments are just places to collect lies and misinformation.”

Y también los test, acuñando términos como los Clean Tests: F.I.R.S.T (Fast, Independent, Repeatable, Self-Validating, Timely). Durante este recorrido, el texto va profundizando en la forma de pensar que después nos llevara a conceptos más complejos como los patrones de diseño, o los principios del diseño orientado a objetos como S.O.L.I.D.

Si has leído la documentación sobre Extensiones en Dynamics 365 for Finance and Operations, te sonarán al menos dos de esos principios: la O (Open-Clossed Principle) y la L (Liskov Substitution Principle). Tanto si te suenan como si no, pásate por el Dynamics Saturday de Madrid el 19 de Mayo porque hablaremos de ellos y de más cosas interesantes 🙂

También profundizaré sobre estos principios y patrones en los próximos artículos de este blog y el de mi departamento en Microsoft: Dynamics AX in the Field.

Stay tuned!

AX Performance Monitor 101 – Tips and tricks to deal with performance counter files [EN]

Windows Performance Monitor for Dynamics AX

 

In my previous blog post, I explained how to setup Performance Monitor (PerfMon) to proactively capture performance data while cleaning old files to keep disk space under control. This is, let’s say, our ideal scenario, but sometimes setup is not that specific and we need to deal with suboptimal files that contains the performance data we need to analyze:

  • We have too many files
  • We have too few files
  • We have some huge file that makes analysis or processing it too slow
  • We have files captured in different languages

Let’s have a brief description on how we can deal with some situations by introducing a couple of small but useful tools:

PAL – Performance Analysis of Logs

PAL is a small but really useful tool created by Clint Huffman that takes one perfmon counter file and creates a nice HTML report with graphs and descriptions that can be used as starting point for performance analysis. It’s not that the tool replaces a manual in-deep analysis of any potential problem, but it helps giving some tips that can be used to start looking for something else.

 

Read the full article at “Dynamics AX in the Field”, the blog from the Premier Field Engineering team at Microsoft.

 

AX Performance Monitor 101 – Setup Perfmon for continuous monitoring with rolling files [EN]

Windows Performance Monitor for Dynamics AX

 

Windows Performance Monitor (PerfMon) is likely the most useful tool (together with our DynamicsPerf package) to monitor and diagnose performance problems related with your Microsoft Dynamics AX infrastructure and, in general, for any software running on Windows operating systems. Given its importance, is surprising how many people is not using it properly or, even worst, is not using it at all.

I will briefly explain how to setup PerfMon to collect performance counters in all servers for continuous monitoring, creating log files per day, compressing and deleting old files to minimize disk space, along with some tips and tricks during the process:

Create and configure a Data Collector Set

  • First of all open Performance Monitor either going to Administrative Tools in Windows Control Panel or searching “perfmon” in the Start menu.
  • Navigate to Data Collector Sets > User Defined > Right Click > New > Data Collector Set.
  • Choose “Create from a template” and finish the wizard. Some nice templates for all Dynamics AX server roles can be obtained as part of our DynamicsPerf download, under “DynamicsPerf 2.00\DynamicsPerf\Windows Perfmon Scripts” subfolder or as part of the PAL tool. We will talk about PAL on the next post on this series.

 

Read the full article at “Dynamics AX in the Field”, the blog from the Premier Field Engineering team at Microsoft.