Tech and Tips Thursday: Loading Javascript, Fun With Linux, On Systems
Login
Technology

Tech and Tips Thursday: Loading Javascript, Fun With Linux, On Systems

This is the third edition of our Tech and Tips Thursday series. Today we will be talking about loading javascript files in your browser, having fun with a couple of Linux commands and exploring the idea of complex systems using Gall's Law.
Welcome to the third edition of the Tech and Tips Thursday series. Today we will be talking about loading javascript files in your browser, having fun with a couple of Linux commands and exploring the idea of complex systems using Gall's Law. 

About T&T Thursday


Tech and Tips Thursday (or T&T Thursday for short) is a biweekly technology and tips article on various software development, technology and productivity topics. Topics that we are interested in, have some experience with and topics that we find interesting outside of technology.

T&T Thursday article follows a standard format. It consists of three sections:

  • One Coding Example
  • One Useful App or Tool 
  • One Interesting Idea or Thought

One Coding Example


Today's example is about Javascript in the browser.  

If you've built a website then you have loaded a javascript file in the HTML using the <script> tag.  Something like this:

<script src="/js/my_awesome_javascript.js" type="text/javascript></script>

When you load a javascript file this way, what usually happens is the following: 

  1. The browser first loads the HTML page
  2. Then the browser begins parsing the HTML code
  3. When it encounters the <script> tag, the browser goes to fetch that file
  4. After the javascript file is downloaded, the browser parses and executes the javascript code
  5. It then continues parsing the HTML code

You have probably experienced the downside of this process if you tried accessing an element in your javascript before that element was parsed by the browser. 

For example:

<script type="text/javascript">
  var el = document.getElementById("my_list")
  console.log(el)
</script>

<div id="my_list">
</div>

In this case, the console will show "undefined" message since the javascript code will be executed before the browser parses the DIV element. 

To solve this problem traditionally we used something like this:

(function() {
  // your code here
})

// OR Using jQuery

$(document).on("ready", function() {
  // your code here
})

There is a third way.  You can add a "defer" tag to your script. Like this:

<script defer type="text/javascript">
  var el = document.getElementById("my_list")
  console.log(el)
</script>

This tag will tell the browser to defer the execution of this javascript until after it finishes loading the whole HTML file. 

You can also use the defer tag a SCRIPT tag that loads javascript from a file. The browser will fetch the javascript, parse it but will not execute the code until after HTML is loaded. 

One Useful App or Tool 


Today, we will have some fun. Our useful too is a couple of fun tools.  

  1. Cowsay
  2. Cowthink
  3. Figlet 
  4. Fortune

These are fun Linux tools that you can use to pass the day while compiling your code or waiting for your deploy to finish. 

If you are on the Debain system, you can install them with this command: 

 :~# sudo apt install cowsay figlet fortune 

On Redhat-based system substitute, apt install with yum install.

Let's explore these four tools.

Cowsay

The cowsay command draws animals using ASCII characters in the terminal. It also makes them say things.

Cowsay in action


You can change which animal you want to display by passing the -f option. 

Use cowsay -l for a full list of available options.


Cowthink

To make the cow think, use the cowthink command. Cowthink command is bundled with cowsay command.

Cow's thinking...


Figlet

You can use the figlet command to create large-sized banners. You can put these manners in your welcome script, or as your email signature.

Got Milk Banner


Fortune

The fortune command will create a  random quote of the day.

Some of the quotes are quite interesting.


Of course, you can combine fortune with cowsay.

Fortune will keep you entertained ... for a long, long time.


Life has been so serious and stressful, these little tools can be a much-needed distraction. Enjoy! 

One Interesting Idea 


Let's begin with a quote. 

A complex system that works is invariably found to have evolved from a simple system that works. The inverse proposition also appears to be true: A complex system designed from scratch never works and cannot be made to work.
- John Gall, System's Theorist. Author of The Systems Bible. 

Here's a thought experiment for you. Build a modern house from scratch. All you have is a few simple tools, a shovel and a bunch of rocks, some metal nails, wires, and wood. You can call your friends to help you dig and put the house together. 

It could take you a year or more to dig the foundation, build the framing, and put the walls up.  But no matter how much you try, there is a 99% chance that your house will resemble a stone-aged dwelling more than anything modern. 

Now take your thought experiment further. Think about how to build a plane, create a new vaccine or extract natural resources from the ground. Try to figure out how to do all of this without having any of the modern technology, tools and knowledge.  It is an impossible task. 

It is impossible to create a complex system from scratch. 

And that's what Gall's Law is all about.  Complex systems that work, only work because they evolved from simpler working systems. These systems have gone through a selection bias, were influenced by different events, variables and outcomes. The end result is a working complex system.

Complex systems designed from scratch will not work in real life precisely because they have not been subjected to these selection forces. 

To build complex systems, first, you should start by building a prototype of a simple process. Then put that prototype into the real-world, test it, improve it, and refine it. Then repeat the same process, over and over.  

That is how working complex systems come to be. 


Until next time.  

If you liked this installment of Tech and Tips Thursday, please be sure to subscribe and share it with your friends and colleagues on your favourite platform. 

Get Tech and Tips Thursday articles in your email.