CategoryBlog

WebDev – Articles – 01

A short summary of some of the interesting articles I came across in the last couple of weeks.

UI

Most Important Color in UI Design
A very interesting article on the Color Blue and why it is used so much.

Tools

Canary 62 Dev Tools

One of the highlights of the new Dev tools is that you can capture screenshots of a specific node.

  1. Select the Node
  2. Open the Command Menu (CTRL-SHIFT-P)
  3. Type ‘capture node’

https://developers.google.com/web/updates/2017/08/devtools-release-notes?utm_source=feed&utm_medium=feed&utm_campaign=updates_feed

VSCode 1.16

  • HTML now finally gets autoclose tag. However it is not enabled for JSX, so you still need to install the Auto-Close-Plugin
  • Support of Typescript 2.5
  • Faster Refactorings for Typescript, by selecting a Code Segment you can rightclick and say “Extract Function”

https://code.visualstudio.com/updates/v1_16

WhatRuns

A useful tool to detect which technologies are used by a specific website.
https://www.whatruns.com/

Security

Edge Insecure by Design: Bypass Content Security Policy (CSP)
A reported Security Issue that effects Safari, Chrome and Edge, got fixed in Safari and Chrome. Microsoft responds: Works as Designed.

Random Articles

Trending Developer Skills based on Job Descriptions
An interesting way to take a look at the vacant Job Positions and concluding which technologies are currently being used for the Production Stack.

(tl;dr: Rapid Rise of React, NodeJS and Postgres)

Why Coding Style Matters
A short article about the benefits of a clear and consistent coding style.ama
“Programs are meant to be read by humans and only incidentally for computers to execute.”
— H. Abelson and G. Sussman (in “Structure and Interpretation of Computer Programs”)

VSCode: Launch create-react-app and Chrome with launch.json

