<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Layman's Guide to Computing - Season 08</title><link href="https://ngjunsiang.github.io/laymansguide/" rel="alternate"></link><link href="https://ngjunsiang.github.io/laymansguide/feeds/season-08.atom.xml" rel="self"></link><id>https://ngjunsiang.github.io/laymansguide/</id><updated>2021-01-23T08:00:00+08:00</updated><entry><title>Issue 104: Storing sensitive data</title><link href="https://ngjunsiang.github.io/laymansguide/issue104.html" rel="alternate"></link><published>2021-01-23T08:00:00+08:00</published><updated>2021-01-23T08:00:00+08:00</updated><author><name>J S Ng</name></author><id>tag:ngjunsiang.github.io,2021-01-23:/laymansguide/issue104.html</id><summary type="html"></summary><content type="html">&lt;p&gt;&lt;strong&gt;Previously:&lt;/strong&gt; A race condition happens when threads depend on instructions happening with coincidental timing for success. When instructions are not executed with appropriate timing, one or more threads can get stuck waiting on a response that never&amp;nbsp;comes.&lt;/p&gt;
&lt;p&gt;To wrap up this season on how apps work, I’m going to try answering a question I had on my mind as I was still new to computers: where do my secrets get stored? If I don’t want them to be stored, what are my&amp;nbsp;options?&lt;/p&gt;
&lt;p&gt;I will answer that &lt;em&gt;from an app’s perspective&lt;/em&gt; in this&amp;nbsp;issue.&lt;/p&gt;
&lt;h2&gt;Why would I want to keep secrets from my&amp;nbsp;users?&lt;/h2&gt;
&lt;p&gt;You just wrote an app. Your app syncs data to a cloud database (&lt;a href="https://ngjunsiang.github.io/laymansguide/issue090.html"&gt;Issue 90&lt;/a&gt;)). But the cloud database has many other app developers using it as well—how would it know it is you and not some other malicious hacker? It recognises you via a &lt;strong&gt;shared secret&lt;/strong&gt;: a token or an &lt;span class="caps"&gt;API&lt;/span&gt; key that you can see after you log in to your dashboard on their&amp;nbsp;website.&lt;/p&gt;
&lt;p&gt;After your users install the app, every request sent by your app to the cloud database has to be authenticated using this &lt;em&gt;shared secret&lt;/em&gt;. That means you are going to have to get this shared secret onto the app somehow. But this has to happen without the user being able to see it or access it, otherwise a savvy user could use that key to gain access to your cloud&amp;nbsp;database.&lt;/p&gt;
&lt;h2&gt;Storing secrets on the&amp;nbsp;web&lt;/h2&gt;
&lt;p&gt;The code that is loaded by the user’s browser runs under their control, so putting the shared secret anywhere in that code is a bad idea. Any savvy user who knows how to view the script’s source can potentially find&amp;nbsp;it!&lt;/p&gt;
&lt;p&gt;A much safer option is to store the secret with the code that runs on &lt;em&gt;your server&lt;/em&gt;. But not in the server’s source code! If you are most developers, you would be using some kind of version control system (&lt;a href="https://ngjunsiang.github.io/laymansguide/issue019.html"&gt;Issue 19&lt;/a&gt;)) that maintains a copy of your source code and all its changes. If you are using Github or some other public platform for this, you have to be very careful that the shared secret is not visible (or otherwise guessable) just by reading the source&amp;nbsp;code.&lt;/p&gt;
&lt;p&gt;For a simple shared secret, such as a short string of characters, app developers usually use &lt;strong&gt;environment variables&lt;/strong&gt;. These are pieces of information that are kept in memory only, accessible by the app, and are set by the operating system whenever the app starts up. The server where you run your code will let you configure the environment variables that your app needs, keeping them out of sight of the&amp;nbsp;users.&lt;/p&gt;
&lt;h2&gt;Storing secrets in a mobile&amp;nbsp;app&lt;/h2&gt;
&lt;p&gt;Mobile apps are supported by a host of services provided by the operating system (&lt;span class="caps"&gt;OS&lt;/span&gt;), typically managed by Google or Apple. They each offer a way for you to store a shared secret with the &lt;span class="caps"&gt;OS&lt;/span&gt;. Your app can use this shared secret from the &lt;span class="caps"&gt;OS&lt;/span&gt; to encrypt information so that other apps are not able to access it. When your app starts up, it requests the secret from the &lt;span class="caps"&gt;OS&lt;/span&gt;, and uses it to decrypt the secret&amp;nbsp;again.&lt;/p&gt;
&lt;h2&gt;Storing secrets in a laptop&amp;nbsp;app&lt;/h2&gt;
&lt;p&gt;If you are developing a laptop app that does not rely on a connection to your server (i.e. a “standalone” app), your options are somewhat more limited. Since all your app code and resources will be in the user’s machine and thus accessible to the user, your best bet is to find some way to obfuscate it and hope no one finds it&amp;nbsp;easily.&lt;/p&gt;
&lt;p&gt;This is one reason why so many apps require an online connection: it is much easier to hide secrets on a machine you own and control! With a server connection, you can require the app to retrieve the secret from the server, and delete the temporary copy of the secret after&amp;nbsp;use.&lt;/p&gt;
&lt;h2&gt;Storing&amp;nbsp;passwords&lt;/h2&gt;
&lt;p&gt;If your users log in with an email and password (which is almost every online service ever), you don‘t actually store their passwords; that is terrible security practice, even if you do it in a database! A nifty piece of software technology, known as a &lt;strong&gt;hash function&lt;/strong&gt;, takes that password (regardless of length) and turns it into a unique&lt;sup id="fnref:1"&gt;&lt;a class="footnote-ref" href="#fn:1"&gt;1&lt;/a&gt;&lt;/sup&gt; &lt;strong&gt;hash&lt;/strong&gt; with a fixed number of&amp;nbsp;characters.&lt;/p&gt;
&lt;p&gt;Examples of&amp;nbsp;hashes:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="mf"&gt;661&lt;/span&gt;&lt;span class="n"&gt;c425549bc70b98e908325b8c64f82&lt;/span&gt;
&lt;span class="mf"&gt;056&lt;/span&gt;&lt;span class="n"&gt;cd6eb540ace37e64572c64c778d45&lt;/span&gt;
&lt;span class="mf"&gt;239&lt;/span&gt;&lt;span class="n"&gt;b1ddbb45caf82408cb89f13816185&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;What you do, then, is to store the password &lt;em&gt;hash&lt;/em&gt; instead of the password. When a user sends a username and password, you hash their attempted password, compare it with the stored hash, and see if they are the&amp;nbsp;same.&lt;/p&gt;
&lt;p&gt;The hashes are designed to be difficult to reverse. The state-of-the-art algorithm used today can generate hashes that would take millions of years to reverse using hardware currently available. But there are techniques that can reverse hashes of some older algorithms in as little as 30 minutes, so if you are a developer, please find out which one to&amp;nbsp;use!&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue&amp;nbsp;summary:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Shared secrets allow secured access to resources, such as databases or other services. These shared secrets are typically kept on a server controlled by the app developer. For mobile apps, they are usually stored with the operating system, inaccessible to other&amp;nbsp;apps.&lt;/p&gt;
&lt;p&gt;Phew, we had enough issues here to cover the main parts. And I managed to answer one of the sometime-in-the-future questions! Actually, I also answered another one on software installation earlier, in issues &lt;a href="https://ngjunsiang.github.io/laymansguide/issue099.html"&gt;99&lt;/a&gt;) and &lt;a href="https://ngjunsiang.github.io/laymansguide/issue100.html"&gt;100&lt;/a&gt;), so I’m going to go ahead and strike it&amp;nbsp;off.&lt;/p&gt;
&lt;h2&gt;What I’ll be covering&amp;nbsp;next&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Next issue:&lt;/strong&gt; [&lt;span class="caps"&gt;LMG&lt;/span&gt; S9] Issue 105: Operating&amp;nbsp;Systems&lt;/p&gt;
&lt;p&gt;This wraps up another season of Layman’s Guide on how apps work. Next season, I am going to zoom out and look at the environment that apps operate in: the operating system. Yep, I’m going to tackle the most complex pieces of software ever to be written, and try to explain them in terms that laypeople can understand&amp;nbsp;😅&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Sometime in the future:&lt;/strong&gt; What&amp;nbsp;is:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;booting up? [Issue&amp;nbsp;15]&lt;/li&gt;
&lt;li&gt;&lt;span class="caps"&gt;XSS&lt;/span&gt;? [Issue&amp;nbsp;8]&lt;/li&gt;
&lt;li&gt;a good reason developers write code and give it away for free online? [Issue&amp;nbsp;21]&lt;/li&gt;
&lt;li&gt;firmware? [Issue&amp;nbsp;34]&lt;/li&gt;
&lt;li&gt;OpenType? And what are fonts anyway? [Issue&amp;nbsp;42]&lt;/li&gt;
&lt;li&gt;&lt;del&gt;involved in installing a piece of software? [Issue 48]&lt;/del&gt;&lt;/li&gt;
&lt;li&gt;How do apps know where a file starts and ends? [Issue&amp;nbsp;49]&lt;/li&gt;
&lt;li&gt;&lt;del&gt;a password hash? [Issue 63]&lt;/del&gt;&lt;/li&gt;
&lt;li&gt;a driver file and why do I need one? [Issue&amp;nbsp;98]&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="footnote"&gt;
&lt;hr /&gt;
&lt;ol&gt;
&lt;li id="fn:1"&gt;
&lt;p&gt;In practice, there is a very low chance that two different passwords may end up giving the same hash. This technology is still being improved!&amp;#160;&lt;a class="footnote-backref" href="#fnref:1" title="Jump back to footnote 1 in the text"&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;</content><category term="Season 08"></category><category term="app"></category></entry><entry><title>Issue 103: Why apps hang even with multiple threads</title><link href="https://ngjunsiang.github.io/laymansguide/issue103.html" rel="alternate"></link><published>2021-01-16T08:00:00+08:00</published><updated>2021-01-16T08:00:00+08:00</updated><author><name>J S Ng</name></author><id>tag:ngjunsiang.github.io,2021-01-16:/laymansguide/issue103.html</id><summary type="html">&lt;p&gt;A race condition happens when threads depend on instructions happening with coincidental timing for success. When instructions are not executed with appropriate timing, one or more threads can get stuck waiting on a response that never&amp;nbsp;comes.&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;strong&gt;Previously:&lt;/strong&gt; Applications are assigned a thread by the &lt;span class="caps"&gt;OS&lt;/span&gt; for running a sequence of instructions. The instructions are executed sequentially, and the app cannot proceed if it gets stuck on any&amp;nbsp;instruction.&lt;/p&gt;
&lt;h2&gt;Multithreading&lt;/h2&gt;
&lt;p&gt;An app can hang if its sole thread gets stuck. In some cases, an app can be written to make use of multiple threads. This is possible when a computer has more than one processing core, or if an operating system is designed to divide computing time among multiple&amp;nbsp;threads.&lt;/p&gt;
&lt;h2&gt;Race&amp;nbsp;conditions&lt;/h2&gt;
&lt;p&gt;Trying to design apps to use multiple threads is hard! Apps running into an error is one thing; a more subtle form of failure is known as a &lt;strong&gt;race condition&lt;/strong&gt;. This happens when the success of two or more tasks depend on near-perfect timing which the threads have little control&amp;nbsp;over.&lt;/p&gt;
&lt;h2&gt;Main and secondary&amp;nbsp;threads&lt;/h2&gt;
&lt;p&gt;A common pattern is to have the app’s graphical interface and main code run in its own thread, with any subsidiary tasks (such as opening files) running in a secondary thread. If the task in the secondary thread is taking too long, the main thread can still issue instructions to terminate the secondary thread’s task, and thereby restore order and&amp;nbsp;control.&lt;/p&gt;
&lt;p&gt;Sounds fair enough. How might this&amp;nbsp;fail?&lt;/p&gt;
&lt;p&gt;Lets take an example: the main thread has a task that involves sending a signal to secondary thread, and then waiting for a response from it. Secondary thread has a task that involves sending a signal to main thread, and then waiting for a response from it. Both tasks complete successfully when they are carried out independently. But what if the main and secondary threads both run those tasks near-simultaneously, before the other thread has a chance to respond? They both get stuck waiting for a response. The app has just&amp;nbsp;hung!&lt;/p&gt;
&lt;h2&gt;Multiple worker&amp;nbsp;threads&lt;/h2&gt;
&lt;p&gt;Another pattern is to split the job up into multiple parts, and have multiple threads each take a part of the job. When they have all completed, the completed parts are then stitched back together into the finished&amp;nbsp;result.&lt;/p&gt;
&lt;p&gt;But this has its own ways of failing&amp;nbsp;too.&lt;/p&gt;
&lt;p&gt;The threads have to coordinate their job status, and often do so by updating a common set of data. Thread 1 might request access to that data to update it. To ensure that the data doesn’t change before it is done, it will usually request a lock (&lt;a href="https://ngjunsiang.github.io/laymansguide/issue082.html"&gt;Issue 82&lt;/a&gt;)) on it, to prevent other threads from modifying it at the same&amp;nbsp;time.&lt;/p&gt;
&lt;p&gt;One way this can fail in practice is if two or more worker threads request a lock simultaneously. They both get a lock, because at the moment their requests are processed, nothing else has locked the resource. But now they can’t proceed to modify the data because it has been locked by another thread that isn’t&amp;nbsp;them.&lt;/p&gt;
&lt;p&gt;This situation is known as a &lt;strong&gt;deadlock&lt;/strong&gt;. This and similar situations are just one out of many ways that apps can&amp;nbsp;hang.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue summary:&lt;/strong&gt; A race condition happens when threads depend on instructions happening with coincidental timing for success. When instructions are not executed with appropriate timing, one or more threads can get stuck waiting on a response that never&amp;nbsp;comes.&lt;/p&gt;
&lt;p&gt;Yep, multithreaded programming is&amp;nbsp;hard.&lt;/p&gt;
&lt;h2&gt;What I’ll be covering&amp;nbsp;next&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Next issue:&lt;/strong&gt; [&lt;span class="caps"&gt;LMG&lt;/span&gt; S8] Issue 104: Storing sensitive&amp;nbsp;data&lt;/p&gt;
&lt;p&gt;To wrap up this season on apps, I’ll look at one last question: how do apps keep our data&amp;nbsp;secure&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Sometime in the future:&lt;/strong&gt; What&amp;nbsp;is:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;booting up? [Issue&amp;nbsp;15]&lt;/li&gt;
&lt;li&gt;&lt;span class="caps"&gt;XSS&lt;/span&gt;? [Issue&amp;nbsp;8]&lt;/li&gt;
&lt;li&gt;a good reason developers write code and give it away for free online? [Issue&amp;nbsp;21]&lt;/li&gt;
&lt;li&gt;firmware? [Issue&amp;nbsp;34]&lt;/li&gt;
&lt;li&gt;OpenType? And what are fonts anyway? [Issue&amp;nbsp;42]&lt;/li&gt;
&lt;li&gt;involved in installing a piece of software? [Issue&amp;nbsp;48]&lt;/li&gt;
&lt;li&gt;How do apps know where a file starts and ends? [Issue&amp;nbsp;49]&lt;/li&gt;
&lt;li&gt;a password hash? [Issue&amp;nbsp;63]&lt;/li&gt;
&lt;li&gt;a driver file and why do I need one? [Issue&amp;nbsp;98]&lt;/li&gt;
&lt;/ul&gt;</content><category term="Season 08"></category><category term="app"></category><category term="operating system"></category></entry><entry><title>Issue 102: Threading</title><link href="https://ngjunsiang.github.io/laymansguide/issue102.html" rel="alternate"></link><published>2021-01-09T08:00:00+08:00</published><updated>2021-01-09T08:00:00+08:00</updated><author><name>J S Ng</name></author><id>tag:ngjunsiang.github.io,2021-01-09:/laymansguide/issue102.html</id><summary type="html">&lt;p&gt;Applications are assigned a thread by the &lt;span class="caps"&gt;OS&lt;/span&gt; for running a sequence of instructions. The instructions are executed sequentially, and the app cannot proceed if it gets stuck on any&amp;nbsp;instruction.&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;strong&gt;Previously:&lt;/strong&gt; An app crashes when it encounters a situation it can’t handle, or when it attempts to perform an operation that is disallowed by the operating&amp;nbsp;system.&lt;/p&gt;
&lt;p&gt;This post is a prelude to talking about app hangs. Hangs are both simple yet complicated to talk about, but there’s a piece of the puzzle that has to come into the picture first. That piece is about how apps&amp;nbsp;work.&lt;/p&gt;
&lt;p&gt;In a computer, the operating system (&lt;span class="caps"&gt;OS&lt;/span&gt;) has to coordinate the requested actions of so many different apps. How does it know which action came from which&amp;nbsp;app?&lt;/p&gt;
&lt;p&gt;Through a mechanism known as&amp;nbsp;threads.&lt;/p&gt;
&lt;h2&gt;Threading&lt;/h2&gt;
&lt;p&gt;When you run an app, the &lt;span class="caps"&gt;OS&lt;/span&gt; creates a separate thread. A thread is a sequence of programmed instructions, like a thread of thought. Or a thread of bureaucracy. The &lt;span class="caps"&gt;OS&lt;/span&gt; completes each instruction in the thread, and if it gets stuck on any single task, it cannot move&amp;nbsp;on.&lt;/p&gt;
&lt;p&gt;Sometimes, this is good and necessary, like when you need input from the user (don’t be doing anything else until I tell you what I need!). Other times, it is unnecessary&amp;nbsp;waiting.&lt;/p&gt;
&lt;h2&gt;What causes threads to get&amp;nbsp;stuck?&lt;/h2&gt;
&lt;p&gt;Some of us really hate math, but not computers! The math is hardly ever what causes threads to&amp;nbsp;stop.&lt;/p&gt;
&lt;p&gt;Like in the workplace, it is often other &lt;del&gt;people&lt;/del&gt; devices.&lt;/p&gt;
&lt;p&gt;When an app (running in a thread) tries to open a file to read data from it, the operating system has to look up the virtual memory  address (&lt;a href="https://ngjunsiang.github.io/laymansguide/issue055.html"&gt;Issue 55&lt;/a&gt;)), follow it to the hard disk or solid state disk, and then wait for the disk to respond with the&amp;nbsp;data.&lt;/p&gt;
&lt;p&gt;And in that moment, &lt;em&gt;lots&lt;/em&gt; of things can go&amp;nbsp;wrong.&lt;/p&gt;
&lt;p&gt;If the disk is failing, and unable to read the sector where the data resides, it will usually keep attempting to do so. Meanwhile, back in the operating system, the thread is stuck. It cannot move on, because the previous instruction to open the file has not completed. It can’t even decide to abort the currently-running instruction—telling the app to stop &lt;strong&gt;is already another instruction&lt;/strong&gt; which has to&amp;nbsp;wait!&lt;/p&gt;
&lt;p&gt;The only thing to do now is wait for the &lt;span class="caps"&gt;OS&lt;/span&gt; to realise that this thread is taking too long to do its thing, and forcibly terminate the thread. This is known as a thread &lt;strong&gt;timeout&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Is there any way to work around this? Yep! The termination instruction has to come from a separate thread. This means the app has to run multiple&amp;nbsp;threads.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue summary:&lt;/strong&gt; Applications are assigned a thread by the &lt;span class="caps"&gt;OS&lt;/span&gt; for running a sequence of instructions. The instructions are executed sequentially, and the app cannot proceed if it gets stuck on any&amp;nbsp;instruction.&lt;/p&gt;
&lt;h2&gt;What I’ll be covering&amp;nbsp;next&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Next issue:&lt;/strong&gt; [&lt;span class="caps"&gt;LMG&lt;/span&gt; S8] Issue 103: Why apps hang even with multiple&amp;nbsp;threads&lt;/p&gt;
&lt;p&gt;Processors today already have multiple cores, and many apps can already run on multiple threads. Why do they still hang? I’ll answer this in the next issue&amp;nbsp;:)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Sometime in the future:&lt;/strong&gt; What&amp;nbsp;is:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;booting up? [Issue&amp;nbsp;15]&lt;/li&gt;
&lt;li&gt;&lt;span class="caps"&gt;XSS&lt;/span&gt;? [Issue&amp;nbsp;8]&lt;/li&gt;
&lt;li&gt;a good reason developers write code and give it away for free online? [Issue&amp;nbsp;21]&lt;/li&gt;
&lt;li&gt;firmware? [Issue&amp;nbsp;34]&lt;/li&gt;
&lt;li&gt;OpenType? And what are fonts anyway? [Issue&amp;nbsp;42]&lt;/li&gt;
&lt;li&gt;involved in installing a piece of software? [Issue&amp;nbsp;48]&lt;/li&gt;
&lt;li&gt;How do apps know where a file starts and ends? [Issue&amp;nbsp;49]&lt;/li&gt;
&lt;li&gt;a password hash? [Issue&amp;nbsp;63]&lt;/li&gt;
&lt;li&gt;a driver file and why do I need one? [Issue&amp;nbsp;98]&lt;/li&gt;
&lt;/ul&gt;</content><category term="Season 08"></category><category term="app"></category><category term="operating system"></category></entry><entry><title>Issue 101: Why apps crash</title><link href="https://ngjunsiang.github.io/laymansguide/issue101.html" rel="alternate"></link><published>2021-01-02T08:00:00+08:00</published><updated>2021-01-02T08:00:00+08:00</updated><author><name>J S Ng</name></author><id>tag:ngjunsiang.github.io,2021-01-02:/laymansguide/issue101.html</id><summary type="html">&lt;p&gt;An app crashes when it encounters a situation it can’t handle, or when it attempts to perform an operation that is disallowed by the operating&amp;nbsp;system.&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;strong&gt;Previously:&lt;/strong&gt; Windows systems categorise data into two types: files, and settings. Files are stored under an appropriate subfolder&amp;nbsp;in &lt;code&gt;C:\&lt;/code&gt;, while other storage devices and network locations are stored elsewhere or given their own drive letters. Settings are managed through the Windows Registry, which is stored&amp;nbsp;in &lt;code&gt;C:\Windows\System32\Config\&lt;/code&gt; and &lt;code&gt;C:\Windows\Users\Name\&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Besides general slowness, two of the most frustrating experiences we have with computers is when they crash, and when they&amp;nbsp;hang.&lt;/p&gt;
&lt;p&gt;You mean there’s a difference? Sometimes we use the two terms interchangeably, but they are really not the&amp;nbsp;same.&lt;/p&gt;
&lt;p&gt;Remember: applications are just a list of computer instructions telling the computer what to do: where to get the data, how to process it, and what to return. When the instructions make perfect sense, everything goes well. But sometimes they&amp;nbsp;don’t.&lt;/p&gt;
&lt;h2&gt;Crashing&lt;/h2&gt;
&lt;p&gt;A crash happens when the app receives &lt;strong&gt;(a)&lt;/strong&gt; a response that it does not know how to handle, or &lt;strong&gt;(b)&lt;/strong&gt; is not allowed to carry&amp;nbsp;out.&lt;/p&gt;
&lt;h3&gt;Unhandled&amp;nbsp;responses&lt;/h3&gt;
&lt;p&gt;A common error made by many programming newbies (including me) is failing to account for all the ways that things can go wrong. For example, if I am writing a simple app to read a text file and perform some calculations, an obvious step in the app is sending a request to the operating system (&lt;span class="caps"&gt;OS&lt;/span&gt;) to open the text&amp;nbsp;file.&lt;/p&gt;
&lt;p&gt;Even that simple step is fraught with many possible failures! The text file may have been locked by another app (which is writing data to the file), or the user running the app might not have permission to open the file (especially if it is in another user’s home directory), or&amp;nbsp;&amp;#8230;&lt;/p&gt;
&lt;p&gt;Well, a whole bunch of things can go wrong. And when they do, the &lt;span class="caps"&gt;OS&lt;/span&gt; throws an error. If the app does not have any code to handle that error &amp;#8230; game over, it cannot proceed and it crashes&amp;nbsp;abruptly.&lt;/p&gt;
&lt;p&gt;This is a lot more common than you think, even for experienced programmers, especially when a process that isn’t expected to throw an error actually does it. And sometimes it just can’t be helped: when your computer runs out of memory, and an app requests for more memory but doesn’t get it, and it just cant go on without that memory &amp;#8230; it&amp;nbsp;crashes.&lt;/p&gt;
&lt;h3&gt;Illegal&amp;nbsp;instructions&lt;/h3&gt;
&lt;p&gt;Memory in the computer is managed by the &lt;span class="caps"&gt;OS&lt;/span&gt; (&lt;a href="https://ngjunsiang.github.io/laymansguide/issue065.html"&gt;Issue 65&lt;/a&gt;)), which partitions it into different zones. The memory used by &lt;span class="caps"&gt;OS&lt;/span&gt; processes is protected from access by other apps (for your privacy and protection), and memory used by an app cannot be used by another app, unless it is shared memory&amp;nbsp;space.&lt;/p&gt;
&lt;p&gt;So when an app sends an instruction requesting to access memory space it does not have authorisation to, or when the &lt;span class="caps"&gt;OS&lt;/span&gt; itself attempts to access an address that it can’t (especially addresses that point to hardware devices) &amp;#8230; it crashes. An app crash just brings you back to your desktop, but an &lt;span class="caps"&gt;OS&lt;/span&gt; crash usually leads to the famous Blue Screen Of Death (&lt;span class="caps"&gt;BSOD&lt;/span&gt;).&lt;/p&gt;
&lt;p&gt;These days, OSes are better at handling crashes. If the crash occurs in the window management system (the part that lets apps create windows on screen and icons in the taskbar), Windows can often just restart it without restarting or touching the rest of the &lt;span class="caps"&gt;OS&lt;/span&gt;. But if it happens in a critical part that can’t be restarted by itself, then &amp;#8230; &lt;span class="caps"&gt;BSOD&lt;/span&gt;&amp;nbsp;:)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue summary:&lt;/strong&gt; An app crashes when it encounters a situation it can’t handle, or when it attempts to perform an operation that is disallowed by the operating&amp;nbsp;system.&lt;/p&gt;
&lt;p&gt;Definitely oversimplified for ease of understanding, but I see no point going into the technical details unless a future issue calls for&amp;nbsp;it.&lt;/p&gt;
&lt;p&gt;Before going into app hangs, I’ll need to talk about threads first. If you have heard of multithreading before, yep I am going to talk about that next&amp;nbsp;issue!&lt;/p&gt;
&lt;h2&gt;What I’ll be covering&amp;nbsp;next&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Next issue:&lt;/strong&gt; [&lt;span class="caps"&gt;LMG&lt;/span&gt; S8] Issue 102:&amp;nbsp;Threading&lt;/p&gt;
&lt;p&gt;“Many hands make light work” is true for computers as well, and I’ll go into more detail about how a computer uses its many hands to speed up the work it does :) Before that, let’s examine the simple case of an app doing only one thing at a time: the single-threaded&amp;nbsp;app.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Sometime in the future:&lt;/strong&gt; What&amp;nbsp;is:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;booting up? [Issue&amp;nbsp;15]&lt;/li&gt;
&lt;li&gt;&lt;span class="caps"&gt;XSS&lt;/span&gt;? [Issue&amp;nbsp;8]&lt;/li&gt;
&lt;li&gt;a good reason developers write code and give it away for free online? [Issue&amp;nbsp;21]&lt;/li&gt;
&lt;li&gt;firmware? [Issue&amp;nbsp;34]&lt;/li&gt;
&lt;li&gt;OpenType? And what are fonts anyway? [Issue&amp;nbsp;42]&lt;/li&gt;
&lt;li&gt;involved in installing a piece of software? [Issue&amp;nbsp;48]&lt;/li&gt;
&lt;li&gt;How do apps know where a file starts and ends? [Issue&amp;nbsp;49]&lt;/li&gt;
&lt;li&gt;a password hash? [Issue&amp;nbsp;63]&lt;/li&gt;
&lt;li&gt;a driver file and why do I need one? [Issue&amp;nbsp;98]&lt;/li&gt;
&lt;/ul&gt;</content><category term="Season 08"></category><category term="app"></category><category term="memory"></category><category term="operating system"></category></entry><entry><title>Issue 100: Where does all the app data go? A look at Windows systems</title><link href="https://ngjunsiang.github.io/laymansguide/issue100.html" rel="alternate"></link><published>2020-12-26T08:00:00+08:00</published><updated>2020-12-26T08:00:00+08:00</updated><author><name>J S Ng</name></author><id>tag:ngjunsiang.github.io,2020-12-26:/laymansguide/issue100.html</id><summary type="html">&lt;p&gt;Windows systems categorise data into two types: files, and settings. Files are stored under an appropriate subfolder&amp;nbsp;in &lt;code&gt;C:\&lt;/code&gt;, while other storage devices and network locations are stored elsewhere or given their own drive letters. Settings are managed through the Windows Registry, which is stored&amp;nbsp;in &lt;code&gt;C:\Windows\System32\Config\&lt;/code&gt; and &lt;code&gt;C:\Windows\Users\Name\&lt;/code&gt;.&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;strong&gt;Previously:&lt;/strong&gt; MacOS, Linux, and other similar systems treat everything as a file, organised into appropriate&amp;nbsp;subfolders.&lt;/p&gt;
&lt;p&gt;Previous issue: Mac- and Linux-like systems. Since the key points are so short, let’s&amp;nbsp;summarise:&lt;/p&gt;
&lt;p&gt;On Mac-like systems, the top-level folders&amp;nbsp;are&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;an &lt;code&gt;/Applications&lt;/code&gt; folder for&amp;nbsp;apps&lt;/li&gt;
&lt;li&gt;a &lt;code&gt;/Library&lt;/code&gt; folder for shared files (see &lt;a href="https://ngjunsiang.github.io/laymansguide/issue017.html"&gt;Issue 17&lt;/a&gt;), but on Mac this extends to things like sounds, profile pics, colors,&amp;nbsp;&amp;#8230;)&lt;/li&gt;
&lt;li&gt;a &lt;code&gt;/System&lt;/code&gt; folder for, well, you know&amp;nbsp;what.&lt;/li&gt;
&lt;li&gt;a &lt;code&gt;/Network&lt;/code&gt; folder for accessing resources on the network (such as shared&amp;nbsp;folders)&lt;/li&gt;
&lt;li&gt;a &lt;code&gt;/Users&lt;/code&gt; folder for accessing user folders and&amp;nbsp;files&lt;/li&gt;
&lt;li&gt;a &lt;code&gt;/Drives&lt;/code&gt; folder for accessing other storage devices (e.g. &lt;span class="caps"&gt;USB&lt;/span&gt;&amp;nbsp;drives)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Linux systems are similarly divided, but into differently named&amp;nbsp;folders.&lt;/p&gt;
&lt;p&gt;This issue: (A rant on)&amp;nbsp;Windows.&lt;/p&gt;
&lt;h2&gt;Windows-like systems (who am I kidding, there’s only&amp;nbsp;Windows)&lt;/h2&gt;
&lt;p&gt;Unlike Mac-like systems, where all data comes in the form of a file, Windows systems recognise two types of data: settings, and&amp;nbsp;files.&lt;/p&gt;
&lt;h3&gt;Files in Windows&amp;nbsp;systems&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Apps get put&amp;nbsp;in &lt;code&gt;C:\Program Files&lt;/code&gt; or &lt;code&gt;C:\Program Files (x86)&lt;/code&gt;, for 64-bit and 32-bit programs respectively&lt;sup id="fnref:1"&gt;&lt;a class="footnote-ref" href="#fn:1"&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/li&gt;
&lt;li&gt;Library? Shared files? Ha! (I’ll talk about this further&amp;nbsp;down)&lt;/li&gt;
&lt;li&gt;System files go&amp;nbsp;into &lt;code&gt;C:\Windows&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Network resources, well &amp;#8230; don’t really have a &amp;#8230; well they are a different category of location that does not start with a drive letter and instead starts&amp;nbsp;with &lt;code&gt;\\&lt;/code&gt;, unless you assign these locations to a drive letter, then they have a drive letter.&amp;nbsp;Sorta.&lt;/li&gt;
&lt;li&gt;User files go&amp;nbsp;into &lt;code&gt;C:\Users&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Other storage devices are auto-detected and assigned a drive letter, though not always&amp;nbsp;consistently.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And now we talk about&amp;nbsp;settings.&lt;/p&gt;
&lt;h3&gt;Settings in Windows&amp;nbsp;systems&lt;/h3&gt;
&lt;p&gt;Settings are stored in&amp;nbsp;the &lt;code&gt;C:\Windows\System32\Config\&lt;/code&gt; and &lt;code&gt;C:\Windows\Users\Name\&lt;/code&gt; folder, which technically makes them system files, which &amp;#8230; wait, how are apps supposed to access them&amp;nbsp;then?&lt;/p&gt;
&lt;p&gt;App developers are supposed to do it through a system library, which provides variables named&amp;nbsp;like &lt;code&gt;ApplicationData.LocalSettings&lt;/code&gt;, &lt;code&gt;ApplicationDataCompositeValue&lt;/code&gt;,&amp;nbsp;and &lt;code&gt;RoamingSettings&lt;/code&gt;. These variables let developers store and retrieve settings, which all end up stored in a system known as the &lt;strong&gt;Windows Registry&lt;/strong&gt;. And Administrators can edit them using something known as the Registry&amp;nbsp;Editor.&lt;/p&gt;
&lt;p&gt;The Windows Registry consists of 5 top-level areas (known as hives), each one beginning with the&amp;nbsp;word &lt;code&gt;HKEY_&lt;/code&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;HKEY_CLASSES_ROOT&lt;/code&gt; is for storing application settings, and file extension information (e.g. which app to use to open each type of file&amp;nbsp;extension)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;HKEY_CURRENT_USER&lt;/code&gt; is for storing settings and configuration specific to the current (logged in)&amp;nbsp;user&lt;/li&gt;
&lt;li&gt;&lt;code&gt;HKEY_LOCAL_MACHINE&lt;/code&gt; is for storing settings and configuration common to all users (e.g. default&amp;nbsp;settings)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;HKEY_USERS&lt;/code&gt; is for storing settings and configuration of each user.&amp;nbsp;The &lt;code&gt;HKEY_CURRENT_USER&lt;/code&gt; data for all users is stored here, and copied&amp;nbsp;to &lt;code&gt;HKEY_CURRENT_USER&lt;/code&gt; when they log&amp;nbsp;in.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;HKEY_CURRENT_CONFIG&lt;/code&gt; is for storing information about the computer’s configuration and&amp;nbsp;resources&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The usual way of finding out how to modify a particular setting for X is to google “registry setting for X” and proceed from&amp;nbsp;there.&lt;/p&gt;
&lt;p&gt;Logos, backgrounds, buttons, and other application data? They go&amp;nbsp;into &lt;code&gt;C:\Program Files&lt;/code&gt; (or &lt;code&gt;C:\Program Files (x86)&lt;/code&gt; if still 32-bit) for traditional Windows apps, or&amp;nbsp;into &lt;code&gt;C:\Program Files\WindowsApps&lt;/code&gt; for Windows App Store apps. What if other apps also need to use them? Then they go into &lt;del&gt;&lt;code&gt;C:\Library&lt;/code&gt;, just kidding, if only it were so easy&lt;/del&gt; &lt;code&gt;C:\Program Files\Common Files&lt;/code&gt;, but you’ll notice it’s pretty empty. Usually, they’ll be stored within the app’s folder, and you have to find out where to edit the Windows Registry so other programs know where to find them (apparently you can look&amp;nbsp;in &lt;code&gt;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\KnownDLLs&lt;/code&gt;). Whoa, wait, what happened to apps not messing around in each other’s&amp;nbsp;folders—&lt;/p&gt;
&lt;p&gt;&lt;span class="caps"&gt;OKAY&lt;/span&gt; &lt;span class="caps"&gt;MOVING&lt;/span&gt; &lt;span class="caps"&gt;ON&lt;/span&gt;—What if a user installs a program that they don’t want other users using? It goes&amp;nbsp;into &lt;code&gt;C:\Users\username\AppData\&lt;/code&gt;. User settings? They go into—nah, they don’t go into a file, they’re supposed to be settings so they go into the Windows Registry somewhere&amp;nbsp;under &lt;code&gt;HKEY_CURRENT_USER&lt;/code&gt;. Temporary files? They go&amp;nbsp;into &lt;code&gt;C:\Windows\Temp&lt;/code&gt;; isn’t that a system folder? Well yes, but if you put it&amp;nbsp;in &lt;code&gt;C:\Temp&lt;/code&gt; folks will complain and Disk Cleanup will not find&amp;nbsp;it.&lt;/p&gt;
&lt;p&gt;So to uninstall a Windows app, you run its uninstaller. Which may or may not work perfectly. Or it might remove its files but still appear in the Program List because it did a terrible job cleaning up its settings in Windows Registry. So you reinstall the program, this time using a third-party app that helps you track app installations and registry changes, so that it detects what new files/settings it creates, and then when you uninstall the program you do it through the third-party app so that it hopefully removes all traces once and for&amp;nbsp;all.&lt;/p&gt;
&lt;p&gt;Phew. And that’s all I&amp;nbsp;hope.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue summary:&lt;/strong&gt; Windows systems categorise data into two types: files, and settings. Files are stored under an appropriate subfolder&amp;nbsp;in &lt;code&gt;C:\&lt;/code&gt;, while other storage devices and network locations are stored elsewhere or given their own drive letters. Settings are managed through the Windows Registry, which is stored&amp;nbsp;in &lt;code&gt;C:\Windows\System32\Config\&lt;/code&gt; and &lt;code&gt;C:\Windows\Users\Name\&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Okay so this ran much longer than I expected. In fact, it ran so long that I split it into two issues. I promised to explain computers as simply and jargon-free as possible, and I hope I have managed to do that. I am definitely biased, and that I do not apologise for, because this newsletter issue would be half its original length if *muttering* &lt;em&gt;some&lt;/em&gt; operating systems would just follow sensible principles that &lt;em&gt;other&lt;/em&gt; operating systems have no problem following&amp;nbsp;&amp;#8230;&lt;/p&gt;
&lt;h2&gt;What I’ll be covering&amp;nbsp;next&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Next issue:&lt;/strong&gt; [&lt;span class="caps"&gt;LMG&lt;/span&gt; S8] Issue 101: Why do apps&amp;nbsp;crash?&lt;/p&gt;
&lt;p&gt;Moving on from app files and settings, the next few issues will explore common app problems. Coming up next issue: why do apps&amp;nbsp;crash?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Sometime in the future:&lt;/strong&gt; What&amp;nbsp;is:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;booting up? [Issue&amp;nbsp;15]&lt;/li&gt;
&lt;li&gt;&lt;span class="caps"&gt;XSS&lt;/span&gt;? [Issue&amp;nbsp;8]&lt;/li&gt;
&lt;li&gt;a good reason developers write code and give it away for free online? [Issue&amp;nbsp;21]&lt;/li&gt;
&lt;li&gt;firmware? [Issue&amp;nbsp;34]&lt;/li&gt;
&lt;li&gt;OpenType? And what are fonts anyway? [Issue&amp;nbsp;42]&lt;/li&gt;
&lt;li&gt;involved in installing a piece of software? [Issue&amp;nbsp;48]&lt;/li&gt;
&lt;li&gt;How do apps know where a file starts and ends? [Issue&amp;nbsp;49]&lt;/li&gt;
&lt;li&gt;a password hash? [Issue&amp;nbsp;63]&lt;/li&gt;
&lt;li&gt;a driver file and why do I need one? [Issue&amp;nbsp;98]&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="footnote"&gt;
&lt;hr /&gt;
&lt;ol&gt;
&lt;li id="fn:1"&gt;
&lt;p&gt;I really was hoping not to have to explain 32-bit vs 64-bit programs ever since &lt;a href="https://ngjunsiang.github.io/laymansguide/issue055.html"&gt;Issue 55&lt;/a&gt;), so for now let’s just say 32-bit programs are for 32-bit CPUs and 64-bit programs are for 64-bit CPUs. Unfortunately many old 32-bit apps have not caught up with the times and converted themselves to 64-bit apps, so Windows has to do hacky stuff to make old 32-bit apps work on modern 64-bit CPUs.&amp;#160;&lt;a class="footnote-backref" href="#fnref:1" title="Jump back to footnote 1 in the text"&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;</content><category term="Season 08"></category><category term="app"></category></entry><entry><title>Issue 99: Where does all the app data go? A look at Mac-like systems</title><link href="https://ngjunsiang.github.io/laymansguide/issue099.html" rel="alternate"></link><published>2020-12-19T08:00:00+08:00</published><updated>2020-12-19T08:00:00+08:00</updated><author><name>J S Ng</name></author><id>tag:ngjunsiang.github.io,2020-12-19:/laymansguide/issue099.html</id><summary type="html">&lt;p&gt;MacOS, Linux, and other similar systems treat everything as a file, organised into appropriate&amp;nbsp;subfolders.&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;strong&gt;Previously:&lt;/strong&gt; Apps generally handle three categories of files: its own (permanent) app files, (shared) user files, and (ephemeral) temporary&amp;nbsp;files.&lt;/p&gt;
&lt;p&gt;What we are here to find out is: where do these apps keep their data, and how can we get rid of them (if we really want&amp;nbsp;to)?&lt;/p&gt;
&lt;p&gt;Web apps and mobile apps will not be discussed here, because they are much more heavily sandboxed, everything gets confined into the app’s little prison, and we generally don’t have these concerns when it comes to&amp;nbsp;them.&lt;/p&gt;
&lt;h2&gt;Just one little niggle&amp;nbsp;&amp;#8230;&lt;/h2&gt;
&lt;p&gt;I am so sorry to burden you with this otherwise unrelated information, but since there are a significant number of Windows users and a significant number of MacOS users, I had to bring this up at some&amp;nbsp;point.&lt;/p&gt;
&lt;p&gt;Windows and Mac manage this differently, so we are going to have to talk about two different kinds of systems. I will spend more time on the Windows system, because it needs more&amp;nbsp;time.&lt;/p&gt;
&lt;p&gt;Let’s get the easy one out of the way first: this issue deals with&amp;nbsp;&amp;#8230;&lt;/p&gt;
&lt;h2&gt;Mac-like systems&lt;sup id="fnref:1"&gt;&lt;a class="footnote-ref" href="#fn:1"&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/h2&gt;
&lt;p&gt;On MacOS (and Linux) systems, everything is a file. All files get stashed into some kind of&amp;nbsp;folder.&lt;/p&gt;
&lt;p&gt;I personally prefer this because you have everything sorted into sensible top-level folders&lt;sup id="fnref:2"&gt;&lt;a class="footnote-ref" href="#fn:2"&gt;2&lt;/a&gt;&lt;/sup&gt;. Mac&amp;nbsp;has:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;an &lt;code&gt;/Applications&lt;/code&gt; folder for&amp;nbsp;apps&lt;/li&gt;
&lt;li&gt;a &lt;code&gt;/Library&lt;/code&gt; folder for shared files (see &lt;a href="https://ngjunsiang.github.io/laymansguide/issue017.html"&gt;Issue 17&lt;/a&gt;), but on Mac this extends to things like sounds, profile pics, colors,&amp;nbsp;&amp;#8230;)&lt;/li&gt;
&lt;li&gt;a &lt;code&gt;/System&lt;/code&gt; folder for, well, you know&amp;nbsp;what.&lt;/li&gt;
&lt;li&gt;a &lt;code&gt;/Network&lt;/code&gt; folder for accessing resources on the network (such as shared&amp;nbsp;folders)&lt;/li&gt;
&lt;li&gt;a &lt;code&gt;/Users&lt;/code&gt; folder for accessing user folders and&amp;nbsp;files&lt;/li&gt;
&lt;li&gt;a &lt;code&gt;/Drives&lt;/code&gt; folder for accessing other storage devices (e.g. &lt;span class="caps"&gt;USB&lt;/span&gt;&amp;nbsp;drives)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;and then, similar to Linux, it&amp;nbsp;has &lt;code&gt;/bin&lt;/code&gt;, &lt;code&gt;/etc&lt;/code&gt; and other weird-looking folders that we don’t need to worry about at this point. Just treat them similar to system files and try not to touch them. The apps that we install generally do not clutter up these folders&amp;nbsp;unnecessarily.&lt;/p&gt;
&lt;p&gt;Logos, backgrounds, buttons, and other application data? They go&amp;nbsp;into &lt;code&gt;/Applications&lt;/code&gt;. What if other apps also need to use them? Then they go&amp;nbsp;into &lt;code&gt;/Library&lt;/code&gt;. What if a user installs a program that they don’t want other users using? It goes&amp;nbsp;into &lt;code&gt;/Users/username/Applications&lt;/code&gt;. User settings? They go&amp;nbsp;into &lt;code&gt;/Users/username/Library&lt;/code&gt; (under a subfolder for the app). Temporary files? They go&amp;nbsp;into &lt;code&gt;/Library/Caches&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Linux systems are similarly divided, but into differently named folders. Everything is still a file, and belongs in some folder&amp;nbsp;somewhere.&lt;/p&gt;
&lt;p&gt;So to uninstall an app, you remove its files&amp;nbsp;from &lt;code&gt;/Applications&lt;/code&gt; or &lt;code&gt;/Users/username/Applications&lt;/code&gt; and&amp;nbsp;from &lt;code&gt;/Library&lt;/code&gt;, and that’s usually it. Apps are usually quite good at doing that themselves, so you don’t need to&amp;nbsp;worry.&lt;/p&gt;
&lt;p&gt;And then we deal with Windows systems in the next&amp;nbsp;issue.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue summary:&lt;/strong&gt; MacOS, Linux, and other similar systems treat everything as a file, organised into appropriate&amp;nbsp;subfolders.&lt;/p&gt;
&lt;p&gt;I’m keeping this issue short because the next issue will be much longer. *Ominous music&amp;nbsp;plays*&lt;/p&gt;
&lt;h2&gt;What I’ll be covering&amp;nbsp;next&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Next issue:&lt;/strong&gt; [&lt;span class="caps"&gt;LMG&lt;/span&gt; S8] Issue 100: Where does all the app data go? A look at Windows&amp;nbsp;systems&lt;/p&gt;
&lt;p&gt;The reasons for the difference between Mac-like systems and Windows systems is, again, historical, but I better prepare you because you are not going to like the next&amp;nbsp;issue.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Sometime in the future:&lt;/strong&gt; What&amp;nbsp;is:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;booting up? [Issue&amp;nbsp;15]&lt;/li&gt;
&lt;li&gt;&lt;span class="caps"&gt;XSS&lt;/span&gt;? [Issue&amp;nbsp;8]&lt;/li&gt;
&lt;li&gt;a good reason developers write code and give it away for free online? [Issue&amp;nbsp;21]&lt;/li&gt;
&lt;li&gt;firmware? [Issue&amp;nbsp;34]&lt;/li&gt;
&lt;li&gt;OpenType? And what are fonts anyway? [Issue&amp;nbsp;42]&lt;/li&gt;
&lt;li&gt;involved in installing a piece of software? [Issue&amp;nbsp;48]&lt;/li&gt;
&lt;li&gt;How do apps know where a file starts and ends? [Issue&amp;nbsp;49]&lt;/li&gt;
&lt;li&gt;a password hash? [Issue&amp;nbsp;63]&lt;/li&gt;
&lt;li&gt;a driver file and why do I need one? [Issue&amp;nbsp;98]&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="footnote"&gt;
&lt;hr /&gt;
&lt;ol&gt;
&lt;li id="fn:1"&gt;
&lt;p&gt;The technical term is &amp;#8220;Unix-like systems&amp;#8221;, but we don’t need to know that, even if all the Unix fanfolks are pointing pitchforks at me now.&amp;#160;&lt;a class="footnote-backref" href="#fnref:1" title="Jump back to footnote 1 in the text"&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id="fn:2"&gt;
&lt;p&gt;There’s lots of things that make less sense once we get into more detail, but fortunately we don’t do that here.&amp;#160;&lt;a class="footnote-backref" href="#fnref:2" title="Jump back to footnote 2 in the text"&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;</content><category term="Season 08"></category><category term="app"></category></entry><entry><title>Issue 98: Temporary files</title><link href="https://ngjunsiang.github.io/laymansguide/issue098.html" rel="alternate"></link><published>2020-12-12T08:00:00+08:00</published><updated>2020-12-12T08:00:00+08:00</updated><author><name>J S Ng</name></author><id>tag:ngjunsiang.github.io,2020-12-12:/laymansguide/issue098.html</id><summary type="html">&lt;p&gt;Apps generally handle three categories of files: its own (permanent) app files, (shared) user files, and (ephemeral) temporary&amp;nbsp;files.&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;strong&gt;Previously:&lt;/strong&gt; A laptop app can do practically anything, if it is running through the Administrator/root account. Sandboxing is carried out through permission&amp;nbsp;control.&lt;/p&gt;
&lt;p&gt;Thus far, I’ve summarised the salient differences between web apps, mobile apps, and laptop apps (my own terminology). I think we can move on to talking about their&amp;nbsp;similarities.&lt;/p&gt;
&lt;p&gt;There is a category of app that needs access to your device storage. It might be Youtube trying to download (part of) a stream onto your device for playback. Or it might be Tiktok trying to help you record a video for uploading. These apps need storage access so they can stash all the data into files, rather than hogging device memory with it. The same way we stash things into drawers and cabinets when we don’t need them, so they don’t clutter the space around us. And then we forget about them until we run out of space&amp;nbsp;😅&lt;/p&gt;
&lt;p&gt;You almost never see where those files appear. They get hidden &amp;#8230; &lt;em&gt;somewhere&lt;/em&gt; *gesticulates&amp;nbsp;around*.&lt;/p&gt;
&lt;h2&gt;Temporary&amp;nbsp;files&lt;/h2&gt;
&lt;p&gt;These files are short-lived; they typically don’t stick around for more than a few days. For that reason, they are known as &lt;strong&gt;temporary files&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;In a webapp, the browser generally stores these files into one of its allocated folders, somewhere&amp;nbsp;in &lt;code&gt;C:\Users\[USERNAME]\AppData\Local\Google\Chrome\User Data\Default\Cache&lt;/code&gt; or the like. They get cleared when you clear your browser cache. On a mobile or laptop app, the operating system designates a space for temporary files,&amp;nbsp;in &lt;code&gt;C:\Windows\TEMP&lt;/code&gt; or &lt;code&gt;AppData\Local\Temp&lt;/code&gt; for Windows,&amp;nbsp;or &lt;code&gt;/tmp&lt;/code&gt; on Linux. You can clear those files through Disk Cleanup in&amp;nbsp;Windows.&lt;/p&gt;
&lt;p&gt;In general, temporary files are things you are not supposed to think about too much. The operating system has ways to clear them regularly. Apps are supposed to use these standardised locations to stash temporary files, and attempting to place them anywhere else is considered impolite, like leaving your stuff lying around in an office or otherwise public&amp;nbsp;space.&lt;/p&gt;
&lt;h2&gt;User&amp;nbsp;files&lt;/h2&gt;
&lt;p&gt;But then, sometimes the app produces useful data that you want to keep around! Your journal which you keep in a Word document, photos of your cat or dog, and the copious, copious video files&amp;nbsp;&amp;#8230;&lt;/p&gt;
&lt;p&gt;Webapps have no space for you to do that. You are just supposed to save them onto your phone or laptop; the browser has no way for different users to stash their own&amp;nbsp;files.&lt;/p&gt;
&lt;p&gt;Most smartphones assume they are going to be used by a single user, and you just stash those files directly into phone storage. Not the best system, but it is what it&amp;nbsp;is.&lt;/p&gt;
&lt;p&gt;Laptops are where it gets a bit more interesting. Most laptop operating systems (OSes) assume they might be used by multiple users, each on their own account (hence the login screen), and therefore allocate separate spaces where each user may keep their stuff, inaccessible to other users except Administrators (&lt;a href="https://ngjunsiang.github.io/laymansguide/issue097.html"&gt;Issue 97&lt;/a&gt;)).&lt;/p&gt;
&lt;p&gt;On Windows, these users each have their own folder&amp;nbsp;in &lt;code&gt;C:\Users\&lt;/code&gt;; on MacOS, that’s&amp;nbsp;in &lt;code&gt;/Users/&lt;/code&gt;; on Linux, it’s&amp;nbsp;typically &lt;code&gt;/home/&lt;/code&gt;. (Don’t ask about&amp;nbsp;the &lt;code&gt;\&lt;/code&gt;s&amp;nbsp;vs &lt;code&gt;/&lt;/code&gt;s; its one of those things that’s just the way history happened and has no real technical reason behind&amp;nbsp;it.)&lt;/p&gt;
&lt;h2&gt;App&amp;nbsp;files&lt;/h2&gt;
&lt;p&gt;Of course, each app needs to have &lt;em&gt;its own space&lt;/em&gt; to keep &lt;em&gt;its own files&lt;/em&gt;, which allow it to do what it&amp;nbsp;does.&lt;/p&gt;
&lt;p&gt;Webapps get their own folder somewhere&amp;nbsp;in &lt;code&gt;C:\Users\[USERNAME]\AppData\Local\Google\Chrome\...&lt;/code&gt;, they can only see what is in that folder, and they cannot see what is in the parent folder, or sibling folders. It’s sandboxing, again (&lt;a href="https://ngjunsiang.github.io/laymansguide/issue092.html"&gt;Issue 92&lt;/a&gt;))!&lt;/p&gt;
&lt;p&gt;Mobile apps get stored&amp;nbsp;into &lt;code&gt;/data/app&lt;/code&gt; or some similar folder, and you’re not supposed to think too hard about where, because of *handwaving* &lt;em&gt;sandboxing&lt;/em&gt;. The same idea applies: The app is not supposed to know, or be able to see, where other apps store their data! Eyes on the app’s own data only, and the user’s data (you did give it permission to access storage, right?), and any temporary data which it has&amp;nbsp;created.&lt;/p&gt;
&lt;p&gt;Laptop apps get stored&amp;nbsp;in &lt;code&gt;C:\Program Files&lt;/code&gt;, and interestingly enough have some kind of civil arrangement where they agree not to delete each others’ files, although antivirus programs have this passive-aggressive low-key thing where they like to mark each others’ program files as potential malware&amp;nbsp;*shrug*.&lt;/p&gt;
&lt;h2&gt;System&amp;nbsp;files&lt;/h2&gt;
&lt;p&gt;These files were around &lt;del&gt;in the beginning of time&lt;/del&gt; when the &lt;span class="caps"&gt;OS&lt;/span&gt; was installed; that means when you bought your laptop, they were already there, and any sensible system would prevent non-Administrators from mucking around with them. Windows stashes them&amp;nbsp;in &lt;code&gt;C:\Windows&lt;/code&gt;, while MacOS and Linux store them&amp;nbsp;in &lt;code&gt;/bin/&lt;/code&gt;, &lt;code&gt;/lib&lt;/code&gt;, and various similarly opaque&amp;nbsp;folders.&lt;/p&gt;
&lt;p&gt;I might go into more detail about these, possibly in a future season when I talk about operating systems, but for now we are done talking about categories of files.&amp;nbsp;Phew!&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue summary:&lt;/strong&gt; Apps generally handle three categories of files: its own (permanent) app files, (shared) user files, and (ephemeral) temporary&amp;nbsp;files.&lt;/p&gt;
&lt;p&gt;In reality, there are a whole bunch of different filetypes and other little details that apps need to worry about, but this is a newsletter for layfellas so let’s start&amp;nbsp;simple.&lt;/p&gt;
&lt;h2&gt;What I’ll be covering&amp;nbsp;next&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Next issue:&lt;/strong&gt; [&lt;span class="caps"&gt;LMG&lt;/span&gt; S8] Issue 99: Where does all the app data go? A look at Mac-like&amp;nbsp;systems&lt;/p&gt;
&lt;p&gt;I separated temporary files and user files in this issue. Temp files are files that come and go, like stray cats, while user files are shared with other apps as well and there’s really not very much that you can predict about them except hope users don’t do anything too crazy. System files are strictly off-limits so don’t even think about&amp;nbsp;that.&lt;/p&gt;
&lt;p&gt;But meanwhile, as an app developer, even after you exclude the above categories of files, there is still a whole bunch of questions you kinda need to worry about at some&amp;nbsp;point:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;where do I store my logos and backgrounds and buttons and other&amp;nbsp;data?&lt;/li&gt;
&lt;li&gt;where do I keep my&amp;nbsp;settings?&lt;/li&gt;
&lt;li&gt;where do I keep user&amp;nbsp;settings?&lt;/li&gt;
&lt;li&gt;if my program is meant to make a &lt;span class="caps"&gt;USB&lt;/span&gt; device useable, where do I drop the driver files? (Yep, that’s gonna need its own&amp;nbsp;issue)&lt;/li&gt;
&lt;li&gt;what if someone uninstalls my program but I want them to be able to keep their settings around in case they decide to reinstall and then it can feel exactly the way they left&amp;nbsp;off?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Yeah I have no idea who actually thinks about that last question either, but it’s something that seems to get asked in every software uninstallation&amp;nbsp;*shrug*.&lt;/p&gt;
&lt;p&gt;So let’s get into that in the next&amp;nbsp;issue.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Sometime in the future:&lt;/strong&gt; What&amp;nbsp;is:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;booting up? [Issue&amp;nbsp;15]&lt;/li&gt;
&lt;li&gt;&lt;span class="caps"&gt;XSS&lt;/span&gt;? [Issue&amp;nbsp;8]&lt;/li&gt;
&lt;li&gt;a good reason developers write code and give it away for free online? [Issue&amp;nbsp;21]&lt;/li&gt;
&lt;li&gt;firmware? [Issue&amp;nbsp;34]&lt;/li&gt;
&lt;li&gt;OpenType? And what are fonts anyway? [Issue&amp;nbsp;42]&lt;/li&gt;
&lt;li&gt;involved in installing a piece of software? [Issue&amp;nbsp;48]&lt;/li&gt;
&lt;li&gt;How do apps know where a file starts and ends? [Issue&amp;nbsp;49]&lt;/li&gt;
&lt;li&gt;a password hash? [Issue&amp;nbsp;63]&lt;/li&gt;
&lt;li&gt;a driver file and why do I need one? [Issue&amp;nbsp;98]&lt;/li&gt;
&lt;/ul&gt;</content><category term="Season 08"></category><category term="cache"></category></entry><entry><title>Issue 97: Laptop apps</title><link href="https://ngjunsiang.github.io/laymansguide/issue097.html" rel="alternate"></link><published>2020-12-05T08:00:00+08:00</published><updated>2020-12-05T08:00:00+08:00</updated><author><name>J S Ng</name></author><id>tag:ngjunsiang.github.io,2020-12-05:/laymansguide/issue097.html</id><summary type="html">&lt;p&gt;A laptop app can do practically anything, if it is running through the Administrator/root account. Sandboxing is carried out through permission&amp;nbsp;control.&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;strong&gt;Previously:&lt;/strong&gt; Mobile apps are sandboxed by the operating system. As a result, they have to bundle all the libraries they need, and are not allowed to share libraries with other apps. This results in mobile apps with huge&amp;nbsp;filesizes.&lt;/p&gt;
&lt;p&gt;This issue is going to be short, because laptop apps are … well, almost unlimited in what they can&amp;nbsp;do.&lt;/p&gt;
&lt;p&gt;Web apps are sandboxed by the web browser. Mobile apps are sandboxed by the mobile operating system (&lt;span class="caps"&gt;OS&lt;/span&gt;). Laptop apps are sandboxed by hte desktop &lt;span class="caps"&gt;OS&lt;/span&gt; (yup, Windows on laptop and desktop is practically the&amp;nbsp;same).&lt;/p&gt;
&lt;p&gt;The main difference here lies in the difference between a mobile and desktop &lt;span class="caps"&gt;OS&lt;/span&gt;. Mobile OSes do not allow mobile apps to share libraries with other apps, and restrict their privileges (&lt;a href="https://ngjunsiang.github.io/laymansguide/issue096.html"&gt;Issue 96&lt;/a&gt;)). Desktop OSes, on the other hand, let you do anything that is computationally possible … if you have&amp;nbsp;permission.&lt;/p&gt;
&lt;h2&gt;The Admin&amp;nbsp;account&lt;/h2&gt;
&lt;p&gt;A desktop &lt;span class="caps"&gt;OS&lt;/span&gt; often has an all-powerful user, known as the Administrator (Windows/MacOS), or root user (Linux). This user does not need permission to do anything. But with great power comes great responsibility, and with an admin account it is all too easy to do something that renders the computer&amp;nbsp;unuseable.&lt;/p&gt;
&lt;p&gt;So lower-privilege accounts exist—these are the user accounts. Logging in as a user gives you limited privileges: often you cannot change &lt;span class="caps"&gt;OS&lt;/span&gt; files, install or remove apps, or do anything risky. This is, for the most part, how desktop OSes sandbox the computer environment from damage by other&amp;nbsp;apps.&lt;/p&gt;
&lt;h2&gt;What an admin can&amp;nbsp;do&lt;/h2&gt;
&lt;p&gt;So what happens when you run an app on an admin&amp;nbsp;account?&lt;/p&gt;
&lt;p&gt;This app&amp;nbsp;can:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Edit, delete, rename &lt;span class="caps"&gt;OS&lt;/span&gt;-related&amp;nbsp;files&lt;/li&gt;
&lt;li&gt;Create new “virtual” (emulated) hardware devices, and manage drivers for&amp;nbsp;it&lt;/li&gt;
&lt;li&gt;Send data to any device, or receive data from any&amp;nbsp;device&lt;/li&gt;
&lt;li&gt;Make changes to storage devices, including the disk where the &lt;span class="caps"&gt;OS&lt;/span&gt; itself is installed (but not the partition&lt;sup id="fnref:1"&gt;&lt;a class="footnote-ref" href="#fn:1"&gt;1&lt;/a&gt;&lt;/sup&gt; where the &lt;span class="caps"&gt;OS&lt;/span&gt; is&amp;nbsp;installed)&lt;/li&gt;
&lt;li&gt;Run programs in the&amp;nbsp;background&lt;/li&gt;
&lt;li&gt;Send data over the network to any &lt;span class="caps"&gt;IP&lt;/span&gt; address, over any port (&lt;a href="https://ngjunsiang.github.io/laymansguide/issue033.html"&gt;Issue 33&lt;/a&gt;))&lt;/li&gt;
&lt;li&gt;Prevent other programs from doing so (&lt;a href="https://ngjunsiang.github.io/laymansguide/issue034.html"&gt;Issue 34&lt;/a&gt;))&lt;/li&gt;
&lt;li&gt;Install libraries that can be used by other&amp;nbsp;programs&lt;/li&gt;
&lt;li&gt;Access &lt;span class="caps"&gt;OS&lt;/span&gt; settings and make changes that affect &lt;span class="caps"&gt;OS&lt;/span&gt;&amp;nbsp;operation&lt;/li&gt;
&lt;li&gt;&amp;#8230; and many more&amp;nbsp;things!&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;User Account&amp;nbsp;Control&lt;/h2&gt;
&lt;p&gt;What if a user needs access to some of these permissions (but not all)? Does that mean they need to become an&amp;nbsp;Admin?&lt;/p&gt;
&lt;p&gt;Windows, and other OSes as well, usually have some way to give users limited permissions for some tasks. Windows uses User Account Control, which pops up a dialog box to alert the user. If the user gives permission for the app to proceed, then it is able to do so. If it is running on a user account, it can only perform tasks that the user account is allowed to perform. Linux uses the concept of groups; for a user to have permission to access bluetooth, for example, the linux &lt;span class="caps"&gt;OS&lt;/span&gt; often requires the user to be added to&amp;nbsp;the &lt;code&gt;bluetooth&lt;/code&gt; group in the &lt;span class="caps"&gt;OS&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue summary:&lt;/strong&gt; A laptop app can do practically anything, if it is running through the Administrator/root account. Sandboxing is carried out through permission&amp;nbsp;control.&lt;/p&gt;
&lt;p&gt;This is the reason why you should still buy a machine with a desktop operating system if you plan to be doing anything really productive; the sandboxing systems of web and mobile apps ultimately still impose a significant limit what you can do with the device. This is intentional; it is done for your safety! But if you want your device to do more, you’ll often need to override these “safety limits”, and that is where desktop operating systems come&amp;nbsp;in.&lt;/p&gt;
&lt;h2&gt;What I’ll be covering&amp;nbsp;next&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Next issue:&lt;/strong&gt; [&lt;span class="caps"&gt;LMG&lt;/span&gt; S8] Issue 98: Temporary&amp;nbsp;files&lt;/p&gt;
&lt;p&gt;Next issue is going to round off this mini-arc on how different kinds of apps operate. In the process of doing whatever it is they do, apps often generate temporary files that can be safely removed. How does this work for web apps and mobile apps? And for laptop&amp;nbsp;apps?&lt;/p&gt;
&lt;p&gt;From there, I’ll expand to talking about how apps store their data on and retrieve their data from the operating&amp;nbsp;system.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Sometime in the future:&lt;/strong&gt; What&amp;nbsp;is:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;booting up? [Issue&amp;nbsp;15]&lt;/li&gt;
&lt;li&gt;&lt;span class="caps"&gt;XSS&lt;/span&gt;? [Issue&amp;nbsp;8]&lt;/li&gt;
&lt;li&gt;a good reason developers write code and give it away for free online? [Issue&amp;nbsp;21]&lt;/li&gt;
&lt;li&gt;firmware? [Issue&amp;nbsp;34]&lt;/li&gt;
&lt;li&gt;OpenType? And what are fonts anyway? [Issue&amp;nbsp;42]&lt;/li&gt;
&lt;li&gt;What is involved in installing a piece of software? [Issue&amp;nbsp;48]&lt;/li&gt;
&lt;li&gt;How do apps know where a file starts and ends? [Issue&amp;nbsp;49]&lt;/li&gt;
&lt;li&gt;What is a password hash? [Issue&amp;nbsp;63]&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="footnote"&gt;
&lt;hr /&gt;
&lt;ol&gt;
&lt;li id="fn:1"&gt;
&lt;p&gt;I’ll talk about partitions in a future issue, when I move on to hardware devices&amp;#160;&lt;a class="footnote-backref" href="#fnref:1" title="Jump back to footnote 1 in the text"&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;</content><category term="Season 08"></category><category term="app"></category><category term="operating system"></category></entry><entry><title>Issue 96: Why are mobile apps so large in size?</title><link href="https://ngjunsiang.github.io/laymansguide/issue096.html" rel="alternate"></link><published>2020-11-28T08:00:00+08:00</published><updated>2020-11-28T08:00:00+08:00</updated><author><name>J S Ng</name></author><id>tag:ngjunsiang.github.io,2020-11-28:/laymansguide/issue096.html</id><summary type="html">&lt;p&gt;Mobile apps are sandboxed by the operating system. As a result, they have to bundle all the libraries they need, and are not allowed to share libraries with other apps. This results in mobile apps with huge&amp;nbsp;filesizes.&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;strong&gt;Previously:&lt;/strong&gt; Mobile apps, unlike web apps, can bundle resources and libraries to be installed to a mobile device. They can also request access to storage, and typically have a higher memory limit than web&amp;nbsp;apps.&lt;/p&gt;
&lt;p&gt;In the process of creating an app, a developer often needs to use libraries (&lt;a href="https://ngjunsiang.github.io/laymansguide/issue017.html"&gt;Issue 17&lt;/a&gt;)), which are ready-packaged chunks of code she can run without having to write the code herself. Some provide core functions (e.g. sending information via the Internet, or checking if a data connection is available), while some provide optional features (e.g. mobile payments, or user feedback&amp;nbsp;systems).&lt;/p&gt;
&lt;p&gt;Libraries that provide core functions are typically provided by the operating system (&lt;span class="caps"&gt;OS&lt;/span&gt;), which ultimately controls the device’s resources, but all else have to be pulled in by the app,&amp;nbsp;somehow.&lt;/p&gt;
&lt;h2&gt;Web apps vs mobile&amp;nbsp;apps&lt;/h2&gt;
&lt;p&gt;Web apps, which I covered in &lt;a href="https://ngjunsiang.github.io/laymansguide/issue094.html"&gt;Issue 94&lt;/a&gt;), pull in any resources they need through web requests. This includes any libraries that they need. The browser allows it to do this, but prevents access to most parts of the operating system, and allows limited access to camera, sound, storage, etc. The sandboxing features of the browser make web apps generally safer to&amp;nbsp;access.&lt;/p&gt;
&lt;p&gt;A mobile app, on the other hand, is sandboxed by the operating system. Most of the resources it needs have to be present at the time of running the app, and that includes libraries. In an unsandboxed environment, commonly used libraries (e.g. mobile payment libraries) could be installed in the &lt;span class="caps"&gt;OS&lt;/span&gt; and shared by the apps. But this opens up a means of unauthorised access to multiple apps: hack this library successfully, and all other apps on the &lt;span class="caps"&gt;OS&lt;/span&gt; are also&amp;nbsp;affected!&lt;/p&gt;
&lt;p&gt;The sandboxing system in a mobile device does not allow this. Each app must bundle all the libraries it requires, to be installed into storage after downloading. This way, if an app has one or more libraries compromised, it would at least not expose the user’s data in other&amp;nbsp;apps.&lt;/p&gt;
&lt;h2&gt;Libraries in a mobile&amp;nbsp;app&lt;/h2&gt;
&lt;p&gt;The tradeoff to separating all these mobile apps and preventing sharing, is that each app now comes with its own copy of all the libraries it needs. And the file size can really add up—you already see it in the huge app sizes. I unbundled the installation package of a popular shopping app, Lazada, just to see what is inside&amp;nbsp;it.&lt;/p&gt;
&lt;p&gt;The list is way too long to post as an image, or even as text; it has over 300,000 code functions bundled inside! I should note that I am not an Android developer and can’t tell you very much about whether these libraries are absolutely necessary, but here are some noteworthy libraries included that I can make an educated guess&amp;nbsp;about:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Libraries to translate code from one programming language to another (often to translate an easier language into a faster or better-supported&amp;nbsp;language)&lt;/li&gt;
&lt;li&gt;Compatibility fallback &lt;span class="amp"&gt;&amp;amp;&lt;/span&gt; device evaluation libraries (probably for devices on older Android&amp;nbsp;versions)&lt;/li&gt;
&lt;li&gt;Layout libraries (for calculating placement of window frames in devices with different screen&amp;nbsp;sizes)&lt;/li&gt;
&lt;li&gt;Graphics, media, augmented reality (&lt;span class="caps"&gt;AR&lt;/span&gt;) libraries (for graphics rendering, video playback, capturing images from camera,&amp;nbsp;etc)&lt;/li&gt;
&lt;li&gt;System, network, version detection and updating,&amp;nbsp;etc&lt;/li&gt;
&lt;li&gt;Animation libraries (I see one from&amp;nbsp;AirBnB)&lt;/li&gt;
&lt;li&gt;Analytics libraries (to track user and ad engagement, and do A/B&amp;nbsp;testing)&lt;/li&gt;
&lt;li&gt;Debug, crash reporting, logging libraries (for troubleshooting app&amp;nbsp;crashes)&lt;/li&gt;
&lt;li&gt;Integration libraries (for login using &lt;span class="caps"&gt;FB&lt;/span&gt; and other&amp;nbsp;accounts)&lt;/li&gt;
&lt;li&gt;Maps,&amp;nbsp;location&lt;/li&gt;
&lt;li&gt;Search, image search, &lt;span class="caps"&gt;QR&lt;/span&gt; code, user feed, and related&amp;nbsp;services&lt;/li&gt;
&lt;li&gt;Database access (it seems to use Google Firebase, in addition to&amp;nbsp;others)&lt;/li&gt;
&lt;li&gt;Mobile&amp;nbsp;payments&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;and then there is the app itself, which contains code&amp;nbsp;for:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Address validation, checkout,&amp;nbsp;delivery&lt;/li&gt;
&lt;li&gt;User feed and homepage, login management,&amp;nbsp;recommendations&lt;/li&gt;
&lt;li&gt;Search&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;and many others which I don’t know&amp;nbsp;about.&lt;/p&gt;
&lt;h2&gt;Why aren’t web apps so huge&amp;nbsp;then?&lt;/h2&gt;
&lt;p&gt;They are! But they don’t need many of these (e.g. code translation and compatibility), and most of the libraries in 1–13 would have been loaded separately from the main page (see &lt;a href="https://ngjunsiang.github.io/laymansguide/issue078.html"&gt;Issue 78&lt;/a&gt;) for a visual example). Much of the functionality would not need to be loaded or installed upfront, only when it is required (e.g. map&amp;nbsp;display).&lt;/p&gt;
&lt;p&gt;For a web app, many more functions would also have been offloaded to Lazada’s servers, such as address validation. On a mobile app, this code is included upon installation to reduce data&amp;nbsp;usage.&lt;/p&gt;
&lt;p&gt;More importantly, you have little idea how large a web app really is, since you are never shown its filesize anywhere&amp;nbsp;;)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue summary:&lt;/strong&gt; Mobile apps are sandboxed by the operating system. As a result, they have to bundle all the libraries they need, and are not allowed to share libraries with other apps. This results in mobile apps with huge&amp;nbsp;filesizes.&lt;/p&gt;
&lt;p&gt;It’s worth thinking about what this says whenever we hear about so much data being transmitted over the internet. Much of this data is actually duplicated data (for security of inefficiency reasons), or metadata (for data management), or overhead data (because of the way the data is packaged). Just like Amazon&amp;nbsp;packaging!&lt;/p&gt;
&lt;h2&gt;What I’ll be covering&amp;nbsp;next&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Next issue:&lt;/strong&gt; [&lt;span class="caps"&gt;LMG&lt;/span&gt; S8] Issue 97: Laptop&amp;nbsp;apps&lt;/p&gt;
&lt;p&gt;Finally we can move on to more fully explore the complexity of apps that integrate more closely with the operating system: laptop&amp;nbsp;apps!&lt;/p&gt;
&lt;p&gt;This should be enough of a primer before I go on to talk about where all this app data goes, and then about app installation and uninstallation (and hence strike out another “sometime in the future” question, woohoo!&amp;nbsp;🙌)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Sometime in the future:&lt;/strong&gt; What&amp;nbsp;is:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;booting up? [Issue&amp;nbsp;15]&lt;/li&gt;
&lt;li&gt;&lt;span class="caps"&gt;XSS&lt;/span&gt;? [Issue&amp;nbsp;8]&lt;/li&gt;
&lt;li&gt;a good reason developers write code and give it away for free online? [Issue&amp;nbsp;21]&lt;/li&gt;
&lt;li&gt;firmware? [Issue&amp;nbsp;34]&lt;/li&gt;
&lt;li&gt;OpenType? And what are fonts anyway? [Issue&amp;nbsp;42]&lt;/li&gt;
&lt;li&gt;What is involved in installing a piece of software? [Issue&amp;nbsp;48]&lt;/li&gt;
&lt;li&gt;How do apps know where a file starts and ends? [Issue&amp;nbsp;49]&lt;/li&gt;
&lt;li&gt;What is a password hash? [Issue&amp;nbsp;63]&lt;/li&gt;
&lt;/ul&gt;</content><category term="Season 08"></category><category term="app"></category></entry><entry><title>Issue 95: What’s in a mobile app?</title><link href="https://ngjunsiang.github.io/laymansguide/issue095.html" rel="alternate"></link><published>2020-11-21T08:00:00+08:00</published><updated>2020-11-21T08:00:00+08:00</updated><author><name>J S Ng</name></author><id>tag:ngjunsiang.github.io,2020-11-21:/laymansguide/issue095.html</id><summary type="html">&lt;p&gt;Mobile apps, unlike web apps, can bundle resources and libraries to be installed to a mobile device. They can also request access to storage, and typically have a higher memory limit than web&amp;nbsp;apps.&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;strong&gt;Previously:&lt;/strong&gt; Web apps require the browser to request memory on their behalf, and thus their memory usage shows up under the browser process in the &lt;span class="caps"&gt;OS&lt;/span&gt; Task Manager. Web apps use this data to store a more convenient (but larger) representation of the webpage document, and to store the data needed by the&amp;nbsp;app.&lt;/p&gt;
&lt;p&gt;“Why use the mobile app when there’s already a&amp;nbsp;website?”&lt;/p&gt;
&lt;p&gt;“Why even have a mobile app that looks almost exactly like the&amp;nbsp;website?”&lt;/p&gt;
&lt;p&gt;I’m not going to answer from an aesthetic or user experience point of view, you’re all experts in your own preferences :) Instead, I’ll focus on whats actually under the hood in this newsletter&amp;nbsp;issue.&lt;/p&gt;
&lt;p&gt;If you haven’t read &lt;a href="https://ngjunsiang.github.io/laymansguide/issue093.html"&gt;Issue 93&lt;/a&gt;) on web apps (a.k.a. websites), I’d recommend you do that for the full context, because in this issue I’ll highlight some key differences between web apps and mobile&amp;nbsp;apps.&lt;/p&gt;
&lt;h2&gt;Resources&lt;/h2&gt;
&lt;p&gt;Web apps have to request every single image, video, non-text object on the page via a web request. Caching (&lt;a href="https://ngjunsiang.github.io/laymansguide/issue039.html"&gt;Issue 39&lt;/a&gt;))—storing these resources for offline use—can reduce subsequent load times, but the first load will still be the most&amp;nbsp;painful.&lt;/p&gt;
&lt;p&gt;A mobile app can package the most common, unchanging resources (logos, button images, backgrounds, etc) into the mobile app itself, so they can be loaded directly in the app, without having to make a web request and wait for the response. This lets it load faster (theoretically … in practice, many apps still have to retrieve other data from the server, so the loading speed improvement is&amp;nbsp;marginal)&lt;/p&gt;
&lt;h2&gt;Flexibility&lt;/h2&gt;
&lt;p&gt;The document object model, or &lt;span class="caps"&gt;DOM&lt;/span&gt; (&lt;a href="https://ngjunsiang.github.io/laymansguide/issue094.html"&gt;Issue 94&lt;/a&gt;)) is how web apps keep track of all the elements and their contents on a page, but it is not the most efficient way to do so. A mobile app has more choice in deciding which user interface library (&lt;a href="https://ngjunsiang.github.io/laymansguide/issue017.html"&gt;Issue 17&lt;/a&gt;)) it wants to&amp;nbsp;use.&lt;/p&gt;
&lt;h2&gt;Storage&amp;nbsp;access&lt;/h2&gt;
&lt;p&gt;A mobile app can request permission to access storage on the mobile device, allowing it to store files (images, data, &amp;#8230;) on the device without having to interrupt the user each time. It is not limited only to browser storage interfaces (localstorage, sessionstorage) and browser databases (IndexedDB)—see &lt;a href="https://ngjunsiang.github.io/laymansguide/issue093.html"&gt;Issue 93&lt;/a&gt;)—but can use other kinds of interfaces and databases, if they are available on the mobile device, or bundled into the mobile&amp;nbsp;app.&lt;/p&gt;
&lt;h2&gt;Memory&amp;nbsp;use&lt;/h2&gt;
&lt;p&gt;Both Android and iOS impose a memory limit on each app that is running. And they treat a mobile browser as a single app, despite all the web apps running inside it. So a web app has to share that limit with all the other web apps running in the mobile browser (which is why your tabs have to reload so often—they are also cleared&amp;nbsp;often!).&lt;/p&gt;
&lt;p&gt;On the other hand, a mobile app can have that per-app limit all to&amp;nbsp;itself.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;All told, a mobile app has more resources, which it requests directly from the &lt;span class="caps"&gt;OS&lt;/span&gt; instead of via the web browser, and it has more freedom in using those resources.
How so? And more importantly, why are some mobile apps just so darn &lt;em&gt;huge&lt;/em&gt;?&lt;/p&gt;
&lt;p&gt;This and mobile app sandboxing explained next&amp;nbsp;issue.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue summary:&lt;/strong&gt; Mobile apps, unlike web apps, can bundle resources and libraries to be installed to a mobile device. They can also request access to storage, and typically have a higher memory limit than web&amp;nbsp;apps.&lt;/p&gt;
&lt;p&gt;Mobile apps are a bit of a weak spot for me since I haven’t had as much experience here as I had in other areas, but nonetheless the limits of sandboxing are pretty visible. For the most part, we have accepted this tradeoff between size and security since storage space became much cheaper. But this tradeoff is also apparent not only in software, but also in business management and other areas: to increase security, we often also have to increase&amp;nbsp;bloat.&lt;/p&gt;
&lt;h2&gt;What I’ll be covering&amp;nbsp;next&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Next issue:&lt;/strong&gt; [&lt;span class="caps"&gt;LMG&lt;/span&gt; S8] Issue 96: Why are mobile apps so large in&amp;nbsp;size?&lt;/p&gt;
&lt;p&gt;Remember the days when most apps we downloaded and installed on a laptop were &lt;span class="caps"&gt;2MB&lt;/span&gt; or less? Today, mobile apps are many times that size. This is partly because of the way sandboxing is done for mobile apps. How so? I’ll go into more detail next week&amp;nbsp;;)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Sometime in the future:&lt;/strong&gt; What&amp;nbsp;is:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;booting up? [Issue&amp;nbsp;15]&lt;/li&gt;
&lt;li&gt;&lt;span class="caps"&gt;XSS&lt;/span&gt;? [Issue&amp;nbsp;8]&lt;/li&gt;
&lt;li&gt;a good reason developers write code and give it away for free online? [Issue&amp;nbsp;21]&lt;/li&gt;
&lt;li&gt;firmware? [Issue&amp;nbsp;34]&lt;/li&gt;
&lt;li&gt;OpenType? And what are fonts anyway? [Issue&amp;nbsp;42]&lt;/li&gt;
&lt;li&gt;What is involved in installing a piece of software? [Issue&amp;nbsp;48]&lt;/li&gt;
&lt;li&gt;How do apps know where a file starts and ends? [Issue&amp;nbsp;49]&lt;/li&gt;
&lt;li&gt;What is a password hash? [Issue&amp;nbsp;63]&lt;/li&gt;
&lt;/ul&gt;</content><category term="Season 08"></category><category term="app"></category><category term="memory"></category><category term="operating system"></category></entry><entry><title>Issue 94: Why do web browsers take up so much memory?</title><link href="https://ngjunsiang.github.io/laymansguide/issue094.html" rel="alternate"></link><published>2020-11-14T08:00:00+08:00</published><updated>2020-11-14T08:00:00+08:00</updated><author><name>J S Ng</name></author><id>tag:ngjunsiang.github.io,2020-11-14:/laymansguide/issue094.html</id><summary type="html">&lt;p&gt;Web apps require the browser to request memory on their behalf, and thus their memory usage shows up under the browser process in the &lt;span class="caps"&gt;OS&lt;/span&gt; Task Manager. Web apps use this data to store a more convenient (but larger) representation of the webpage document, and to store the data needed by the&amp;nbsp;app.&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;strong&gt;Previously:&lt;/strong&gt; Web apps have limited access to the device’ storage, and can only store data in browser-managed databases. Progressive Web Apps (PWAs) can additionally register service workers that run in the background. Because they are so cleanly sandboxed, they can be easily removed by clearing the browser cache and storage, and deregistering any service workers&amp;nbsp;manually.&lt;/p&gt;
&lt;p&gt;Apps once lived on a computer. You double-clicked them or pressed Enter or right-clicked Run, a window pops up and a rectangle appears on your taskbar. If Task Manager is showing you that it is using up gobs of memory, you just End Task and the rectangle disappears. Later in this season I’ll say more about what it is like to live in a computer, but we are on web apps&amp;nbsp;now.&lt;/p&gt;
&lt;p&gt;Web apps are somewhat more complicated. Because they are so tidily sandboxed (&lt;a href="https://ngjunsiang.github.io/laymansguide/issue092.html"&gt;Issue 92&lt;/a&gt;)), they cannot actually live on your computer. Instead, they live in your&amp;nbsp;browser.&lt;/p&gt;
&lt;h2&gt;Living in a web&amp;nbsp;browser&lt;/h2&gt;
&lt;p&gt;Living in a computer means that the operating system (&lt;span class="caps"&gt;OS&lt;/span&gt;) takes care of you; it gives you the memory and disk space you need, gives you &lt;span class="caps"&gt;CPU&lt;/span&gt; time to run your processes, and gives you access to devices (such as the screen and&amp;nbsp;keyboard).&lt;/p&gt;
&lt;p&gt;When you live in the browser, the browser takes care of you. Everything you need is requested from the operating system (&lt;span class="caps"&gt;OS&lt;/span&gt;) by the browser. The space that the web app uses in localstorage, sessionstorage, IndexedDB, and the cache, is space that the browser requested. The &lt;span class="caps"&gt;CPU&lt;/span&gt; cycles that the web app needs are cycles that the browser has&amp;nbsp;requested.&lt;/p&gt;
&lt;p&gt;When you open the &lt;span class="caps"&gt;OS&lt;/span&gt; Task Manager, where do these requests show up? Under (one of) the browser processes, naturally. If you have more than 20 browser tabs open for more than 5 apps, it shouldn’t be surprising that they are using a lot of memory; I’ll go into why shortly. More worryingly, that’s not helpful if you’re trying to figure out which browser tab to close so you can play your memory-consuming video&amp;nbsp;game.&lt;/p&gt;
&lt;p&gt;Only the browser has that information; you will have to open the browser’s Task Manager (another google away) to see that&amp;nbsp;information.&lt;/p&gt;
&lt;h2&gt;A web app’s&amp;nbsp;needs&lt;/h2&gt;
&lt;p&gt;I have a browser tab open now, with a Google Sheet loaded. What is the Google Sheet app doing on that page? Let’s open DevTools and find&amp;nbsp;out.&lt;/p&gt;
&lt;p&gt;DevTools has a really cool tab labelled “Memory”, and it has a nice visual depiction of what the app is doing with all that&amp;nbsp;memory:&lt;/p&gt;
&lt;p&gt;&lt;img alt="Firefox DevTools, showing the Memory tab. The app is using 83.84MB of memory, and 32MiB of that is used by objects." src="https://ngjunsiang.github.io/laymansguide/issue094_01.png" /&gt;&lt;br /&gt;
&lt;em&gt;DevTools in Firefox lets you inspect the memory that web apps use.&lt;br /&gt;The Memory tab shows what is stored in memory.&lt;br /&gt;Most of the memory here is being taken up by javascript&amp;nbsp;objects.&lt;/em&gt;    &lt;/p&gt;
&lt;p&gt;Javascript &lt;code&gt;object&lt;/code&gt;s here are Javascript’s own internal representation of data, which is quite similar to a document database’s format. Altogether, they take up 32 MiB of memory space (difference between &lt;span class="caps"&gt;MB&lt;/span&gt; and MiB is covered in &lt;a href="https://ngjunsiang.github.io/laymansguide/issue040.html"&gt;Issue 40&lt;/a&gt;)). Google Sheets is juggling a lot of data internally, data which is not stored in IndexedDB or&amp;nbsp;localstorage!&lt;/p&gt;
&lt;p&gt;&lt;code&gt;other&lt;/code&gt;, taking up 15 MiB, seems to be pointing to a javascript library that Google Sheets is using to render the&amp;nbsp;spreadsheet.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;strings&lt;/code&gt; are simpler&amp;nbsp;than &lt;code&gt;object&lt;/code&gt;s, each one representing a snippet of text, or possibly even a number. They only take up&amp;nbsp;5MiB. &lt;code&gt;scripts&lt;/code&gt; are the internally stored scripts that the page is executing; they take up 11&amp;nbsp;MiB.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;domNode&lt;/code&gt; is where it gets interesting. We are used to seeing &lt;span class="caps"&gt;HTML&lt;/span&gt; documents (&lt;a href="https://ngjunsiang.github.io/laymansguide/issue050.html"&gt;Issue 50&lt;/a&gt;)) as a plain text document with lots of formatting, but in a browser it becomes more than just text. Each part of the page, an &lt;span class="caps"&gt;HTML&lt;/span&gt; element, can have its properties changed by Javascript as the page reacts to new data, or to user&amp;nbsp;input.&lt;/p&gt;
&lt;h2&gt;The &lt;span class="caps"&gt;HTML&lt;/span&gt; Document Object&amp;nbsp;Model&lt;/h2&gt;
&lt;p&gt;It would be too computationally taxing to keep scanning through the text document to figure out which part of the page is meant to be changed. Instead, the browser has its own way of storing the &lt;em&gt;hierarchy&lt;/em&gt; of elements: each menu option falls under a menu heading, which falls under the navigation bar, which falls under the header, which falls under the main document, and so on. If each browser had its own way of doing that, a web developer would have to learn all of them to make a webpage that worked across all browsers; that’s&amp;nbsp;terrible!&lt;/p&gt;
&lt;p&gt;Instead, the web standardised on one way of doing so: the &lt;span class="caps"&gt;HTML&lt;/span&gt; &lt;strong&gt;Document Object Model (&lt;span class="caps"&gt;DOM&lt;/span&gt;)&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Internally, a web browser converts the &lt;span class="caps"&gt;HTML&lt;/span&gt; page into a &lt;span class="caps"&gt;DOM&lt;/span&gt;—a data structure that makes it easy to find the specific &lt;span class="caps"&gt;HTML&lt;/span&gt; element (or elements) that need to be modified by each function. The &lt;span class="caps"&gt;HTML&lt;/span&gt; &lt;span class="caps"&gt;DOM&lt;/span&gt; for the page I’m on takes up 14 MiB, which may sound like a lot, until you remember that each element also has associated metadata stored along with its content. And Google Sheets has lots of&amp;nbsp;elements!&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;&lt;strong&gt;Issue summary:&lt;/strong&gt; Web apps require the browser to request memory on their behalf, and thus their memory usage shows up under the browser process in the &lt;span class="caps"&gt;OS&lt;/span&gt; Task Manager. Web apps use this data to store a more convenient (but larger) representation of the webpage document, and to store the data needed by the&amp;nbsp;app.&lt;/p&gt;
&lt;p&gt;And that is how a web app uses up 84MiB of memory space. If you have multiple tabs running the same app (e.g. multiple Google Sheets open), some of the memory can be shared (&lt;a href="https://ngjunsiang.github.io/laymansguide/issue065.html"&gt;Issue 84&lt;/a&gt;)) by these tabs&amp;nbsp;(e.g. &lt;code&gt;scripts&lt;/code&gt;), but otherwise each tab is going to have its own memory&amp;nbsp;needs.&lt;/p&gt;
&lt;p&gt;In the earlier days of the internet, when spreadsheets were still a separate app, this memory usage would have showed up in the &lt;span class="caps"&gt;OS&lt;/span&gt; Task Manager under Lotus 1-2-3, Microsoft Excel, or some other spreadsheet program. Today, it shows up under Chrome or Firefox, and the details are only inspectable through the browser’s Task&amp;nbsp;Manager.&lt;/p&gt;
&lt;p&gt;No wonder browsers get all the blame these&amp;nbsp;days.&lt;/p&gt;
&lt;h2&gt;What I’ll be covering&amp;nbsp;next&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Next issue:&lt;/strong&gt; [&lt;span class="caps"&gt;LMG&lt;/span&gt; S8] Issue 95: What’s in a mobile&amp;nbsp;app?&lt;/p&gt;
&lt;p&gt;This issue felt like a data dump; I know it’s a lot all to take in 😅 In my childhood, I had access to lots of books with these cutaways showing the inner mechanisms of devices of all sorts, and I loved those books. It’s rather harder to do the same with software, since there’s nothing to physically slice through (even if only in the imagination!) I hope that the screenshots in this season of &lt;span class="caps"&gt;LMG&lt;/span&gt; will help you imagine the inner mechanisms of apps. Let me know if it’s working for you, and if there’s anything you’d like to see&amp;nbsp;:)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Sometime in the future:&lt;/strong&gt; What&amp;nbsp;is:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;booting up? [Issue&amp;nbsp;15]&lt;/li&gt;
&lt;li&gt;&lt;span class="caps"&gt;XSS&lt;/span&gt;? [Issue&amp;nbsp;8]&lt;/li&gt;
&lt;li&gt;a good reason developers write code and give it away for free online? [Issue&amp;nbsp;21]&lt;/li&gt;
&lt;li&gt;firmware? [Issue&amp;nbsp;34]&lt;/li&gt;
&lt;li&gt;OpenType? And what are fonts anyway? [Issue&amp;nbsp;42]&lt;/li&gt;
&lt;li&gt;What is involved in installing a piece of software? [Issue&amp;nbsp;48]&lt;/li&gt;
&lt;li&gt;How do apps know where a file starts and ends? [Issue&amp;nbsp;49]&lt;/li&gt;
&lt;li&gt;What is a password hash? [Issue&amp;nbsp;63]&lt;/li&gt;
&lt;/ul&gt;</content><category term="Season 08"></category><category term="app"></category><category term="cache"></category><category term="memory"></category><category term="operating system"></category></entry><entry><title>Issue 93: What’s in a web app?</title><link href="https://ngjunsiang.github.io/laymansguide/issue093.html" rel="alternate"></link><published>2020-11-07T08:00:00+08:00</published><updated>2020-11-07T08:00:00+08:00</updated><author><name>J S Ng</name></author><id>tag:ngjunsiang.github.io,2020-11-07:/laymansguide/issue093.html</id><summary type="html">&lt;p&gt;Web apps have limited access to the device’ storage, and can only store data in browser-managed databases. Progressive Web Apps (PWAs) can additionally register service workers that run in the background. Because they are so cleanly sandboxed, they can be easily removed by clearing the browser cache and storage, and deregistering any service workers&amp;nbsp;manually.&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;strong&gt;Previously:&lt;/strong&gt; Sandboxing is a catch-all term for the concept of ensuring apps don’t have access to resources outside of their privileges. Sandboxed apps are generally safer than non-sandboxed apps in terms of security, and easier to manage, terminate, and&amp;nbsp;uninstall.&lt;/p&gt;
&lt;p&gt;The simplest apps we use do not &lt;em&gt;generate&lt;/em&gt; data; think about your calculator, which simply crunches calculations and displays the result (conveniently ignoring the ones with memory slots for storing calculated values …). Or currency converters, or timezone converters … no storage&amp;nbsp;needed.&lt;/p&gt;
&lt;p&gt;So how do web apps store&amp;nbsp;data?&lt;/p&gt;
&lt;h2&gt;Data storage in web&amp;nbsp;apps&lt;/h2&gt;
&lt;p&gt;As a web-first programming language, Javascript programs were not expected to have to access, open, or create files on the device. That would make it really easy for a malicious script to download malware to a folder, where it could be accidentally invoked! Instead, it relies on other features to store and retrieve data for specific&amp;nbsp;purposes:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;To remember user logins (the “Remember me” feature you see on almost every login screen), web apps can set/unset cookies (&lt;a href="https://ngjunsiang.github.io/laymansguide/issue069.html"&gt;Issue 69&lt;/a&gt;)) in the&amp;nbsp;browser.&lt;/li&gt;
&lt;li&gt;To obtain files for use, the web app can invoke a File Select dialog for the user to choose a file, such as for uploading to the server. The web app is not allowed to access arbitrary files this&amp;nbsp;way.&lt;/li&gt;
&lt;li&gt;If data needs to be provided to the user in the form of a file, it can be stored on the disk with the user’s permission through a download&amp;nbsp;dialog.&lt;/li&gt;
&lt;li&gt;The web app can store data through a browser feature called &lt;strong&gt;localstorage&lt;/strong&gt;. This is a &lt;em&gt;key-value database&lt;/em&gt;, managed by the browser, that allows you to store data (the &lt;em&gt;value&lt;/em&gt;) tagged to a &lt;em&gt;key&lt;/em&gt;. The same way a hotel lobby holds your luggage for you and lets you access it through a luggage tag, or the way you can rent a locker for storing your stuff (&lt;em&gt;value&lt;/em&gt;) and access it through the locker &lt;em&gt;key&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;For data that is only needed in that tab (e.g. partially filled form data), and can be safely deleted when the tab is closed, the browser provides &lt;strong&gt;sessionstorage&lt;/strong&gt;. This works similarly to&amp;nbsp;localstorage.&lt;/li&gt;
&lt;li&gt;For more significant amounts of data, web apps can use IndexedDB, a more advanced database also managed in the browser. It is a document database (&lt;a href="https://ngjunsiang.github.io/laymansguide/issue088.html"&gt;Issue 88&lt;/a&gt;)), with each document tagged to a key in a key-object&amp;nbsp;system.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img alt="Firefox DevTools, showing the Storage tab. Local Storage is selected, displaying a list of keys and values." src="https://ngjunsiang.github.io/laymansguide/issue093_01.png" /&gt;&lt;br /&gt;
&lt;em&gt;DevTools in Firefox lets you inspect the data that web apps keep.&lt;br /&gt;The Storage tab shows what is stored in cache, cookies, IndexedDB, localstorage, and sessionstorage.&lt;br /&gt;IndexedDB, localstorage, and sessionstorage are key-value databases that store the data (value) tagged to a&amp;nbsp;key.&lt;/em&gt;    &lt;/p&gt;
&lt;h2&gt;Requesting and receiving data on a&amp;nbsp;server&lt;/h2&gt;
&lt;p&gt;So a web app doesn’t much in the way of storage access, but they were not designed for that at all. Most of the heavy lifting is not meant to be done in the browser, but elsewhere, on a server. A web app would send heavy workloads to a server (typically owned by the same company) through an &lt;span class="caps"&gt;API&lt;/span&gt; (&lt;a href="https://ngjunsiang.github.io/laymansguide/issue004.html"&gt;Issue 4&lt;/a&gt;)) through a web request (&lt;a href="https://ngjunsiang.github.io/laymansguide/issue009.html"&gt;Issue 9&lt;/a&gt;)), and receive the results through a server response (&lt;a href="https://ngjunsiang.github.io/laymansguide/issue008.html"&gt;Issue 8&lt;/a&gt;)).&lt;/p&gt;
&lt;p&gt;A web app would also need resources for display: images, videos, PDFs, &amp;#8230; these are requested and received via web requests as&amp;nbsp;well.&lt;/p&gt;
&lt;p&gt;Cool, so a web developer can just write Javascript code to get the data and resources it needs, display stuff to the user, wait for the user to interact, and then make more requests to the server to calculate stuff, or send the app more data (such as the user’s tweets or posts or other&amp;nbsp;stuff).&lt;/p&gt;
&lt;p&gt;Just one problem with this: if internet connectivity is intermittent or laggy, none of this is going to work! Even when the internet is fine, it makes for a very slow experience. How do we improve&amp;nbsp;this?&lt;/p&gt;
&lt;p&gt;One way is to cache (&lt;a href="https://ngjunsiang.github.io/laymansguide/issue039.html"&gt;Issue 39&lt;/a&gt;)) as many things as possible: header images, logos, emojis, icons, … these can all be stored in localstorage and accessed even when the app is&amp;nbsp;offline.&lt;/p&gt;
&lt;p&gt;Some apps, such as Google Docs, will also store user data in IndexedDB for a smoother experience—imagine having to wait for a request-response round-trip to the Google servers for every word you type. The data gets modified in IndexedDB first, and then synced to the servers. If the device gets disconnected from the internet, at least you will still be able to read whatever is in IndexedDB (and if you have enabled offline access, you can even edit the data in IndexedDB, and the Docs app will attempt to sync it to the server once connectivity is&amp;nbsp;restored).&lt;/p&gt;
&lt;h2&gt;Running background&amp;nbsp;processes&lt;/h2&gt;
&lt;p&gt;Then what’s with these popups on some websites asking you to install them? And how are some websites actually able to send us notifications? Something has got to be running in the browser background for these to happen, and none of what we have learned so far explains that … what&amp;nbsp;gives?&lt;/p&gt;
&lt;p&gt;Enter &lt;strong&gt;Progressive Web Apps&lt;/strong&gt; (PWAs). With some Googling and lots of reading on StackOverflow and other web documents, a web developer can get started meeting the various requirements needed to create a &lt;span class="caps"&gt;PWA&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;And in exchange for that inconvenience, she can use &lt;strong&gt;service workers&lt;/strong&gt;: javascript scripts that run on their own and are not dependent on the browser tab staying open. These service workers can listen for messages from the server, carry out some processing, make requests and receive responses, all independently from the app running in the tab. On mobile devices, they are gradually gaining more features as well, such as access to the Share feature (enabling users to share content with the &lt;span class="caps"&gt;PWA&lt;/span&gt;), and being able to access cameras, microphones, location services, and other things (provided the user grants&amp;nbsp;permission).&lt;/p&gt;
&lt;h2&gt;Installing web&amp;nbsp;apps&lt;/h2&gt;
&lt;p&gt;Okay, wait. &lt;span class="caps"&gt;WHAT&lt;/span&gt;?!&lt;/p&gt;
&lt;p&gt;I imagine most folks would be okay with cookies, with localstorage and even IndexedDB. You want things from an app, you gotta give it space to work, right? That’s&amp;nbsp;fair.&lt;/p&gt;
&lt;p&gt;But service workers, what?! You mean if I click Install, these apps get to run stuff &lt;em&gt;in the background&lt;/em&gt; in my browser, even after the tab is closed? If I’m not cool with that, I can just choose not to install and then these service workers won’t get installed,&amp;nbsp;right?&lt;/p&gt;
&lt;p&gt;Umm, I don’t know how to break this to you gently, but&amp;nbsp;nope.&lt;/p&gt;
&lt;p&gt;Once you visit a site (&lt;span class="caps"&gt;URL&lt;/span&gt;) with a registered service worker, your browser automatically registers it. The only thing the Install button does is to add a shortcut on your Desktop/Home Screen, and perhaps enable some features (such as mobile Share). But the service workers are already&amp;nbsp;there.&lt;/p&gt;
&lt;h2&gt;Uninstalling web&amp;nbsp;apps&lt;/h2&gt;
&lt;p&gt;And now the good&amp;nbsp;news.&lt;/p&gt;
&lt;p&gt;Because web apps are so cleanly sandboxed, they don’t stick tendrils into your operating system or device storage (beyond the space reserved by the browser, anyway). Removing apps and their files just involves clearing your browser cache and website storage. You will, however, have to deregister the service workers manually; please google for&amp;nbsp;instructions.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue summary:&lt;/strong&gt; Web apps have limited access to the device’ storage, and can only store data in browser-managed databases. Progressive Web Apps (PWAs) can additionally register service workers that run in the background. Because they are so cleanly sandboxed, they can be easily removed by clearing the browser cache and storage, and deregistering any service workers&amp;nbsp;manually.&lt;/p&gt;
&lt;h2&gt;What I’ll be covering&amp;nbsp;next&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Next issue:&lt;/strong&gt; [&lt;span class="caps"&gt;LMG&lt;/span&gt; S8] Issue 94: Why do web browsers take up so much&amp;nbsp;memory?&lt;/p&gt;
&lt;p&gt;I’m finally starting to answer one of the sometime-in-the-future questions below, and can’t wait to get to the meat of “What is involved in installing a piece of software?”; it’ll be a ride!&amp;nbsp;:)&lt;/p&gt;
&lt;p&gt;Before I move on to compare web apps with mobile apps, I’m going to take a short detour next issue and answer a question I hear all too often: “Why do web browsers take up so much&amp;nbsp;memory?”&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Sometime in the future:&lt;/strong&gt; What&amp;nbsp;is:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;booting up? [Issue&amp;nbsp;15]&lt;/li&gt;
&lt;li&gt;&lt;span class="caps"&gt;XSS&lt;/span&gt;? [Issue&amp;nbsp;8]&lt;/li&gt;
&lt;li&gt;a good reason developers write code and give it away for free online? [Issue&amp;nbsp;21]&lt;/li&gt;
&lt;li&gt;firmware? [Issue&amp;nbsp;34]&lt;/li&gt;
&lt;li&gt;OpenType? And what are fonts anyway? [Issue&amp;nbsp;42]&lt;/li&gt;
&lt;li&gt;What is involved in installing a piece of software? [Issue&amp;nbsp;48]&lt;/li&gt;
&lt;li&gt;How do apps know where a file starts and ends? [Issue&amp;nbsp;49]&lt;/li&gt;
&lt;li&gt;What is a password hash? [Issue&amp;nbsp;63]&lt;/li&gt;
&lt;/ul&gt;</content><category term="Season 08"></category><category term="app"></category><category term="cache"></category></entry><entry><title>Issue 92: All about apps</title><link href="https://ngjunsiang.github.io/laymansguide/issue092.html" rel="alternate"></link><published>2020-10-31T08:00:00+08:00</published><updated>2020-10-31T08:00:00+08:00</updated><author><name>J S Ng</name></author><id>tag:ngjunsiang.github.io,2020-10-31:/laymansguide/issue092.html</id><summary type="html">&lt;p&gt;Sandboxing is a catch-all term for the concept of ensuring apps don’t have access to resources outside of their privileges. Sandboxed apps are generally safer than non-sandboxed apps in terms of security, and easier to manage, terminate, and&amp;nbsp;uninstall.&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;strong&gt;Previously:&lt;/strong&gt; Depending on what you need a database for, there may be online database platforms that can manage and automate much of the work for you. Airtable, Smartsheet, Knack, and Zoho Creator are just 4 of many options that offer an easier way to set up and input your data, then access them through apps or other&amp;nbsp;means.&lt;/p&gt;
&lt;p&gt;There was a time when apps, short for &lt;em&gt;applications&lt;/em&gt;, were these files that came on a &lt;span class="caps"&gt;CD&lt;/span&gt; or diskette, usually ending&amp;nbsp;in &lt;code&gt;.exe&lt;/code&gt; (if your settings enabled you to see file extensions). You double-clicked them or pressed ‘Enter’, and things&amp;nbsp;happened.&lt;/p&gt;
&lt;p&gt;Today … the idea of an app is more nebulous.&amp;nbsp;The &lt;code&gt;.exe&lt;/code&gt; files are still there, but now there are also apps that you install from the app store. And what’s up with webpages that display an app installation pop-up and create an icon on your home screen or desktop? Are they the same kind of app? If not, what’s the difference between&amp;nbsp;them?&lt;/p&gt;
&lt;p&gt;Before I answer that question, we need to talk about an important concept called &lt;strong&gt;sandboxing&lt;/strong&gt;.&lt;/p&gt;
&lt;h2&gt;Why do apps need to be&amp;nbsp;sandboxed?&lt;/h2&gt;
&lt;p&gt;An unrestrained app running in your operating system would have access to any and all resources on that machine. It could potentially modify or remove system files, halt running programs or accidentally overwrite their memory contents, and so&amp;nbsp;on.&lt;/p&gt;
&lt;p&gt;&lt;a href="[Issue 56]({filename}/season05/issue056/issue056.md)"&gt;The operating system&lt;/a&gt;) takes some measures to minimise or prevent this. But even within these limits, a app developed with good intentions could still potentially cause trouble. It might accidentally hang on to audio access when it no longer needs it, make a mess of the user’s home folder, leave files in limbo, etc. Programs can leave a mess, and a way to limit this mess is very&amp;nbsp;welcome.&lt;/p&gt;
&lt;p&gt;This is why sandbox systems were already being researched as early as the 1970s, and are still an ongoing research interest at many&amp;nbsp;institutions.&lt;/p&gt;
&lt;h2&gt;What is&amp;nbsp;sandboxing?&lt;/h2&gt;
&lt;p&gt;If you are old enough you might remember playing in a sandbox. While there are usually no explicit rules about how to play in a sandbox, there is usually one unspoken&amp;nbsp;rule:&lt;/p&gt;
&lt;p&gt;What was in the sandbox, stays in the&amp;nbsp;sandbox.&lt;/p&gt;
&lt;p&gt;A sandbox limits the mess, yet gives you unrestrained freedom &lt;em&gt;within&lt;/em&gt; that&amp;nbsp;box.&lt;/p&gt;
&lt;p&gt;In a computer, a sandbox system imposes restrictions on running applications. Some common restrictions&amp;nbsp;include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;only being able to access/change/delete files within a particular&amp;nbsp;subfolder&lt;/li&gt;
&lt;li&gt;only having access to some &lt;span class="caps"&gt;OS&lt;/span&gt; resources (e.g. not being able to access &lt;span class="caps"&gt;USB&lt;/span&gt; devices, or audio, or&amp;nbsp;webcam)&lt;/li&gt;
&lt;li&gt;having limited privileges while the application is not active (e.g. no internet access when not being directly interacted with, and just running in the&amp;nbsp;background)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These restrictions are intended to limit any damage and keep the system more stable than it might otherwise have&amp;nbsp;been.&lt;/p&gt;
&lt;p&gt;So one way to categorise laptop apps, mobile apps, and web apps is in the amount of sandboxing they are subject&amp;nbsp;to.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issue summary:&lt;/strong&gt; Sandboxing is a catch-all term for the concept of ensuring apps don’t have access to resources outside of their privileges. Sandboxed apps are generally safer than non-sandboxed apps in terms of security, and easier to manage, terminate, and&amp;nbsp;uninstall.&lt;/p&gt;
&lt;p&gt;Keeping it vague in this issue because the details really differ between operating systems, kinds of apps, and even the way they are distributed. We’ll be digging into details next issue, starting with the most heavily sandboxed app: the web&amp;nbsp;app.&lt;/p&gt;
&lt;h2&gt;What I’ll be covering&amp;nbsp;next&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Next issue:&lt;/strong&gt; [&lt;span class="caps"&gt;LMG&lt;/span&gt; S8] Issue 93: What’s in a web&amp;nbsp;app?&lt;/p&gt;
&lt;p&gt;From just little snippets of script that animated buttons and counted visitors back in the 90s, Javascript now powers a huge portion of the Internet, processing payments, serving ads, and much more besides. We’ll look at how this gets packaged into a web app next&amp;nbsp;issue.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Sometime in the future:&lt;/strong&gt; What&amp;nbsp;is:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;booting up? [Issue&amp;nbsp;15]&lt;/li&gt;
&lt;li&gt;&lt;span class="caps"&gt;XSS&lt;/span&gt;? [Issue&amp;nbsp;8]&lt;/li&gt;
&lt;li&gt;a good reason developers write code and give it away for free online? [Issue&amp;nbsp;21]&lt;/li&gt;
&lt;li&gt;firmware? [Issue&amp;nbsp;34]&lt;/li&gt;
&lt;li&gt;OpenType? And what are fonts anyway? [Issue&amp;nbsp;42]&lt;/li&gt;
&lt;li&gt;What is involved in installing a piece of software? [Issue&amp;nbsp;48]&lt;/li&gt;
&lt;li&gt;How do apps know where a file starts and ends? [Issue&amp;nbsp;49]&lt;/li&gt;
&lt;li&gt;What is a password hash? [Issue&amp;nbsp;63]&lt;/li&gt;
&lt;/ul&gt;</content><category term="Season 08"></category><category term="app"></category></entry></feed>