mfp's two cents

...on Dynamics AX Development!
  • mfp's two cents

    Optional parameters in C# and X++

    • 3 Comments

    In the upcoming 4.0 version of C# the language now supports optional parameters – just like X++. The following is a valid method declaration in both languages:

    public void foo(int parameter1, int parameter2 = 0, int parameter3 = 100)
    {
    }

    There are a few differences between the languages with regards to optional parameters:

    Named parameters

    In X++ you can only omit optional parameters starting from the last parameter. C# makes it possible to omit any optional parameter. For example:

    foo(5, parameter3: 1000)

    will call foo(5, 0, 1000).

    prmIsDefault

    C# doesn’t provide a way to determine, if a parameter was omitted by the caller, or the caller passed in a value identical to the default value. In X++ the prmIsDefault() method can be used to determine this. However, the use cases for this method are rare – and often fragile. For example, consider this X++ class:

    class BaseClass
    {
        int value;
        public void init(int _value = 0)
        {
            if (prmIsDefault(value))
            {
                value = /* some complex calculation */
            }
            else
            {
                value = _value;
            }
        }
    }
    Now someone comes along and extends the class:
    class MyClass extends BaseClass
    {
        str myStr;
        public void init(int _value = 0)
        {
            myStr = 'foo';
            super(_value);
        }
    }
    Can you see the problem? This following code will never call the complex calculation (which probably was the intention):
    MyClass myClass = new MyClass();
    To solve the problem MyClass needs to be implemented as:
    class MyClass extends BaseClass
    {
        str myStr;
        public void init(int _value = 0)
        {
            myStr = 'foo';
            if (prmIsDefault(_value))
                super();
            else
                super(_value);
        }
    }

    Which really is terrible, as the implementation of the derived class depends on the implementation of the base class. This is bound to break eventually. Add a few more optional parameters and a few more levels of depth in the class hierarchy, and you'll have a real nightmare. My recommendation is to only use prmIsDefault() in private and final methods - as they can't be overridden. In C# you can easy live without this method, as you can achieve the same in a more robust manner using method overloading:

    class BaseClass
    {
        int value;
        public void init()
        {
            int _value = /* some complex calculation */
            this.init(_value);
        }
        public void init(int _value)
        {
            value = _value;
        }
    }
    <humor>It is a good thing we solved the dangling semicolon issue – otherwise it would haunt the C# community in a not too distant future.</humor>
  • mfp's two cents

    Review of: Microsoft Dynamics AX 2009 Programming: Getting Started

    • 0 Comments

    This is an excellent book for getting started with AX. The book’s language is straight forward and simple, so you don’t need a computer science education to reap the gold nuggets buried inside.

    The first half of the book is a case study of a step-by-step implementation of a car rental application. This is a great idea, as these steps take you through many areas of AX development, and on the way introduces you to most of the building blocks of X++. The approach used is to jump straight into the action, without spending many words on background information, which quite impressively doesn’t make the material harder to grasp, but rather makes the book a pleasant and easy read. The book is full of source code examples and screenshots, which will make it easy for you to follow the same steps in your own AX installation.

    The second half of the book is a collection of standalone chapters. I particularly liked the chapter on integration with various AX modules. This chapter provides a 10,000 feet overview of the main modules in AX, such as GL, AR, AP and Inventory. Further it provides code samples on how common customizations can be implemented.

    There are two kinds of books. Those that struggle to reach the final page count by cutting the original manuscript, and those that struggle to produce enough pages to justify calling it a book. (Something similar is true for sauces). This book is of the latter kind, which is a shame. Important information even for beginners is missing in critical places; whereas plenty of pages are spent on low value information. For example, the book contains a 10 page source dump of an data export/import feature the author has implemented – not because the one already in AX isn’t good enough, but simply because he could.

    The vital information that is missing is the primary reason I cannot give this book 5 stars. Here are some examples: In the same chapter the book explains the benefits (speed) of using set-based data base operations, and the powers of overriding table trigger methods like insert() and update() – but the book forgets to mention that overriding such a method will reduce all set-based operations to row-by-row operations on the AOS (incredibly slow in comparison). This cause and effect is one of the typical reasons AX customers are having performance problems. Similarly the book explains the concurrency model of AX4 (pessimistic) and not the concurrency model of AX2009 (optimistic). Another important topic not covered is how to develop a 3 tier application – without such information it is hard to write an application that scales beyond a few users.

    It is clear that the author has worked with AX for a long time. Some of the information provided is outdated in AX2009. For example, the chapter on how to create a web service in AX explains all the hassle you had to go through in AX4, instead of explaining how simple the same could be achieved in AX2009 using the Services node in the AOT. The same is true for the BC.Net examples that use the AX4 way of talking to AX, instead of using the automatically generated proxies available in AX2009, which are much simpler to use – and much more reliable.

    Finally, the technical accuracy of the book is high – it rarely state something that is wrong, but often omits what I believe is critical information. So kudos to the author. However; the editors of the book didn’t do a very good job. The book is full of typos, double words, poorly phrased sentences and what appears to be copy-paste errors. And I do mean full – I spotted one on almost every other page. It is clear that no one took the time to read the book end-2-end before printing it. For example, the appendix with useful web links has half of the URLs wrong – they are duplicates from the previous page and don’t match the description at all.

    I’m giving this book a 4 out of 5 star rating, because it does deliver what it promises: A quick start on developing in AX without providing too much background information.

    The book is written by Erlend Dalen and published by Packt Publishing.

  • mfp's two cents

    Microsoft Dynamics AX 2009 Programming: Getting Started

    • 0 Comments

    A new book on Microsoft Dynamics AX 2009 development has recently been published by Packt Publishing. The book is aimed at developers new to Dynamics AX, and offers what I believe is both a detailed and pragmatic approach by focusing on the most important aspect and providing tons of in-depth step-by-step examples. Naturally, you can debate what areas are the most important, which in this case was decided by the book's author Erlend Dalen. By looking at the book's table of content, I believe he did an excellent job. Once I receive my copy of the book I'll post a more detailed review.

    From the publisher's description:

    What you will learn from this book

    • Get to grips with the AX Development environment
    • Understand the basics of the  X++ language
    • Reduce the time spent on coding by storing and relating data
    • Create Reporting Services reports in Visual Studio using the new Reporting Service extensions
    • Optimize data retrieval to ensure each transfer contains only the data necessary for the further operations
    • Manipulate data in X++
    • Effectively handle transaction scope by using different operators
    • Develop a .Net class in Visual Studio and then use it in AX
    • Build rich web portals with Enterprise Portal and ASP.NET
    • Optimize application performance and extensibility
    • Create services and expose them to external applications
    • Build a new module in AX

    If you want a free sample of one of the book's chapters, you can download the chapter "Searching for Data".

  • mfp's two cents

    New X++ Editor

    • 1 Comments

    Vincent Nicola from our VS Tools team has posted a blog on the new X++ editor coming in AX6. This certainly is an interesting time to be an AX developer.

    http://blogs.msdn.com/vnicolas/archive/2009/10/11/dynamics-ax6-the-new-x-editor.aspx

Page 1 of 1 (4 items)

January, 2010

mfp's two cents

...on Dynamics AX Development!