or The art of using Baby Steps and other strange programming principles
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 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.
Making a living 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!
You dream a very pleasant dream. You are walking in a beautiful magical garden, rich colored, with pretty and strange animals and plants. …
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.
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. …
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.
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. …
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. …
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 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. …
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.
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. …
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.
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. …
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.
This article was written in December/2020. It may be obsolete now.
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.
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