Developing React (with create-react-app) and Visual Studio Code you usually press ESC-` and then npm start.
The script from create-react-app then automatically starts a Browser. That you then close.
hen reopen by pressing F5 to start Chrome in debug mode.

Let’s make these steps a little quicker.

Create a Task for npm start

Press Ctrl-Shift- and Select “Tasks: Configure Default Test Task”
This will create a tasks.json file.

In the tasks.json file you need to add a couple of values:
* isBackground: true – launch.json will not wait untill the task completes
* problemMatcher Needs to be defined to figure out when the task has completet its initialisation phase and it is safe to continue with the next task

Configure create-react-app

To prevent launching the browser you need to add in your .env-file following line:

BROWSER=none

More Info:
* .env-file

Configure the Launch.json file

Press F5 and select Chrome and a launch.json file will be created.
* Change the port to 3000 (create-react-app default)
* Add a preLaunchTask to start the task we defined earlier

Start Working

Tadaa, now you press F5 and can start debugging directly in vscode. The background task will continue running even when you stop debugging.

Stop Working

You need to terminate the task via ctrl-shift-p > terminate Task. (Or you just close vscode)

VSCode Extensions (August 2017)

Here are a couple of VSCode Extensions I currently am using.

tl;dr

Script to install all suggested Plugins

Installing Extensions

There are two ways of installing extensions. Either in the editor or via command line.

Editor

  1. Press Ctrl-P
  2. Paste Code like ext install eamodio.gitlens
  3. Click on install

Command Line

  1. Open command line
  2. Enter command code --install-extensions eamodio.gitlens

Markdown All in One

A litte tool that makes it a little easier to format Markdown documents
Adds useful shortcuts like ctrl-b to make something bold.

code --install-extension yzhang.markdown-all-in-one

Auto Close Tag

If you do not use Emmet shorthand, it is very useful of closing your html tags.

Sadly the plugin cannot figure out if you are defining a type in Typescript and also attempts to close the casting tags.

code --install-extension formulahendry.auto-close-tag

Auto Rename Tag

This plugin takes care of the closing tag of your html-tag. It also works for JSX&TSX files.

code --install-extension formulahendry.auto-rename-tag

GitLens

A great extension to vastly improve your git experience in vscode

code --install-extension eamodio.gitlens

TODO Highlight

Well it Highlights Todos… so well thats good.
You can extend it to display any type of label in your comments.

Plus it can generate a handy list of all todos in the project.
(Sadly jumping to the TODO in the List does not work in Ubuntu)

code --install-extension wayou.vscode-todo-highlight

Path Intellisense

Well it detects when you are trying to define a path to a file and autocompletes it for you.

In typescript it also correctly removes the file extension for imports.

code --install-extension christian-kohler.path-intellisense

edX – Microsoft: 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:
* Git

Cloud Providers
* Gitlab For Private Repos
* Github For Public Repos

Workflows
* Comparing Workflows
* GitLab Flow

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

Code should be formatted always in the same matter. It improves the readablity and removes all personal style from the code enabling all developers to immediatly 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.

Simplfy

This one is rather difficult, but by keeping the code and the structures simple and readable has an 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.

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.

Notes on Course: Microsoft – Advanced CSS Concepts

My notes on the great course Microsoft – Advanced CSS Concepts on edx.

Lesson 01

Responsive Layout

Covers the basics of Responsive Layout.
In essence you use the @media query to figure out what
the width, height, page orientation and resolution of the device is.
Then based on that information you use a different CSS Rule.

To create a consistent Layout you should always design for the smallest device screen – then expand it to the bigger devices.
(Mobile First Strategy).

Base CSS

In General you should use a Style guide to create a consistent look
across your application. They are usually created by the graphic designer.

Typically a website should be suitable for all different types of browsers.
However the CSS implementation and the default styles are different across browsers.
To avoid this problem, you can include a CSS Reset – to ensure a consistent style.

A front end Style guide should help define
* Code standardization of CSS, and HTML
* Consistency of code and design
* More efficient workflow
* Documenting of code practices
* An easy-to-access reference for code and design for new team members

Your style guide will be comprised of:

  • A template: The template contains the basic elements that serve as the foundation for your web page, such as color palette, fonts, headers, footers, body text, navigation, widgets, and grid layouts.
  • Patterns: The patterns for your web page include buttons, logos, images, the font icon library, and form styles.
  • Documentation: The documentation is a record of the style and development pattern of your web page. You can add comments in your code that serve as the style guide or use interactive modals or tool tips.

Media Queries

The most commonly used media queries are:

  • min-width Rules applied for any browser width over the value defined in the query
  • max-width Rules applied for any browser width below the value defined in the query
  • min-height Rules applied for any browser height over the value defined in the query
  • max-height Rules applied for any browser height below the value defined in the query
  • orientation:portrait Rules applied for any browser where the height is greater than or equal to the width
  • orientation:landscape Rules for any browser where the width is greater than the height

The Query information is then used to define breakpoints, points where the layout switches from one size to another.
Example of a set of major device breakpoints:

/* Extra small devices (phones, up to 480px) */
@media screen and (max-width: 767px) {…}

/* Small devices (tablets, 768px and up) */
@media (min-width: 768px) and (max-width: 991px) {…}

/* tablets/desktops and up */
@media (min-width: 992px) and (max-width: 1199px) {…}

/* large like desktops and up */
@media screen and (min-width: 1200px) {…}

Units

Historically the “px” Unit was used, however to incorporate various resolutions it is better to use the “rem” unit.

Going forward

  • Optimize the text for reading
  • Use major device breakpoints, and address content with minor breakpoints
  • Treat your website’s layout as an enhancement
  • Use relative units like rem or em;

Working with images

Images should be resampled to three different media sizes

Note: The alt tag must be set to correctly validate.

Lesson 02

Modular CSS

Modular CSS is:

  • A guideline based approach for breaking down pages into generic reusable CSS code.
  • Based on classes and consistent naming conventions.
  • Easy to read and maintain by teams.

CSS Modules are:

  • Generic, self-contained, and reusable.
  • Modifiable, combinable, and scalable.
  • Can contain or be contained by other modules but stay independent.

What are some common modules?

You will often come across modules such as these:

Example Module

What are the Results of a Module Based Approach?

  • Faster development
  • Flexible and scalable code
  • Code reuse
  • Organized and easy to read code
  • Easier to maintain
  • Team efficiency
  • Decoupled HTML and CSS

Guidlines

  1. OOCSS (Object Oriented CSS) | http://oocss.org/
  2. SMACSS (Scalable and Modular Architecture for CSS) | https://smacss.com/
  3. BEM (Block, Element, Modifier) http://getbem.com/
  4. DRY (Don’t Repeat Yourself CSS)

Font Awesome

A popular set of icon fonts is Font Awesome (http://fontawesome.io/)

Example for a like button

© 2017 Neal Bürger

Theme by Anders NorénUp ↑