Christian Heilmann

You are currently browsing the Christian Heilmann blog archives for December, 2022.

Archive for December, 2022

Code brushes for GitHub Copilot

Tuesday, December 13th, 2022

Github Next now showed a new feature in GitHub Copilot labs that allows you to change code you write to make it cleaner, more robust and document it automatically.

GitHub Copilot is incredible, and if you check what’s happening in the preview released as the Copilot Labs extension it will only get more amazing.

Check this out:

Code brushes applied to a simple JavaScript

Let’s start with a basic JavaScript that checks a string length and reports when it is empty. One with an obvious mistake, as we use a single `=` instead of the type safe `===`. This will always report the string as empty.

if (str.length = 0) {
    console.error('String is empty');
}

Using the `Fix bugs` brush, this is rectified.

if (str.length === 0) {
    console.error('String is empty');
}

Using the `Clean` brush also adds reporting when the string is not empty.

if (str.length === 0) {
    console.error('String is empty');
} else {
    console.log('String is not empty');
}

Using the `List steps` brush adds comments for step (sure, this is redundant, but it also works for much more complex code).

// check the length of the string
if (str.length === 0) {
    // if length is 0, print 'String is empty' 
    console.error('String is empty');
} else {
    // if length is not 0, print 'String is not empty'
    console.log('String is not empty');
}

Using `Make robust` adds error reporting instead of logging and an extra check to make sure that `str` is really a String and not an empty Array.

function test(str) {
    if (str.length === 0) {
        throw new Error('String is empty');
    } else if (typeof str !== 'string') {
        throw new Error('It is not a string');
    } else {
        console.log('String is not empty');
    }
}

The `Add types` brush does exactly that.

/**
 * @param {string} str
 * @returns {string}
 */
function test(str) {
    if (str.length === 0) {
        throw new Error('String is empty');
    } else if (typeof str !== 'string') {
        throw new Error('It is not a string');
    } else {
        console.log('String is not empty');
    }
}

You can also define custom brushes and there are more to come.

Pioneers in Open Source Interview: Browsers, Bootcamps & the Business of Open Source

Friday, December 9th, 2022

I was interviewed by Jay from Moduscreate to talk about my past, how I got into the market, what open source and browser compatibility means for me and many other bits. Amazing to see that we chatted for 1.5 hours and I hope some of it may be inspiring to you.

Watch on YouTube

Opening Node developer tools just got easier

Thursday, December 1st, 2022

Using the command palette in Microsoft Edge, you can open Dedicated Devtools for Node

Microsoft Edge has a command palette which allows you to run commands by typing. You can use this to launch Developer Tools for Node.

  • Press `Ctrl+Q` to open the command palette
  • Type `>`, `node` and press Enter

Using the command palette in Microsoft Edge to open Node developer tools

Alternatively, you can always use the old way to access Node devtools using `edge://inspect` and clicking the link.

The node devtools links in the inspect page

If you don’t see the command palette

This is being currently rolled out in Edge, so if you don’t see it yet, you need to go to edge://flags and turn it on:

Command Palette Flag