DEV275x – Writing Professional Code

The course DEV275x Writing Professional Code is a very short introduction to best practices when it comes to writing code. As usual, this is only my notes I took during the course, you defiantly should check out the course for yourself at https://courses.edx.org/courses/course-v1:Microsoft+DEV275x+2T2017/course/

Module 1: Elements of Professional Code

Source Control with Git

Source Control is one of the most important aspects of programming.

  • Backup of your Source Code
  • Ability to compare with changes done in the past
  • Restore previous versions if something goes wrong with the new version
  • Easy collaboration with other people

There are many different Software packages that enable Source Control. Currently, the two most popular systems are Git (70% of Programmers) followed by SVN (10% of Programmers) (Survey of 30k Developers)

The core difference between the two is, that for SVN you need to set up a dedicated Source Control Server, and all changes are tracked there. With Git it is distributed, so you can use it locally and if you choose in combination with a server.

Especially Code Editors like Visual Studio Code have Git directly integrated making it really easy to set up and use Git.

Programs:

Cloud Providers

Workflows

Markdown

Markdown is really great because you can learn it really fast, and even if you do not convert Markdown into a HTML site or PDF the text is still formatted quite neatly and readable.

Like Git you find support for Markdown files in common editors like Visual Studio Code / Atom. And of course, in blogging software like WordPress have plugins that enable Markdown for the Posts.

Module 2: Communicate with Code

Now, this chapter was rather interesting, it focused on how those smaller things like code conventions actually help to improve the codebase. While the presenter did not use automated tools to improve the code readability it was nice to see that it is a very important aspect of coding to get the really basic elements correct.

Consistency and Naming

The code should be formatted always in the same matter. It improves the readability and removes all personal style from the code enabling all developers to immediately take ownership of the code instead of saying well that is the style of developer A, he should fix it.

Naming is important and greatly improves the readability of the code it does not help to say var c = 0, it is much better to say var beanCounter= 0. You do not write code for the computer but actually for other human beings. The compiler will then convert it into machine code, but you will probably not have to debug that.

Refactor Duplicate Code

A great problem is when the code base has a lot of duplicate code. As soon as that happens and some minor change changes the way how you do things, then you would have to go back and change all the different places where that piece of code is used.

Refactoring early reduces the risk that the next developer says, well, I will just do that with copy and paste.

Simplify

This one is rather difficult, but by keeping the code and the structures simple and readable has a much higher benefit in the maintainability of the code than some complex structure that executes a micron second faster. Of course, that depends on the program you are writing.

As a rule of thumb, functions should be rather short, not hundreds of lines long. (Too short is also bad.) If you needed to add complexity then you also should document why you are adding it and what is the best approach to understand that complex structure.

Module 3: Code Confidently With Unit Tests

Well writing Unit Tests and overall having Tests for your code, allows you to a) know the use cases of your code and b) allows you to see when you change something what else may have been broken while you were developing a new feature.

Sources:

ImageDesigned by Freepik

package.json: Updating Fixed Versions with npm-check

One of the common problems when running a larger project is that you need to use fixed versions in your package.json file. But at the same time you need to regularly update your packages. The most elegant way is using npm-check. The small tool allows you to select which packages should get an update and update accordingly.

Installation

npm i -g npm-check

Usage

To update the packages in your project you now simply run npm-check -u. If you want to ensure that you are installing the exact package run it with the additional optional flag -E to ensure exact-versions.

npm-check -u -E

With Space you select the packages and with Enter you install the package.

Sources:

ImageDesigned by Freepik

Elementary: Changing the Layout of the Window Controls

While Elementary focuses a lot on UI and is beautiful to use. It is totally mind-boggling that they decided to remove the minimize button.

By changing the value for “gsettings set org.pantheon.desktop.gala.appearance button-layout” you can adjust the button layout to your preference. The value would be in the format of [leftElements] : [ rightElements ]

So the default Elementary setting would be:

gsettings set org.pantheon.desktop.gala.appearance button-layout close:maximize

While the Windows Layout would be

gsettings set org.pantheon.desktop.gala.appearance button-layout :minimize,maximize,close

Sadly the official Elementary Apps do not support this setting, so a program like VSCode would have its Icons on the correct side, while the Pantheon-files still has the same button Layout as before. But well it is a good start.