or The art of using Baby Steps and other strange programming principles

What about Bob?
What about Bob?
What about Bob?

Over the years writing code, I have been testing various programming principles. Some I rejected, others I adopted and others I adapted. I also invented some.

It is not enough for a principle to be very good, it needs to be remembered or it will not be used. I believe that the most remembered principles are those that are imported from the everyday life. And if they are associated with something nice or have a funny name, more we tend to use them. And lighter our work becomes.

The Chuck Berry principle


The right architecture for handling mouse and keyboard events

Messy event handling
Messy event handling
Messy event handling

Simple Application

The browser (JavaScript) is very helpful about handling user input. For example:

var doneButton = document.getElementById(“done”)
doneButton.onclick = function () { sendDataToServer() }

This is a simple and straightforward code that works perfectly well for the following context.

  1. The user spends a minute filling out a form with his data.
  2. The user clicks the “done” button.
  3. The user waits two seconds for the page to be updated, which he considers very acceptable.


Making a living in the stock market

Image for post
Image for post
Photo by Sharon McCutcheon on Unsplash

Is it possible to make a living as investor/trader in the stock market?

Yes. Possible and easy. This is what I’ve been doing for more than 35 years. In fact, it is the only way I made money in my life, except when working as employee in my youth.

At this point of life, I would like to expose and discuss some thoughts, beliefs, experiences and financial strategies.

I hope you can use it somehow.

Let’s start!

Our special fairy tale

You dream a very pleasant dream. You are walking in a beautiful magical garden, rich colored, with pretty and strange animals and plants. …


CODEX

A comprehensive tutorial

Image for post
Image for post
A linter running

This is the fourth and last part of a comprehensive tutorial on constructing a JavaScript linter. You can read the third part here.

And here is the source code of dirtyrat in GitHub.

Registering names

As we saw in other parts of this tutorial, when the linter, while parsing token by token, finds a token of kind name, it calls some function to register the name (token) as declared or as used.

Lets’s take a look at the module register.

Basically, registering names means filling dictionaries of the source code file object (rat) using the pattern dictionary[branchedName]=token.

Besides preparing data for later matching of names, the register immediately points to the double declaration error. …


CODEX

A comprehensive tutorial

Image for post
Image for post
A linter running

This is the third part of a comprehensive tutorial on constructing a JavaScript linter. You can read the second part here.

And here is the source code of dirtyrat in GitHub.

Parsing the function body — blocks

Statements like if, else, for, while always create a block of code, also known as scope. When the parser finds, for example, the statement break it must have a way to know if this statement is inside a loop or not. Other example: when the parser finds a closing curly brace, it must know what block is being closed.

Controlling the code blocks is done by two global variables and two small functions. …


CODEX

A comprehensive tutorial

Image for post
Image for post
A linter running

This is the second part of a comprehensive tutorial on constructing a JavaScript linter. You can read the first part here.

And here is the source code of dirtyrat in GitHub.

In the first part of the tutorial, we learned about the tokenizer, the scanner, and the displaying of errors. Just one file per each of these three entities is enough. And the code inside each file is easy to follow and is not very big. Piece of cake!

Now we have to examine the relations among the token objects that represent the source code we want to lint. The part of the linter responsible for this task is called a parser. The parser must do a lot more than just checking each token against its next neighbor. …


A comprehensive tutorial

Image for post
Image for post
A linter running

This is the first part of a comprehensive tutorial on constructing a JavaScript linter. A linter is a tool for checking source code. We will see the fundamental concepts and the source code of a real linter written in JavaScript, including algorithms for the tricky parts.

Note: dirtyrat is the linter used to produce this tutorial.

How a linter works internally

How can we make a computer so clever to understand a thousand line file written with the complex set of rules of JavaScript? How to deal with such complexity? The answer is always the same.

We break the big complex system in small, simple components, that have simple relations with other components.


The DRY principle may be messing with your code

Image for post
Image for post
Multi-Man from The Impossibles

In this article, we discuss the use of the DRY (Don’t Repeat Yourself) programming principle. We will examine a case when DRY should NOT be used. And we will see a step-by-step code refactoring obeying the DRY principle, that shows what to do and what not to do.

All code here is procedural JavaScript.

The DRY principle

Of all the programming principles, for a combination of reasons, DRY is the most attractive to me. DRY is a common name, which demonstrates what it is about. Also, DRY is an acronym for a love at first sight phrase: Don’t repeat yourself.

Maybe because it makes sense (who wants double work?) so easy, and is easy to remember, we tend to overestimate it. Using it when we should not use it, using when is not necessary, or using it in the wrong way. …


A study on performance of JavaScript 2.5D games

Image for post
Image for post
Ultima 8

In this article, we check whether the browser is capable of running a sprite game at 60 FPS (frames per second) or not. We discuss architecture options, run performance tests and discover a HUGE catch.

The Loop

An application running at 60 FPS means that it has less than 16,666 ms (1 second / 60) to complete the execution of each loop. But since the browser and the operating system have other tasks to perform, in practice we have half of this time.

If we want a STRONG margin of safety (we don’t know all the circumstances in which our game will run), we may consider 3 ms as the maximum time available for the execution of each loop in the game. …


How to make the WhatsApp link accessible for Linux desktop

Image for post
Image for post
Photo by Christian Wiediger on Unsplash

In this article we will see how make the links for WhatsApp work for Linux desktop. Also we will see CSS code to animate the WhatsApp icon.

Disclaimer

This article was written in December/2020. It may be obsolete now.

According to WhatsApp

According to WhatsApp, the right link to WhatsApp in your web page has an href attribute like this:

https://wa.me/XXXXXXXXXXX?text=Hello

You must replace XXXXXXXXXXX by the full phone number in international format. Omit any zeros, brackets, or dashes when adding the phone number in international format.

The Problem

This method is OK when the user is at smartphone or Windows desktop. And is broken when the user is at a Linux desktop. Clicking on the WhatsApp link (in case of Linux desktop) makes the browser ask your authorization to access some application. Many people would not allow it. Even when you allow it. …

About

Joana Borges Late

I am interested in computer programming and production of browser games. Also I am a fan of https://www.bobsprite.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store