Code annotations in AL – Please, don’t!

One of good practices of writing C/AL Code for Microsoft Dynamics NAV since the dawn of civilization was annotating (commenting) code changes. If you are not sure what I mean by that, this is what I am talking about:

While standards varied about > vs +, or < vs -, or what the annotations should include, there was absolute consensus that annotating changes is an absolute must.

And it was a must. It was such an important rule that everyone followed it without questions asked. In my career, I’ve seen one or two situations of somebody changing or deleting a line of code without leaving any comment, and I’ve seen quite a lot of code, believe you me. It was that important.

It was that important in fact that it was one of the first things developers learned when they signed up for the job, and it was one of the rules they all followed from their first day.

Continue reading Code annotations in AL – Please, don’t!

Control Add-ins Supercharged: Debugging with source maps

So far I’ve shown how to configure gulp to help you with some basic JavaScript development tasks, such as bundling and minifying, and how to automate builds on every source file change. Let’s now take it to an entirely new level: debugging.

If you ever tried to debug your control add-in source code using Visual Studio Code, you might have realized two things: first, that it’s actually pretty simple to do; and second, that it’s not the kind of debugging that you want.

Let’s see why that is.

First, using VS Code with a browser such as Chrome, Edge (especially “Canary”, mmmm) or Firefox is easy. There are debugging extensions built for that purpose that allow you to either launch a browser with VS Code attached as a debugger, or to attach VS Code to a running instance of a browser (some browser configuration needed beforehand). However, when you use VS Code as a debugger like this, it’s hardly more than a glorified browser built-in developer tool – the only benefit of using VS Code is that, well, you are in VS Code, rather than inside the browser. However, you are not really debugging your source files – you are debugging scripts currently loaded in the browser. You can’t set debug breakpoints in your source files – you can only set them in copies of files that are loaded by the browser. If you catch a bug (kind of a point with a debugger) you can’t stop the process and immediately change the line where the bug is, but you have to first locate the matching source script, and then the offending line, and then fix it there. Not exactly a fun pastime.

And that’s annoying enough if you have a single script to work with, but if you have several scripts, bundled together, then minified, well, good luck with that. Debugging minified code is as close as you can get to inquisition-level torture in this century.

So, let’s fix this mess, and let’s enable debugging as it should be – let’s enable debugging of actual source files with full breakpoint integration and all.

That’s what my next branch is about. In it, I introduce source maps and how you can use gulp to build them. And then I explain how you can configure your VS Code to debug your source files.

So, head over to https://github.com/vjekob/supercharged_01/tree/06-gulp-debug and check out some pretty cool stuff.

Control Add-ins Supercharged: Automating gulp.watch

Yesterday you’ve seen how to use gulp to make it do something truly useful: bundling your JavaScript and CSS files. Introducing gulp for the purpose of bundling your files allows you to split your functionality into as many files as you want, but use only a single script and a single stylesheet file from your control add-in. That way you not only optimized how your browser loads the files, but you also eliminated the need to maintain your controladdin object file every single time a new JavaScript or CSS file is added (or an existing one is removed).

However, you still need to run gulp build every single time you want to build your bundles. If you forget that, your controladdin will not be updated with your changes.

Thankfully, gulp has an answer to this: the gulp.watch feature. That’s the topic of my next demo, that I’ve explained in the 05-gulp-watch branch of my supercharged-01 repository.

The Readme.md file of that branch explains how to configure the watch task in the gulpfile.js file, and how to configure VS Code to automatically run the watch task every time you open the workspace. Once you follow those instructions, you can work on individual JavaScript or CSS files without the need to run gulp build or to maintain your controladdin object file. The former is taken care of by gulp, and the latter is taken care by… well, gulp too. Gulp is cool, really 😎

Control Add-ins Supercharged: Teaching gulp some useful tricks

My last demo introduces gulp, an amazingly simple task automation tool. You’ve seen what it is, how to set it up, and how to create a simple hello-world task. Now it’s time to teach gulp some useful tricks and make it automate the “build” process for the JavaScript and CSS files.

The first demo in this series uses a single-file approach, and there I stated that it’s a bad thing to develop like that. It’s bad to put all the functionality in one single file. However, that rule applies for development, not for runtime. Your browser actually prefers using a smaller number of JavaScript (or CSS) files. That’s why typical runtime JavaScript libraries are bundled. On top of bundling, you’ll also want to minify your JavaScript and CSS files to make them as small as possible, to further improve the download and initialization speed.

These are the things that today’s demo uses. So, head over to the https://github.com/vjekob/supercharged_01/tree/04-gulp-useful branch, and check out how to configure your gulp to build your JavaScript and CSS bundles from your source files.

Control Add-ins Supercharged: Hello, gulp!

Get ready for the next big step in taking the control add-in development to the next level. Today, I am (re)introducing gulp.

I’ve blogged about gulp in the past, but I’ve never really finished that series. Life and work got in the way. But while I may not have blogged about it much, it’s been my companion for quite some time now, and now I want it to become yours, too.

In previous “Control Add-ins Supercharged” examples we’ve mostly explored how not to do things. Now we are ready to take a look in the opposite direction and start talking about how to do do things.

For this example, I’ll use my next demo branch 04-gulp-hello-world that you can check out here: https://github.com/vjekob/supercharged_01/tree/03-gulp-hello-world.

I don’t intend to copy/paste all the theory explained in the branch’s Readme file, but I’ll just say what you can find there:

  • Steps to install the prerequisites to run gulp
  • Steps to install gulp and make sure it works
  • Examples how to run gulp tasks from both command line and VS Code
  • Just a tiny little bit of theory around Node.js packages
  • A few good practices around some Node.js artifacts that will appear in your workspace once you install gulp

And with this small example that introduces gulp I conclude the introduction into the “Control Add-ins Supercharged” series. All the next steps will deliver ready-to-use stuff that you can plug into your own control add-in development process, and we’ll start building our toolchain step by step.

Have a great weekend!