<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Keter Sammy on Medium]]></title>
        <description><![CDATA[Stories by Keter Sammy on Medium]]></description>
        <link>https://medium.com/@ketersammy09?source=rss-ac396f86460c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*FpcCChyWhqalxEmN_KIscA.jpeg</url>
            <title>Stories by Keter Sammy on Medium</title>
            <link>https://medium.com/@ketersammy09?source=rss-ac396f86460c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 22:01:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ketersammy09/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Understanding File Permissions in Linux: A Comprehensive Guide with Examples]]></title>
            <link>https://medium.com/@ketersammy09/understanding-file-permissions-in-linux-a-comprehensive-guide-with-examples-e3f710d85cb8?source=rss-ac396f86460c------2</link>
            <guid isPermaLink="false">https://medium.com/p/e3f710d85cb8</guid>
            <dc:creator><![CDATA[Keter Sammy]]></dc:creator>
            <pubDate>Mon, 20 Nov 2023 12:51:00 GMT</pubDate>
            <atom:updated>2023-11-20T12:51:00.459Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VjfXwgjOvr23otlnClg9-w.jpeg" /></figure><p>Linux, as a robust and secure operating system, employs a powerful and flexible file permission system to regulate access to files and directories. These permissions are crucial for maintaining the security and integrity of a Linux system. In this article, we will delve into the basics of file permissions, exploring how they work and providing practical examples.</p><h3>File Permissions Overview:</h3><p>In Linux, each file and directory is associated with three sets of permissions:</p><ol><li><strong>Read (r):</strong> The ability to read the contents of a file or view a directory’s listing.</li><li><strong>Write (w):</strong> The ability to modify the contents of a file or create, delete, or rename files within a directory.</li><li><strong>Execute (x):</strong> The ability to execute a file or enter a directory.</li></ol><p><em>Permission Types/Categories:</em></p><ul><li><strong>User (u):</strong> The owner of the file or directory.</li><li><strong>Group (g):</strong> Users belonging to the file’s group.</li><li><strong>Others (o):</strong> Users who are neither the owner nor in the group.</li></ul><p>Permissions and types for each file works this way:</p><p>For each file, the read/write/execute appear thrice for each type/category:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*6SVxdOskaD7W89g2rDaozQ.png" /></figure><blockquote>In the picture above, there is a photo file called Nebula.jpg. Notice the start of the line and let’s break down the meaning of the permissions in ‘-rw-rw-r — ‘.</blockquote><ul><li>The first ‘-’ indicates that this is a file. Notice that in the entry below it, it starts with a ‘d’ indicating a directory.</li><li>Following that are 9 characters which are read in groups of 3, each group denoting a category i.e. the first 3 for <em>User</em>, the next 3 for <em>Group</em> and the last 3 for <em>Others</em>.</li><li>For this photo file, <em>User</em> has permission to read and write but not to execute, thus <em>‘rw-’</em>; <em>Group</em> has permission to also read/write thus <em>‘rw-’</em> but not to execute; and <em>Others</em> has permission to only read thus<em> ‘r — ’</em>.<br>A ‘-’ means no permission.</li></ul><h3>Viewing Permissions:</h3><p>To view the permissions of a file or directory, use the ls command with the -l option:</p><pre>$ ls -l filename</pre><p>This will display a detailed listing that includes the permissions, owner, group, size, and modification time.</p><h3>Modifying Permissions:</h3><h4>chmod Command:</h4><p>The chmod command is used to change file permissions. It supports both symbolic and octal notation.</p><h4>Octal Notation:</h4><ul><li>4 (Read): 100</li><li>2 (Write): 010</li><li>1 (Execute): 001</li></ul><p>Combine these values for each permission set (user, group, others) to get the desired permission. For example, to grant read and write permissions to the owner and read-only permission to the group:</p><pre>$ chmod 640 filename</pre><h4>Symbolic Notation:</h4><ul><li>u (User):</li><li>g (Group):</li><li>o (Others):</li><li>a (All):</li><li>+ (Add permission):</li><li>- (Remove permission):</li><li>= (Set exact permissions):</li></ul><p>For example, to grant execute permission to the owner:</p><pre>$ chmod u+x filename</pre><h3>Examples:</h3><h4>Example 1: Basic Permissions</h4><pre>$ touch file.txt<br>$ ls -l file.txt<br>-rw-r--r-- 1 user group 0 Nov 20 12:00 file.txt</pre><p>In this example, the file file.txt has read and write permissions for the owner, and read-only permissions for the group and others.</p><h4>Example 2: Changing Permissions</h4><pre>$ chmod u+x file.txt<br>$ ls -l file.txt<br>-rwxr--r-- 1 user group 0 Nov 20 12:00 file.txt</pre><p>Here, the owner has gained execute permission, as denoted by the added “x.”</p><h4>Example 3: Recursive Permission Change for Directories</h4><pre>$ mkdir mydir<br>$ touch mydir/file1<br>$ touch mydir/file2<br>$ chmod -R 750 mydir<br>$ ls -l mydir<br>drwxr-x--- 2 user group 4096 Nov 20 12:00 file1<br>drwxr-x--- 2 user group 4096 Nov 20 12:00 file2</pre><p>The -R option makes the chmod command recursive, changing permissions for all files and subdirectories within mydir.</p><p><strong><em>Understanding file permissions in Linux is vital for maintaining a secure and organized system. The ability to control who can access, modify, and execute files ensures the integrity and confidentiality of your data. By using the </em></strong><strong><em>chmod command, you can easily manage file permissions and tailor access levels according to your specific needs.</em></strong></p><p>Feel free to reach me at ketersammy09@gmail.com</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e3f710d85cb8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring the Linux File System: A Comprehensive Guide.]]></title>
            <link>https://medium.com/@ketersammy09/exploring-the-linux-file-system-a-comprehensive-guide-9fb865a0b052?source=rss-ac396f86460c------2</link>
            <guid isPermaLink="false">https://medium.com/p/9fb865a0b052</guid>
            <dc:creator><![CDATA[Keter Sammy]]></dc:creator>
            <pubDate>Mon, 20 Nov 2023 12:19:54 GMT</pubDate>
            <atom:updated>2023-11-20T12:52:02.260Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WOzZb2Yevrv50iBX8MQsbQ.jpeg" /></figure><h4>Introduction</h4><p>The Linux file system is the foundation of the operating system, providing a structured way to organize and store data. Understanding the file system is crucial for users and administrators alike, as it dictates how information is stored, accessed, and managed. In this article, we will delve deeply into the Linux file system, demystifying its structure and functionalities in an easy-to-understand manner.</p><h3>Hierarchy of Directories</h3><p>The Linux file system follows a hierarchical structure, with the root directory (“/”) at the top. All other directories and files are organized beneath this root, forming a tree-like structure. Let’s explore some key directories:</p><p><strong><em>1. /bin (Binary)</em></strong></p><p>This directory houses essential system binaries (executable files) necessary for system booting and repair. Common commands like ls (list files) and cp (copy) are found here.</p><p><strong><em>2. /etc (Etcetera)</em></strong></p><p>Configuration files for system-wide settings and application configurations reside in this directory. It plays a vital role in system customization.</p><p><strong><em>3. /home</em></strong></p><p>Each user on the system has a dedicated subdirectory within /home, where their personal files and settings are stored.</p><p><strong><em>4. /var (Variable)</em></strong></p><p>This directory holds variable data, such as logs, databases, and temporary files generated by various programs.</p><p><strong><em>5. /usr (User)</em></strong></p><p>The bulk of user-installed programs and their supporting files are stored here, including binaries, libraries, and documentation.</p><p><strong><em>6. /dev (Devices)</em></strong></p><p>Special files representing physical and virtual devices are stored here. For instance, hard drives are represented as /dev/sda.</p><p><strong><em>7. /proc (Process)</em></strong></p><p>A virtual file system providing information about running processes and system configuration. It is not a physical directory but a dynamic interface to the kernel.</p><p><strong><em>8. /sbin (System Binaries)</em></strong></p><p>This directory contains essential system binaries, similar to /bin, but these are primarily used for system administration tasks. Commands like fdisk (disk partitioning) and ifconfig (network configuration) are stored here.</p><p><strong><em>9. /lib (Library)</em></strong></p><p>Critical system libraries that are required for binaries in /bin and /sbin are stored in this directory. These libraries contain functions and code that are reused by various programs.</p><p><strong><em>10. /opt (Optional)</em></strong></p><p>This directory is used for installing optional software packages. It provides a standardized location for software that is not part of the operating system’s default installation.</p><p><strong><em>11. /root</em></strong></p><p>The home directory for the root user, who is the superuser with administrative privileges. Unlike regular users who have their home directories under /home, the root user&#39;s home is directly under /.</p><p><strong><em>12. /tmp (Temporary)</em></strong></p><p>This directory holds temporary files created by programs and users. It is often used for storing short-lived data that doesn’t need to persist across reboots. The /tmp directory is usually cleared on system startup.</p><p><strong><em>13. /boot</em></strong></p><p>Contains the files required for the system’s bootloader, such as the kernel and initial ramdisk. This directory is critical for the system’s boot process.</p><p><strong><em>14. /media</em></strong></p><p>Traditionally used as a mount point for removable media such as USB drives and CD-ROMs. Modern Linux systems often use the /mnt directory for this purpose.</p><p><strong><em>15. /run</em></strong></p><p>A directory for storing temporary runtime files, such as PID (process ID) files and UNIX domain sockets. It is often used by system services and daemons.</p><p><strong><em>16. /srv (Service)</em></strong></p><p>This directory is intended to contain data for services provided by the system. For example, web server files might be placed in /srv/www.</p><p><strong><em>17. /usr/local</em></strong></p><p>Similar to /opt, this directory is used for installing software locally on the system. However, /usr/local is typically used for software manually installed by the system administrator.</p><p><strong><em>18. /sys (System)</em></strong></p><p>A virtual file system that exposes information and configuration interfaces to the kernel. It allows users and processes to interact with the kernel to query and configure various aspects of the system.</p><p><strong><em>19. /mnt (Mount)</em></strong></p><p>Historically used as a mount point for temporary filesystems or devices. While /media is often used for removable media, /mnt can be used for temporary mounts of other filesystems.</p><p><strong><em>20. /lost+found</em></strong></p><p>This directory is used by the fsck (filesystem check) utility to store recovered files after a filesystem check. If the filesystem is found to have inconsistencies, recovered files may be placed here.</p><p>These directories collectively form the Linux file system hierarchy, providing a structured and organized way to manage the system’s files and directories. Understanding their roles is essential for effectively navigating, administering, and customizing a Linux system.</p><h3>File System Types</h3><p>Linux supports various file system types, each with its own features and use cases. Some common file systems include:</p><h4>1. ext4 (Fourth Extended File System)</h4><p>Widely used and the default file system for many Linux distributions. It offers features like journaling, which enhances data integrity.</p><h4>2. BTRFS (B-Tree File System)</h4><p>A modern file system with advanced features such as snapshots, compression, and built-in RAID support. It is designed for better scalability and data integrity.</p><h4>3. XFS (X File System)</h4><p>Known for its high-performance and scalability, XFS is suitable for large-scale storage systems.</p><h4>4. tmpfs (Temporary File System)</h4><p>A file system stored in memory, commonly used for temporary files and data. It provides fast access but is volatile and doesn’t persist across reboots.</p><h4>File Permissions and Ownership</h4><p>Linux employs a robust system of permissions and ownership to control access to files and directories. Each file and directory has an owner, a group, and a set of permissions for the owner, group, and others. Permissions include read, write, and execute.</p><h4>Example:</h4><pre>-rw-r--r-- 1 user1 users 1024 Nov 20 2023 myfile.txt</pre><p>In this example, user1 is the owner, users is the group, and the file has read and write permissions for the owner, and only read permissions for the group and others. A more detailed guide can be found <a href="https://medium.com/@ketersammy09/understanding-file-permissions-in-linux-a-comprehensive-guide-with-examples-e3f710d85cb8">here</a>.</p><h4>Mount Points</h4><p>Linux allows administrators to attach additional storage devices to the file system using mount points. The mount command is used to associate a device or partition with a specific directory. This flexibility allows for efficient storage management and expansion.</p><p><strong><em>Example;</em></strong></p><pre>sudo mount /dev/sdb1 /mnt/data</pre><p>This command mounts the device /dev/sdb1 to the directory /mnt/data.</p><h3>File System Navigation and Commands</h3><p>Understanding basic file system navigation is essential for effective Linux usage. Here are some fundamental commands:</p><ul><li>cd (Change Directory): Navigate between directories.</li><li>ls (List): Display the contents of a directory.</li><li>pwd (Print Working Directory): Show the current directory path.</li><li>cp (Copy) and mv (Move): Copy or move files and directories.</li><li>rm (Remove): Delete files and directories.</li><li>touch: Create empty files.</li><li>mkdir (Make Directory): Create new directories.</li></ul><p><strong><em>The Linux file system is a fundamental component of the operating system, providing the structure for organizing and accessing data. With an understanding of its hierarchy, file system types, permissions, and basic commands, users and administrators can navigate, manage, and customize their Linux environments effectively. As you continue to explore Linux, mastering the file system is a crucial step toward becoming a proficient user or administrator.</em></strong></p><p>Feel free to reach me at ketersammy09@gmail.com</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9fb865a0b052" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flow Control in JavaScript.]]></title>
            <link>https://medium.com/@ketersammy09/flow-control-in-javascript-fde0bceba7c9?source=rss-ac396f86460c------2</link>
            <guid isPermaLink="false">https://medium.com/p/fde0bceba7c9</guid>
            <category><![CDATA[conditional-statements]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[flow-control-tools]]></category>
            <category><![CDATA[loops-in-javascript]]></category>
            <category><![CDATA[decision-making-tools]]></category>
            <dc:creator><![CDATA[Keter Sammy]]></dc:creator>
            <pubDate>Mon, 24 Apr 2023 12:18:18 GMT</pubDate>
            <atom:updated>2023-04-24T12:18:18.716Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong><em>Flow control in JavaScript refers to the management of the order in which statements and functions are executed based on conditional statements, loops and functions.</em></strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GNJ1sZ85mFfTo90J" /><figcaption>Photo by <a href="https://unsplash.com/@roonz_nl?utm_source=medium&amp;utm_medium=referral">RoonZ nl</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Flow control is a fundamental concept in programming that allows developers to control the order in which statements and instructions are executed in a program. In JavaScript, there are several constructs that can be used for flow control, including loops, conditional statements, and functions. In this response, we’ll focus on loops and their use cases.</p><h3><strong>a). Loops:</strong></h3><p>A loop is a programming construct that allows developers to execute a block of code repeatedly. There are two main types of loops in JavaScript: for loops and while loops.</p><h3><strong><em>&gt;&gt; for loop</em></strong></h3><p>A for loop is used when you know exactly how many times you want to execute a block of code. The syntax of a for loop is as follows:</p><pre>for (initialization; condition; increment/decrement) {<br>   // code to be executed<br>}</pre><p>The initialization step is used to set a variable to an initial value. The condition is a Boolean expression that is evaluated before each iteration of the loop. If the condition is true, the loop executes the code block. After each iteration, the increment/decrement step is executed, and the condition is evaluated again. The loop continues to execute until the condition is false.</p><p>Here’s an example of a for loop that prints the numbers 0 through 4 to the console:</p><pre>for (let i = 0; i &lt; 5; i++) {<br>   console.log(i);<br>}</pre><p>In this example, the loop initializes the variable i to 0, checks if i is less than 5, and executes the code block if the condition is true. After each iteration, i is incremented by 1. The loop continues until i is no longer less than 5.</p><p><strong><em>&gt;&gt; difference between ‘for…in’ loop and ‘for…of’ loop &gt;&gt;</em></strong></p><p><strong>In JavaScript, there are two types of loops for iterating over arrays, strings, and other iterable objects: </strong><strong>for...in and </strong><strong>for...of loops.</strong></p><h3>&gt;&gt; for...in loop:</h3><p>The for...in loop iterates over the keys or indices of an object or array, which can be used to access the values associated with those keys. This type of loop is suitable for iterating over an object&#39;s properties or an array&#39;s indices, but it is not recommended for iterating over arrays because it may not iterate through the array in the order you expect.</p><p>Here is an example of for...in loop that iterates over the keys of an object:</p><pre>const person = { name: &#39;John&#39;, age: 30, occupation: &#39;developer&#39; };<br>for (let key in person) {<br>  console.log(key + &#39;: &#39; + person[key]);<br>}</pre><p>Output:</p><pre>name: John<br>age: 30<br>occupation: developer</pre><p>Here is an example of for...in loop that iterates over the indices of an array:</p><pre>const arr = [&#39;apple&#39;, &#39;banana&#39;, &#39;cherry&#39;];<br>for (let index in arr) {<br>  console.log(index + &#39;: &#39; + arr[index]);<br>}</pre><p>Output:</p><pre>0: apple<br>1: banana<br>2: cherry</pre><p>Note that the for...in loop can also iterate over the prototype chain of an object, which can cause unexpected behavior. Therefore, it is generally recommended to use for...in loop only for objects, and not for arrays.</p><h3>&gt;&gt; for...of loop:</h3><p>The for...of loop iterates over the values of an iterable object, such as an array or a string, in the order they appear. This type of loop is suitable for iterating over the elements of an array, but not for iterating over an object&#39;s properties.</p><p>Here is an example of for...of loop that iterates over the elements of an array:</p><pre>const arr = [&#39;apple&#39;, &#39;banana&#39;, &#39;cherry&#39;];<br>for (let elem of arr) {<br>  console.log(elem);<br>}</pre><p>Output:</p><pre>apple<br>banana<br>cherry</pre><p>Here is an example of for...of loop that iterates over the characters of a string:</p><pre>const str = &#39;Hello World&#39;;<br>for (let char of str) {<br>  console.log(char);<br>}</pre><p>Output:</p><pre>H<br>e<br>l<br>l<br>o<br><br>W<br>o<br>r<br>l<br>d</pre><p>Note that the for...of loop cannot be used to iterate over an object&#39;s properties, as objects are not iterable. If you need to iterate over an object&#39;s properties, use for...in loop instead.</p><h4>&gt;&gt; Nested for loop:</h4><p>A nested for loop is when you have one for loop inside another for loop. This can be useful when you need to iterate through a two-dimensional array or matrix.</p><pre>const matrix = [  [1, 2, 3],<br>  [4, 5, 6],<br>  [7, 8, 9]<br>];<br><br>for (let i = 0; i &lt; matrix.length; i++) {<br>  for (let j = 0; j &lt; matrix[i].length; j++) {<br>    console.log(matrix[i][j]);<br>  }<br>}</pre><p>In this example, the outer loop iterates through the rows of the matrix, while the inner loop iterates through the columns of each row.</p><h3>&gt;&gt; while loop</h3><p>A while loop is used when you don’t know how many times you want to execute a block of code. The syntax of a while loop is as follows:</p><pre>while (condition) {<br>   // code to be executed<br>}</pre><p>In a while loop, the condition is evaluated before each iteration of the loop. If the condition is true, the loop executes the code block. After each iteration, the condition is evaluated again. The loop continues to execute until the condition is false.</p><p>Here’s an example of a while loop that prints the numbers 0 through 4 to the console:</p><pre>let i = 0;<br><br>while (i &lt; 5) {<br>   console.log(i);<br>   i++;<br>}</pre><p>In this example, the loop initializes the variable i to 0, checks if i is less than 5, and executes the code block if the condition is true. After each iteration, i is incremented by 1. The loop continues until i is no longer less than 5.</p><h4>&gt;&gt; While loop with a break statement.</h4><p>Sometimes you may want to exit a loop before it has completed all iterations. In this case, you can use the break statement to exit the loop.</p><pre>let i = 0;<br><br>while (i &lt; 10) {<br>  console.log(i);<br>  i++;<br>  if (i === 5) {<br>    break;<br>  }<br>}</pre><p>In this example, the loop will print the numbers 0 through 4 to the console, then exit the loop when i is equal to 5.</p><h3>b). Conditional statements</h3><p>Conditional statements allow the program to make decisions based on the current state of the code. In JavaScript, there are two primary conditional statements: if and switch. The if statement evaluates a given expression and executes a block of code if the expression is true. On the other hand, the switch statement checks an expression against multiple cases and executes a block of code based on the first matched case. Conditional statements are critical for building flexible and dynamic programs, as they enable developers to create code that can handle a range of scenarios and respond to changing conditions.</p><h4>&gt;&gt; if/else statement.</h4><p>The if/else statement is used to execute different code depending on whether a condition is true or false.</p><pre>const age = 18;<br><br>if (age &gt;= 18) {<br>  console.log(&quot;You are an adult.&quot;);<br>} else {<br>  console.log(&quot;You are not yet an adult.&quot;);<br>}</pre><p>In this example, if the age variable is greater than or equal to 18, the program will print &quot;You are an adult.&quot; Otherwise, it will print &quot;You are not yet an adult.&quot;</p><h4>&gt;&gt; switch statement.</h4><p>The switch statement is used to execute different code depending on the value of a variable.</p><pre>const dayOfWeek = 5;<br><br>switch (dayOfWeek) {<br>  case 1:<br>    console.log(&quot;Monday&quot;);<br>    break;<br>  case 2:<br>    console.log(&quot;Tuesday&quot;);<br>    break;<br>  case 3:<br>    console.log(&quot;Wednesday&quot;);<br>    break;<br>  case 4:<br>    console.log(&quot;Thursday&quot;);<br>    break;<br>  case 5:<br>    console.log(&quot;Friday&quot;);<br>    break;<br>  case 6:<br>    console.log(&quot;Saturday&quot;);<br>    break;<br>  case 7:<br>    console.log(&quot;Sunday&quot;);<br>    break;<br>  default:<br>    console.log(&quot;Invalid day&quot;);<br>    break;<br>}</pre><p>In this example, the switch statement will print &quot;Friday&quot; to the console, since the dayOfWeek variable is set to 5.</p><h3>c). Functions:</h3><p>Functions are reusable blocks of code that can be called multiple times throughout a program.</p><pre>function calculateArea(width, height) {<br>  return width * height;<br>}<br><br>const area = calculateArea(5, 10);<br>console.log(area); // 50</pre><p>In this example, the calculateArea function takes two parameters (width and height) and returns their product. The area variable is then set to the result of calling the function with the arguments 5 and 10. Finally, the program prints the value of area (50) to the console.</p><p><strong><em>Loops and conditional statements are essential features of JavaScript programming that enable developers to execute code repeatedly and conditionally based on specific criteria. Loops allow developers to iterate over arrays or perform a specific action a certain number of times, making code more efficient and concise. Conditional statements, on the other hand, provide a way to execute different sections of code depending on whether a particular condition is met, allowing developers to create dynamic and responsive applications. Together, loops and conditional statements provide a foundation for building complex and powerful JavaScript programs that can adapt to different scenarios and user inputs. Mastery of these features is essential for any JavaScript developer looking to write scalable and maintainable code.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fde0bceba7c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript, a Dynamic Programming Language.]]></title>
            <link>https://medium.com/@ketersammy09/javascript-a-dynamic-programming-language-c036217ade17?source=rss-ac396f86460c------2</link>
            <guid isPermaLink="false">https://medium.com/p/c036217ade17</guid>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[dynamic-programming]]></category>
            <dc:creator><![CDATA[Keter Sammy]]></dc:creator>
            <pubDate>Fri, 14 Apr 2023 07:55:42 GMT</pubDate>
            <atom:updated>2023-04-14T07:55:42.484Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*h94xIk8s0-vNaJrgXYzOTA.png" /><figcaption>JavaScript</figcaption></figure><p>JavaScript is a dynamic language that offers a lot of flexibility in how code is written and executed. This flexibility comes from several key features of the language that allow for <strong>dynamic typing</strong>, <strong>late binding</strong>, <strong>prototypal inheritance</strong>, and the use of the <strong>“eval” function</strong>.</p><p><strong><em>Dynamic Typing:</em></strong></p><p>One of the most distinctive features of JavaScript is its dynamic typing system. Unlike statically-typed languages like Java or C++, JavaScript does not require you to declare variable types ahead of time. Instead, the type of a variable is determined at runtime based on the value it holds. This can make coding in JavaScript more efficient, as it allows you to write code that can work with a wide range of data types without needing to explicitly define each one.</p><p><em>Example:</em></p><pre>let myVariable = &quot;Hello, world!&quot;;<br>console.log(typeof myVariable); // outputs &quot;string&quot;<br><br>myVariable = 42;<br>console.log(typeof myVariable); // outputs &quot;number&quot;<br><br>myVariable = true;<br>console.log(typeof myVariable); // outputs &quot;boolean&quot;</pre><p>In this code, we start by declaring a variable called <strong><em>myVariable</em></strong> and assigning it a <strong><em>string</em></strong> value. We then use the <strong><em>typeof</em></strong> operator to check the type of the variable, which in this case is “<strong><em>string</em></strong>”.</p><p>Next, we assign the variable a numeric value<strong><em> (42)</em></strong> and again check its type using <strong><em>typeof</em></strong>, which now returns <strong><em>“number”.</em></strong></p><p>Finally, we assign the variable a <strong><em>boolean</em></strong> value <strong><em>(true)</em></strong> and check its type once more, which this time returns <strong><em>“boolean”.</em></strong></p><p>As you can see, the type of the <strong><em>myVariable</em></strong> variable changes dynamically at runtime based on the value it holds. This is an example of dynamic typing in JavaScript, which allows for greater flexibility and versatility in how variables are used and assigned.</p><p><strong><em>Late Binding:</em></strong></p><p>Another key aspect of JavaScript’s dynamism is its late binding of function calls. In other words, when you call a function in JavaScript, the specific function being executed is not determined until the code is actually running. This allows for greater flexibility in how functions are called and used, as well as the ability to change function behavior at runtime.</p><pre>function sayHello() {<br>  console.log(&quot;Hello, world!&quot;);<br>}<br><br>function sayGoodbye() {<br>  console.log(&quot;Goodbye, world!&quot;);<br>}<br><br>let greetingFunction = sayHello;<br>greetingFunction(); // outputs &quot;Hello, world!&quot;<br><br>greetingFunction = sayGoodbye;<br>greetingFunction(); // outputs &quot;Goodbye, world!&quot;</pre><p>In this code, we define two functions: sayHello() and sayGoodbye(). We then declare a variable called greetingFunction and assign it the value of the sayHello() function.</p><p>We then call the greetingFunction() function, which outputs &quot;Hello, world!&quot;. However, we then reassign greetingFunction to the sayGoodbye() function, and call it again, which this time outputs &quot;Goodbye, world!&quot;.</p><p>This is an example of late binding in JavaScript, where the function being called is not determined until runtime. In this case, the specific function being executed is determined by the value of the greetingFunction variable, which can be changed at runtime to point to different functions.</p><p>Late binding in JavaScript allows for greater flexibility in how functions are called and used, and can be particularly useful when dealing with complex or dynamic code. However, it also requires careful attention to detail to ensure that the correct functions are being called in the right situations.</p><p><strong><em>Prototypal Inheritance:</em></strong></p><p>JavaScript’s use of prototypal inheritance is also a major factor in its dynamic nature. In JavaScript, objects can inherit properties and methods from other objects, allowing for greater flexibility and code reuse. This is different from the class-based inheritance used in many other programming languages and is one of the key reasons why JavaScript is such a versatile language.</p><pre>// Define a parent object with a method<br>let parent = {<br>  sayHello: function() {<br>    console.log(&quot;Hello, world!&quot;);<br>  }<br>};<br><br>// Define a child object that inherits from the parent<br>let child = Object.create(parent);<br><br>// Call the inherited method on the child object<br>child.sayHello(); // outputs &quot;Hello, world!&quot;</pre><p>In this code, we start by defining a parent object that has a single method called sayHello(), which simply outputs &quot;Hello, world!&quot; to the console.</p><p>We then create a new object called child using the Object.create() method, passing in the parent object as its prototype. This sets up a prototypal inheritance relationship between the parent and child objects, allowing the child object to inherit properties and methods from the parent object.</p><p>Finally, we call the sayHello() method on the child object, which actually executes the sayHello() method from the parent object, since child inherits from parent.</p><p><strong><em>“eval” function:</em></strong></p><p>The built-in “eval” function allows you to execute code dynamically at runtime. This can be useful in certain situations, but it also introduces potential security risks if the code being executed is not trusted. Therefore, it’s important to use the “eval” function with caution and to ensure that any dynamically executed code is safe and secure.</p><pre>let myVariable = 5;<br>let myString = &quot;myVariable * 2&quot;;<br>console.log(eval(myString)); // outputs 10<br><br>myVariable = 10;<br>console.log(eval(myString)); // outputs 20</pre><p>In this code, we start by declaring a variable called myVariable and assigning it the value 5. We then declare a string variable called myString and assign it the value &quot;myVariable * 2&quot;.</p><p>We then call the eval() function and pass in the myString variable as an argument. As we saw in the previous example, the eval() function interprets the string &quot;myVariable * 2&quot; as an expression and evaluates it to 10.</p><p>However, we then change the value of myVariable to 10. We then call eval() again with the same myString variable as an argument. This time, the eval() function evaluates &quot;myVariable * 2&quot; to 20, since myVariable now has a value of 10.</p><p>This demonstrates how the eval() function is dynamic and can adapt to changes in the values of variables and other programmatic constructs. This can be a powerful feature in some cases, but also requires careful attention to ensure that the correct values are being used in each situation.</p><p><strong>While JavaScript’s dynamism can make it a powerful and flexible language, it can also introduce potential pitfalls and bugs if not used carefully. It’s important to understand these dynamic features and their implications, as well as to follow best practices for writing safe and effective JavaScript code.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c036217ade17" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Variables in Computer Programming.]]></title>
            <link>https://medium.com/@ketersammy09/variables-in-computer-programming-368e4cadf8d1?source=rss-ac396f86460c------2</link>
            <guid isPermaLink="false">https://medium.com/p/368e4cadf8d1</guid>
            <category><![CDATA[information-technology]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[variables]]></category>
            <dc:creator><![CDATA[Keter Sammy]]></dc:creator>
            <pubDate>Fri, 20 Jan 2023 09:25:01 GMT</pubDate>
            <atom:updated>2023-01-20T09:25:01.665Z</atom:updated>
            <content:encoded><![CDATA[<p>If you are in the world of Computer Programming, you will most definitely come across the term ‘variable’ no matter the language or purpose of your program. Let’s go ahead and understand what this term means.</p><blockquote>According to <a href="https://dictionary.cambridge.org/dictionary/english/variable">Cambridge Dictionary</a>, the word <a href="https://dictionary.cambridge.org/dictionary/english/variable"><em>variable</em></a> means;</blockquote><blockquote>a). s<strong>omething that is likely to change often</strong></blockquote><blockquote>b). <strong>a number, amount, or situation that can change</strong></blockquote><blockquote><strong>c). a letter or symbol that represents any of a set of values</strong></blockquote><p>This article serves to give an informed explanation of the term in Computer Programming context that is more inclined to the second and third definitions above.</p><p><a href="https://launchschool.com/books/ruby/read/variables">Launch School</a> has a very good definition of a variable with regards to computer programming as follows:</p><blockquote><strong>Variables</strong> are used to store information to be referenced and manipulated in a computer program. They also provide a way of labeling data with a descriptive name, so our programs can be understood more clearly by the reader and ourselves. It is helpful to think of variables as containers that hold information. Their sole purpose is to label and store data in memory. This data can then be used throughout your program.</blockquote><figure><img alt="Illustration of Variable by CompSci; https://sites.google.com/a/iharrow.org.uk/compsci/2-2-programming/2-2-1-programming-concepts" src="https://cdn-images-1.medium.com/max/407/1*1zhuKWJ86YWlMB7zK1RzBg.jpeg" /><figcaption>Illustration of a Variable by CompSci</figcaption></figure><p>We have now established variables as ‘placeholders’ or ‘boxes’ that we can use to store data or values. In order to use them, they need to be given names. Each programming language has naming conventions or rules that govern how variables are given names. The naming conventions dictate the naming syntax of what characters can or cannot be used, capitalization, case sensitivity, etcetera.</p><p>We cannot exhaust all the naming conventions for all languages in this article, however, giving a meaningful and descriptive name that communicates the purpose of the variable is common to all programming languages. Language specific documentations are a good place to find the naming conventions for each language.</p><p>Now that we understand what variables are and how to name them, let’s see how they can be used. First, here are some terms that are associated with variables in programming:</p><p><strong><em>Declare/Define:</em></strong><em> this simply means creating a variable.<br></em><strong><em>Assign/Store:</em></strong><em> once a variable is created, you put a certain value inside it. In most programming languages, ‘=’ is used for assigning values.</em></p><p><strong><em>Accessing:</em></strong><em> the point of storing a value in a variable is so that it can be accessed for use.<br></em><strong><em>Modify/Change:</em></strong><em> this means substituting the value inside a variable for a new one.</em></p><p><strong><em>Scope:</em></strong><em> means how far the variable is accessible for use to sections of a program.</em></p><p>These are just but a few to mention. You can refer to more details <a href="https://www.tutorialspoint.com/computer_programming/computer_programming_variables.htm"><em>here</em></a> and <a href="https://launchschool.com/books/ruby/read/variables#assigningvaluetovariables"><em>here</em></a>.</p><h3><strong>Types of variables.</strong></h3><p>There are five types of variables. Constants, global variables, class variables, instance variables, and local variables.</p><p><strong><em>Constants:</em></strong> they are used for storing data that never needs to change.</p><p><strong><em>Global variables:</em></strong> these variables are available throughout your entire app/program, overriding all scope boundaries.</p><p><strong><em>Class variables:</em></strong> these variables are accessible by instances of your class, as well as the class itself. Class variables must be initialized at the class level, outside of any method definitions.</p><p><strong><em>Instance variables: </em></strong>these variables are available throughout the current instance of the parent class. Instance variables can cross some scope boundaries, but not all of them.</p><p><strong><em>Local variables:</em></strong> the most common variables you will come across and obey all scope boundaries.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=368e4cadf8d1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>