<?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 Chukwunonso Nwafor on Medium]]></title>
        <description><![CDATA[Stories by Chukwunonso Nwafor on Medium]]></description>
        <link>https://medium.com/@stepchuks94?source=rss-33072c96a6ae------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*2YYaYUpKZdAqQruw.jpg</url>
            <title>Stories by Chukwunonso Nwafor on Medium</title>
            <link>https://medium.com/@stepchuks94?source=rss-33072c96a6ae------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 19:37:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@stepchuks94/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[Always Design for C Arrays — the copy subroutine]]></title>
            <link>https://stepchuks94.medium.com/always-design-for-c-arrays-the-copy-subroutine-f09178a421a4?source=rss-33072c96a6ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/f09178a421a4</guid>
            <category><![CDATA[range]]></category>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[cpp]]></category>
            <dc:creator><![CDATA[Chukwunonso Nwafor]]></dc:creator>
            <pubDate>Tue, 23 Apr 2024 15:32:00 GMT</pubDate>
            <atom:updated>2024-04-24T20:10:01.031Z</atom:updated>
            <content:encoded><![CDATA[<h3>Always Design for C Arrays — the copy subroutine</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*rbA62xbNiB8HDzdtLKPWRQ.jpeg" /><figcaption>Wolfgang hasslemann — unsplash</figcaption></figure><p>Last time, <a href="https://stepchuks94.medium.com/always-design-for-c-arrays-from-subarray-to-range-and-back-98defb5380b6">Always Design for C arrays — from subarray to range and back</a>, we introduced subarrays with the c array, we also showed how to map ranges to size.</p><p>A quick recap. A range [<em>i</em>, <em>j</em>) is a sequence of integers <em>i</em>, <em>i</em>+1, . . ., <em>j</em>-1 and has exactly <em>j</em>-<em>i</em> elements.</p><h3>Copying subarrays</h3><p>Given an array</p><pre>const size_t n = 256;<br>int buf[n];</pre><p>We can fill it with consecutive integers</p><pre>fillIota(&amp;buf[0], n, 0);</pre><p>where <em>fillIota</em> is defined as</p><pre>template &lt;class T&gt;<br>// requires T is integer type or real type<br>inline void<br>fillIota(T* f, int64_t n, const T&amp; val) {<br>  int64_t i;<br>  for (i=0; i&lt;n; ++i, ++val) f[i] = val;<br>}</pre><p>What if we want to copy the values of a subarray | &amp;<em>buf</em>[<em>i</em>], <em>j</em>-<em>i</em> | of range [<em>i</em>, <em>j</em>) to a subarray | &amp;<em>buf</em>[<em>k</em>], <em>l</em>-<em>k </em>| of range [<em>k</em>, <em>l</em>) ?</p><p>Like,</p><pre>size_t i = 2, j = 5, k = 7;<br>copy(&amp;buf[i], j-i, &amp;buf[k]);</pre><p>Here we assume that the subarray starting at index <em>k </em>has enough space to contain <em>j</em>-<em>i</em> elements. Notice also that there is no need to specify the size of the subarray starting at &amp;<em>buf</em>[<em>k</em>].</p><p>The <em>copy</em> subroutine can be defined as</p><pre>template &lt;class T&gt;<br>inline void<br>copy (T* in, int64_t n, T* out) {<br>  int64_t i;<br>  for (i=0; i&lt;n; ++i) out[i] = in[i];<br>}</pre><p>There is no need returning the number of elements copied since this is already known by the value n from the caller of the subroutine.</p><h3>Using copy to make room for Inserted element</h3><p>What if we want our array to have more room in case we want to append or insert a new element at a specific location?</p><p>We bring in the concept of capacity.</p><p>Consider the array,</p><pre>size_t cap = 256, len = 200;<br>int buf[cap];</pre><p>Here, we differentiate the size from the capacity denoted by variables <em>len</em> and <em>cap</em> respectively.</p><p>We can fill in the array of size <em>len</em> with,</p><pre>fillIota(&amp;buf[0], len, 0);</pre><p>What if we want to insert the value 400 at position 100 of the array? Well we can do that as shown below</p><pre>insert(&amp;buf[0], len, 100, 400);</pre><p>where <em>insert</em> is defined as</p><pre>template &lt;class T&gt;<br>inline void<br>insert(T* f, int64_t n, int64_t i, const T&amp; val) {<br>  copy(f+i, n-i, f+i+1);<br>  f[i] = val;<br>}</pre><p>Here we use pointer arithmetic as arguments to the copy subroutine.</p><p>Given a pointer <em>p</em> and an index <em>i</em> as shown below</p><pre>int* p = &amp;buf[0];<br>size_t i = 100;</pre><p>The following two expressions</p><pre>p + i</pre><p>and</p><pre>buf[i]</pre><p>references the same element.</p><p>If we were to write the insert subroutine as a routine in the block where array <em>buf</em> is defined, we would have,</p><pre>size_t i = 100;<br>int val = 400;<br>copy(&amp;buf[i], len-i, &amp;buf[i+1]);<br>buf[i] = val;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f09178a421a4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Always Design for C arrays — From subarray to range and back]]></title>
            <link>https://stepchuks94.medium.com/always-design-for-c-arrays-from-subarray-to-range-and-back-98defb5380b6?source=rss-33072c96a6ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/98defb5380b6</guid>
            <category><![CDATA[cpp]]></category>
            <category><![CDATA[c-array]]></category>
            <category><![CDATA[range]]></category>
            <category><![CDATA[interval]]></category>
            <category><![CDATA[subarray]]></category>
            <dc:creator><![CDATA[Chukwunonso Nwafor]]></dc:creator>
            <pubDate>Wed, 17 Apr 2024 16:58:49 GMT</pubDate>
            <atom:updated>2024-04-24T20:07:01.729Z</atom:updated>
            <content:encoded><![CDATA[<h3>Always Design for C arrays — From subarray to range and back</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*Cmjkw6tsihZr3nVnW58wlQ.jpeg" /><figcaption>ganapathy kumar — unsplash</figcaption></figure><p>C arrays are not range-checked, fixed-sized, and fast; just the way we like it.</p><p>Guess what, even variable-sized arrays are fixed-sized. A fixed-sized array is allocated, when its length reaches its capacity, another fixed-sized array of a higher size is allocated and the old data copied to the new array.</p><p>Its all fixed-sized. vector is a c-array, string is also a c-array.</p><h3>Fixed-sized arrays are subarrays</h3><p>Given the array declaration,</p><pre>const size_t n = 256;<br>int buf[n];</pre><p>The following pairs</p><pre>| &amp;buf[0], n |    // entire array<br>| &amp;buf[5], 2 |    // subarray representing range [5,7) of range (0, 256)</pre><p>are subarrays of array buf.</p><p>Assuming the entire array is filled with zero’s</p><pre>fill(&amp;buf[0], n, 0);</pre><p>We can fill specific subarrays for example the subarray | &amp;buf[5], 2 | with</p><pre>fill(&amp;buf[5], 2, 4);</pre><p>where the function fill, is defined as</p><pre>template &lt;class T&gt;<br>inline void<br>fill(T* f, int64_t n, const T&amp; val) {<br>  for (--n; n &gt;= 0; --n) f[n] = val;<br>}</pre><h3>From Range to Subarray</h3><p>A range is an arithmetic progression.</p><p>A range [i, j] is a sequence of integers i, i+1, . . ., j</p><p>A range [i, j) is a sequence of integers i, i+1, . . ., j-1</p><p>A range (i, j] is a sequence of integers i+1, . . ., j-1</p><p>A range (i, j) is a sequence of integers i+1, . . ., j-1</p><p>We consider the range [i, j) as default.</p><p>The size n of a range [i, j) can be gotten from the difference j-i.</p><p>Thus,</p><pre>n = j-i</pre><p>Given this, we can represent ranges with C subarrays.</p><p>The subarray with range [i, j) can be represented as</p><pre>| &amp;buf[i], j-i |</pre><p>Consider the function below</p><pre>template &lt;class T&gt;<br>inline void<br>incrementArrayByVal(T* f, int64_t n, const T&amp; val) {<br>  for (--n; n &gt;= 0; --n) f[n] += val;<br>}</pre><p>We can call it with subarray | &amp;buf[i], j-i | as follows</p><pre>increaseArrayByVal(&amp;buf[i], j-i, val);</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=98defb5380b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Core of a language — Tokens — Literals]]></title>
            <link>https://medium.com/algorithmcity/core-of-a-language-tokens-literals-52bc910b84fb?source=rss-33072c96a6ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/52bc910b84fb</guid>
            <category><![CDATA[language-semantics]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[program-language-design]]></category>
            <category><![CDATA[language-syntax]]></category>
            <dc:creator><![CDATA[Chukwunonso Nwafor]]></dc:creator>
            <pubDate>Wed, 13 Dec 2023 08:16:35 GMT</pubDate>
            <atom:updated>2023-12-13T08:16:35.427Z</atom:updated>
            <content:encoded><![CDATA[<h3>Core of a language — Tokens — Literals</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*HSyCGR-r0vtQq32ze8dmfA.jpeg" /><figcaption>johannes kopf — unsplash</figcaption></figure><h3>Tokens</h3><p>Tokens are primitives of a language. They’re</p><ol><li>identifiers</li><li>keywords</li><li>literals</li><li>operators</li><li>delimiters</li><li>comments</li></ol><h3>Literals</h3><p>Literals are values for specific data types. These literals can be grouped based on types depending on the language involved:</p><ol><li>Integer literal</li><li>Floating point literal</li><li>Character literal</li><li>String literal</li></ol><p>For languages like JavaScript</p><ol><li>Array literal</li><li>Object literal</li><li>RegExp literal</li></ol><p>JavaScript doesn’t differentiate between integer and floating point literals, it just uses the</p><ol><li>Number literal</li></ol><h3>Integer Literal</h3><p>Example of integer literals includes:</p><p>123, 45, 66662343, 72345,</p><h3>Floating Point Literal</h3><p>Example of floating point literals includes:</p><p>234.435, 3435.66, 7234.433432</p><h3>Character Literal</h3><p>Character literals depends on the number of bits used to represent a character in the particular character set. They are usually enclosed in single quotes. Examples include:</p><p>‘a’, ‘X’, ‘C’</p><h3>String Literal</h3><p>String literals depends on the number of bits used to represent a character or code-point in the specific character set. They are usually enclosed in double quotes. Examples include:</p><p>“Obi”, “Helloworld”, “bits”</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52bc910b84fb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/algorithmcity/core-of-a-language-tokens-literals-52bc910b84fb">Core of a language — Tokens — Literals</a> was originally published in <a href="https://medium.com/algorithmcity">Algorithmcity</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Programming languages, Core Semantics, JavaScript and C languages]]></title>
            <link>https://medium.com/algorithmcity/programming-languages-core-semantics-javascript-and-c-languages-fc645e17ac0a?source=rss-33072c96a6ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc645e17ac0a</guid>
            <category><![CDATA[program-language-design]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[c]]></category>
            <category><![CDATA[language-semantics]]></category>
            <dc:creator><![CDATA[Chukwunonso Nwafor]]></dc:creator>
            <pubDate>Wed, 29 Nov 2023 09:48:11 GMT</pubDate>
            <atom:updated>2023-11-29T09:48:11.403Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*bwr50i75qKKtONb3jWJzLA.jpeg" /><figcaption>by neom — unsplash</figcaption></figure><p>For a quick recap, check out <a href="https://medium.com/@stepchuks94/on-programming-languages-and-syntax-4965e91ae6d1">https://medium.com/@stepchuks94/on-programming-languages-and-syntax-4965e91ae6d1</a> first.</p><p>Most languages are composed of at least this five separate concepts:</p><ol><li>Character Set</li><li>Tokens</li><li>Declarations</li><li>Expressions</li><li>Statements.</li></ol><p>But for an in-depth view, we need a clearer understanding of specific concepts. We use JavaScript and C as case-studies.</p><h3>JavaScript.</h3><p>The above 5-part for JavaScript can be further divided into:</p><ol><li>Characer Set</li><li>Tokens and Declarations</li><li>Types, Variables and Literals</li><li>Expressions</li><li>Statements</li><li>Functions</li><li>Arrays</li><li>Objects</li><li>Modules.</li></ol><p>Functions and Modules are an elaboration of (2) above Declarations.</p><p>Array and Objects are an elaboration of (3) above Types.</p><h3>C.</h3><p>The 5-part concepts for C can be further elaborated as:</p><ol><li>Character Set</li><li>Tokens and Declarations</li><li>Types, Variables and Literals</li><li>Expressions</li><li>Statements</li><li>Functions</li><li>Arrays</li><li>Structures.</li></ol><p>Functions and Structures above is an elaboration of (2) above, Declaration, Function and Type Declaration to be exact.</p><p>Arrays is an elaboration of (3) above. Types.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc645e17ac0a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/algorithmcity/programming-languages-core-semantics-javascript-and-c-languages-fc645e17ac0a">Programming languages, Core Semantics, JavaScript and C languages</a> was originally published in <a href="https://medium.com/algorithmcity">Algorithmcity</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[On Programming languages and syntax]]></title>
            <link>https://stepchuks94.medium.com/on-programming-languages-and-syntax-4965e91ae6d1?source=rss-33072c96a6ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/4965e91ae6d1</guid>
            <category><![CDATA[language-syntax]]></category>
            <category><![CDATA[language-symantics]]></category>
            <category><![CDATA[programming-languages]]></category>
            <dc:creator><![CDATA[Chukwunonso Nwafor]]></dc:creator>
            <pubDate>Sat, 25 Nov 2023 13:26:09 GMT</pubDate>
            <atom:updated>2023-11-25T13:26:09.909Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*2kORmWkgwSi5rw1dJOdUOw.jpeg" /><figcaption>by lisa heeke — unsplash</figcaption></figure><p>Every modern mathematical formalism is composed of at most this four parts:</p><ol><li>Tokens</li><li>Declarations</li><li>Expressions</li><li>Statements.</li></ol><p>Tokens can be further divided into</p><ol><li>Identifiers</li><li>Literals (Numeric, Char and String)</li><li>Keywords</li><li>Comments</li></ol><p>Declarations can contain this or more</p><ol><li>Type declaration</li><li>Variable declaration</li><li>Function declaration</li><li>Module declaration</li></ol><p>Expressions can contain this, less or more</p><ol><li>Arithmetic expressions</li><li>Boolean expressions</li><li>Comparison expressions</li><li>Relational expressions</li></ol><p>Statements can contain this, less or more</p><ol><li>Assignment statement</li><li>Function calls</li><li>If-else if — else statement</li><li>While statement</li><li>For statement</li><li>Return statement</li><li>Try-Catch statement</li><li>Exit statement</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4965e91ae6d1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Magna Carta — Language Agnostic Reasoning]]></title>
            <link>https://stepchuks94.medium.com/magna-carta-language-agnostic-reasoning-e5a12d37dc04?source=rss-33072c96a6ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5a12d37dc04</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[mathematical-reasoning]]></category>
            <category><![CDATA[computers]]></category>
            <category><![CDATA[programming-languages]]></category>
            <dc:creator><![CDATA[Chukwunonso Nwafor]]></dc:creator>
            <pubDate>Thu, 27 May 2021 12:48:18 GMT</pubDate>
            <atom:updated>2021-05-27T12:48:18.408Z</atom:updated>
            <content:encoded><![CDATA[<h3>Magna Carta — Language Agnostic Reasoning</h3><p><em>Stop…. Think, Plan, then Code.</em></p><p><em>When in doubt, choose efficiency.</em></p><p><em>Don’t call hardware-related stuff, UNSAFE, you might offend the digital world and its representatives.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*-fsTUeQXQ3_DkKEQiwzdIA.jpeg" /><figcaption>Jordan Harrison — unsplash</figcaption></figure><h3>Introduction</h3><p>Consider a laborer tasked with clearing a land. In his toolbox, a cutlass. With the cutlass he can be able to finish his work. Now imagine if he is given a lawn mower, well you can agree with me that if he puts in the right amount of effort with the lawn mower, he can be able to finish his work on time and of course more conveniently.</p><p>Many a programmer put more emphasis on the tool instead of the task assigned. A task can be solved using C++, C, Java etc. but all languages are not equal. Like George Orwell’s animal farm, “All languages are equal, but some are more equal than others”. A programmer must see a language as a tool to an end.</p><p>We also have to understand and appreciate the fact that some languages are created for specific domains. For example, JavaScript for the browser environment. It would be nonsensical to say you want to use say Java for the browser. It is just not created for that domain except maybe if you compile to JavaScript or an alternative like <em>Wasm</em>.</p><h3>Two ends of the Spectrum</h3><p>At the extremes, we have the digital world (represented by the computer) and the physical world (represented by the programmer). A programmer needs to map the constructs of the physical world to the digital world.</p><h3>Modeling Reality</h3><p>A computer understands bits (0’s and 1’s, low’s and high’s etc.). While a programmer can reason using bits, he would be more productive using constructs that best reflect the problems he deals with in the physical world.</p><p>A programmer knows <em>mathematical reasoning</em>. He can conveniently work with sets and multisets thus he understands the notion of character sets and symbols sets. He knows <em>number theory</em> thus he understands types like the integers, reals and there associated operations. He knows <em>logic</em> thus he understands true and false, AND, OR etc. He knows <em>algebra</em> thus he understands and uses identifiers to represent abstract things.</p><p>But how can a programmer map these to the resources the computer offers. Mind you, a computer might offer resources like the <em>processor</em>, <em>network</em> <em>adapter</em>, <em>memory</em>, <em>screen</em>, <em>camera</em>, <em>disk</em> etc. More importantly, how can a programmer <em>access</em> these resources to complete his task. Surely if he wants to create a <em>video conference software</em>, he must utilize the camera, the network adapter, the screen, the disk etc.</p><h4>A Computer’s Resource</h4><p>A computer provides different resources. Consider that a programmer wants to <em>persist data</em> on <em>disk</em>. Well using a <em>file abstraction</em>, he has to <em>open</em><strong><em> </em></strong>the file, <em>write</em> to the file, then <em>close</em> the file.</p><p>If you consider the fact that most computers are <em>multi-user</em>, <em>multi-threaded</em>, <em>multi-processed</em>, <em>multi-tasked</em>, then you now have to account for the fact that the disk might be in use by another user, thread or process etc. If in use, <em>should you wait</em>?, how long will you wait?, should <em>you abscond</em>?. How would you specify these different concerns. Most abstractions of a computer’s resources use terms like <em>blocking</em>, <em>non-blocking</em>, <em>asynchronous</em>, <em>synchronous</em> etc.</p><h4>Language Evolution</h4><p>The characters used by a language to represent its constructs must come from a <em>character set</em>. The very implementation of a language assigns meaning to the character sequences that are well-formed according to its syntax. However these constructs are the primitives of the language and they must come from a language’s <em>symbol</em> or <em>token set</em>.</p><p>Tokens or symbols usually include <em>keywords</em>, <em>operators</em>, <em>delimiters</em>, <em>literals</em>, <em>identifiers</em>, <em>comments</em> etc.</p><p>The question now is, what are the basic constructs required in a language that a programmer can use to solve his problems. Well, <em>types</em> must be there. <em>expressions</em> must be there, <em>variables</em> must be there, <em>statements</em> also etc.</p><h4>Basic types</h4><p>Assume our language has four basic types <em>integer</em>, <em>character,</em> <em>real</em>, and <em>string</em>. If I introduce two <em>keywords</em> into the language <em>let</em> and <em>be</em>, together with the <em>identifier</em> token, the assignment operator and a statement terminator, I can declare <em>variables</em> to be of type <em>integer</em>, assign values to it then perform an <em>operation</em> called an <em>expression</em>, then print out the expression assuming we are provided the <em>print</em> utility, using the following <em>character sequence</em>.</p><pre><strong>let</strong> a, b <strong>be</strong> <strong>integer</strong>;<br>a = 2; b = 3;<br>print(a+b);</pre><h4>Evolution 1 — promoting reuse using subroutines</h4><p>We want an identifier we can always call like we do in mathematics. Thus we add <em>functions</em> to our language. With it we introduce the keywords <em>function</em> and <em>return, start</em> and <em>end</em>. Re-writing our example above to print the some of the arguments passed to it, we have</p><pre><strong>function</strong> sum(<strong>let</strong> a, b <strong>be</strong> <strong>integer</strong>) : <strong>integer<br>start<br>    return</strong> a+b;<br><strong>end</strong></pre><pre>print(sum(2, 3));</pre><h4>Evolution 2 — subroutines that don’t return values</h4><p>We introduce the keyword <em>procedure</em> to account for subroutines that don’t return values.</p><pre><strong>procedure</strong> print_sum(<strong>let</strong> a, b <strong>be</strong> <strong>integer</strong>)<br><strong>start<br>    </strong>print(a+b);<br><strong>end</strong></pre><pre>print_sum(2, 3);</pre><h4>Evolution 3 — user-defined types (a container of primitive types)</h4><p>Assuming we are told to model the details of an employee of an organization, with the current state of our language, we can do something like:</p><pre><strong>let</strong> first_name, last_name <strong>be string</strong>;<br><strong>let</strong> salary <strong>be real</strong>;<br><strong>let</strong> age <strong>be</strong> <strong>integer</strong>;<br><strong>let</strong> gender <strong>be</strong> <strong>character</strong>;</pre><pre>first_name = &quot;Obi&quot;;<br>last_name = &quot;Nwala&quot;;<br>salary = 80000.0; <br>age = 23;<br>gender = &#39;M&#39;;</pre><p>Now assuming we want to increase Obi’s salary by $50,000 after the first year, we can do something like this:</p><pre>salary = salary + 50000.0;</pre><p>Now assuming I want to create record for Adaku and Adaugo, do I have to declare types like this for them. You can see that this can easily get out of control. How can we go about solving this problem.</p><p>Enter the user-defined type. We group variables of primitive types or other user-defined types and create variables of this user-defined types to represent each individual employee.</p><p>We introduce keywords <em>struct</em>. We show an example use below.</p><pre><strong>let</strong> Employee <strong>be struct</strong><br><strong>start</strong><br>    first_name: <strong>string</strong>;<br>    last_name: <strong>string</strong>;<br>    salary: <strong>real</strong>;<br>    age: <strong>integer</strong>;<br>    gender: <strong>character</strong>;<br><strong>end</strong></pre><pre><strong>let</strong> Obi, Adaku, Adaugo <strong>be Employee</strong>;</pre><pre>Obi.first_name = &quot;Obi&quot;;<br>Obi.last_name = &quot;Nwala&quot;;<br>Obi.salary = 80000.00;<br>Obi.age = 23;<br>Obi.gender = &#39;M&#39;;</pre><pre>Adaku.first_name = &quot;Adaku&quot;;<br>Adaku.last_name = &quot;Nweke&quot;;<br>Adaka.salary = 85000.00;<br>Adaku.age = 22;<br>Adaku.gender = &#39;F&#39;;</pre><p>We can then increase Obi’s salary as</p><pre>Obi.salary = Obi.salary + 50000.0;</pre><p>Continued in Part 2.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5a12d37dc04" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Microsoft’s Windows Operating System — A programmer’s perspective]]></title>
            <link>https://stepchuks94.medium.com/microsofts-windows-operating-system-a-programmer-s-perspective-f71878cc651d?source=rss-33072c96a6ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/f71878cc651d</guid>
            <category><![CDATA[operating-systems]]></category>
            <category><![CDATA[windows]]></category>
            <category><![CDATA[windows-10]]></category>
            <category><![CDATA[operating-system-process]]></category>
            <dc:creator><![CDATA[Chukwunonso Nwafor]]></dc:creator>
            <pubDate>Tue, 11 May 2021 00:45:18 GMT</pubDate>
            <atom:updated>2021-05-11T01:00:08.214Z</atom:updated>
            <content:encoded><![CDATA[<h3>Microsoft’s Windows Operating System — A programmer’s perspective</h3><p><em>Microsoft Technology, fighting the good fight since 1975.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*JcEmKaU_u-2c9eTkbjVuZw.jpeg" /><figcaption>Andre Tan — Unsplash</figcaption></figure><h3>Introduction</h3><p>An operating system manages a computer’s hardware and presents the computer at a certain level of abstraction to the programmer and the end user.</p><p>This computer might be a PC, an Xbox console, a Hololens 2, Iot devices on Rasberry Pi you name it. For a software company, there comes the question, how do you manage all these devices? Do you create individual operating systems for them or do you create a single base that manages them all. If a single base, how do you create the base layer? How do you abstract different I/O devices? How can you make use of the device abstraction layer for say a Hololens 2 that doesn’t have a mouse and a keyboard?.</p><h3>Approach</h3><p>I will divide this work into two parts. The core part and the Developer’s part.</p><h3>The Core Part</h3><p>The Core part will explore</p><ol><li>The Overall systems architecture, its management and system mechanisms</li><li>The abstractions of Processes, Jobs and Threads and there controls and synchronization</li><li>The basic I/O and the Network I/O</li><li>Memory Management</li><li>Storage Management</li><li>Security</li><li>Hypervisor and Virtualization</li></ol><h3>The Developer’s Part</h3><p>The Developer’s part will explore</p><ol><li>The Win32 API</li><li>The .Net Framework with its CLR and FCL</li><li>The Windows Runtime (WinRT)</li><li>The Universal Windows Platform (UWP)</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f71878cc651d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Programmer’s Craft]]></title>
            <link>https://stepchuks94.medium.com/a-programmers-craft-45fe1533d392?source=rss-33072c96a6ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/45fe1533d392</guid>
            <category><![CDATA[programmer]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Chukwunonso Nwafor]]></dc:creator>
            <pubDate>Thu, 29 Apr 2021 03:19:48 GMT</pubDate>
            <atom:updated>2021-04-29T16:30:58.481Z</atom:updated>
            <content:encoded><![CDATA[<p><em>In memory of Egeoluka, truly loved and truly missed.</em></p><p><em>For certain reasons, I have come to appreciate the title ‘programmer’.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*NLGPqBPkOokBK5ZzoJtc7A.jpeg" /><figcaption>by Lukas Blazek — unsplash</figcaption></figure><p><strong>Note:</strong> The below might seem basic but I find them invaluable in completing my understanding of the programmer’s craft.</p><h3>A Programmers Task</h3><p>A programmer has two primary tasks.</p><ol><li>To instruct a digital computer.</li><li>To model reality.</li></ol><p>A computer <em>computes</em>, <em>stores</em> and <em>communicates</em>. That’s all it does and that’ s all it can ever be instructed to do.</p><ol><li>To compute— CPU or/and GPU</li><li>To store — Memory</li><li>To communicate — Array of I/O devices.</li></ol><h3>Tools for Reasoning</h3><p>To model reality, a programmer needs to have certain tools in his toolbox. They include but are not limited to.</p><ol><li>A model of computation — an abstraction of a computer’s architecture.</li><li>An abstraction of the resources provided by a computer called an <em>operating system</em>.</li><li>Program design techniques which include modular, procedural, oop patterns.</li><li>Algorithm design techniques which includes greedy, divide and conquer, dynamic programming, randomized algorithms etc.</li><li>Data types and structuring considerations.</li><li>Language features and concepts like regular languages and context-free languages, interpreters and compilers.</li><li>Mathematical reasoning</li></ol><h3>Problem Domain and Software Architecture</h3><p>The final piece of the puzzle involves a complete understanding of the problem domain we are trying to model and how we organize our solution which of course falls under software architecture.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45fe1533d392" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sql through Postgres — Django ORM without the ORM]]></title>
            <link>https://medium.com/postgresql-projects/sql-through-postgres-django-orm-without-the-orm-80af26331f5d?source=rss-33072c96a6ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/80af26331f5d</guid>
            <category><![CDATA[django-orm]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[postgres]]></category>
            <dc:creator><![CDATA[Chukwunonso Nwafor]]></dc:creator>
            <pubDate>Wed, 25 Nov 2020 11:41:08 GMT</pubDate>
            <atom:updated>2020-11-25T11:49:39.784Z</atom:updated>
            <content:encoded><![CDATA[<h3>Sql through Postgres — Django ORM without the ORM</h3><p><strong><em>updated</em></strong> for <strong><em>python 3.85</em></strong>, <strong><em>postgreSQL 13.1</em></strong> and <strong><em>django 3.1.3</em></strong></p><p><em>Using Ubuntu as the default.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*JeCVbMsT17tWEwk05HkVxw.jpeg" /><figcaption>by Jordan Harrison — unsplash</figcaption></figure><h3>First Things First</h3><p>We create a folder, activate a <strong><em>virtual environment </em></strong>in it, get <strong><em>django</em></strong> and a <strong><em>postgres database connector </em></strong>(<strong><em>psycopg2</em></strong>) and finally create a django project in our folder. ( I am using Ubuntu on WSL2).</p><pre>sudo apt update<br>mkdir psq &amp;&amp; cd psq<br>python3 -m venv env &amp;&amp; source env/bin/activate<br>python3 -m pip install django psycopg2<br>django-admin startproject psq .</pre><p>Checking what was installed:</p><pre>python3 -m pip freeze</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/172/1*2FRelrxbjgju1l3cvZ5tcg.png" /><figcaption>installed apps for our project</figcaption></figure><h4>psq/settings.py</h4><p>Go to our <strong><em>settings.py</em></strong> file in folder <strong><em>psq</em></strong> and update our database connection settings as shown</p><pre>DATABASE = {<br>  &#39;default&#39;: {<br>    &#39;ENGINE&#39;: &#39;django.db.backends.postgresql&#39;,<br>    &#39;NAME&#39;: &#39;&lt;database name&gt;&#39;,<br>    &#39;USER&#39;: &#39;&lt;database user&gt;&#39;,<br>    &#39;PASSWORD&#39;: &#39;&lt;database password&gt;&#39;,<br>    &#39;HOST&#39;: &#39;localhost&#39;,<br>    &#39;PORT&#39;: &#39;5432&#39;,<br>  }<br>}</pre><p>Update your database name, user, password accordingly. Mine from <a href="https://medium.com/postgresql-projects/sql-through-postgres-introduction-aab67fd84b97"><em>Sql through Postgres — Introduction</em></a> is shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*rTsEOKz5UQDRKSi5nZ5QjQ.png" /><figcaption>database settings for project.</figcaption></figure><h3>Without Further Ado</h3><p>Django allows you to connect directly to your database, bypassing the ORM completely using <strong><em>django.db.connection</em></strong> or <strong><em>django.db.connections</em></strong> if you are using more than 1 database. Let’s give it a shot. (<strong><em>Ensure your postgresql server is running</em></strong>).</p><pre>python3 manage.py shell</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*QBwXCLwiH7laB41ljruLgA.png" /><figcaption>sample data definition</figcaption></figure><p>Cross checking if our table was created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*_Xs4evPYguL6bW_3dUHkcQ.png" /><figcaption>cross checking in another terminal</figcaption></figure><h4>Sample Data Manipulations and Queries</h4><p>We will work exclusively from the <strong><em>python shell</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*ZL3IGXQHws3nS7hq_38NyQ.png" /><figcaption>simple data manipulation and queries</figcaption></figure><p><strong>Perform more inserts</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*ZryQGm02iIOzI3JZWpR-6w.png" /><figcaption>more inserts.</figcaption></figure><p><strong>Return the largest sale of each user</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*cS7Yr0WO-o3y84EmrVRmKw.png" /><figcaption>queries on table `sales`</figcaption></figure><p><strong>Result</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*MwQbndtMfVxmHKirzpD8VA.png" /><figcaption>result from largest sales query</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80af26331f5d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/postgresql-projects/sql-through-postgres-django-orm-without-the-orm-80af26331f5d">Sql through Postgres — Django ORM without the ORM</a> was originally published in <a href="https://medium.com/postgresql-projects">PostgreSQL Projects</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQL through Postgres — Introduction]]></title>
            <link>https://medium.com/postgresql-projects/sql-through-postgres-introduction-aab67fd84b97?source=rss-33072c96a6ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/aab67fd84b97</guid>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[wsl-2]]></category>
            <dc:creator><![CDATA[Chukwunonso Nwafor]]></dc:creator>
            <pubDate>Mon, 16 Nov 2020 11:16:30 GMT</pubDate>
            <atom:updated>2020-11-16T11:20:53.247Z</atom:updated>
            <content:encoded><![CDATA[<h3>SQL through Postgres — Introduction</h3><p><strong><em>updated</em></strong> for <strong><em>postgreSQL</em></strong> 13.1</p><p><em>A million accolade for the world’s most advanced open source RDMS.</em></p><p><em>I love Microsoft’s Windows Subsystem for Linux.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*wBkujNp9G-IDxk5GZPygiw.jpeg" /><figcaption>by Carlos Muza — Unsplash</figcaption></figure><h3>Meet PostgreSQL</h3><p>PostgreSQL is a RDMS that follows the client/server model. The server can be on the same host with the client or not (in which case it accesses the server through a TCP/IP connection).</p><p><strong>Windows and Mac OS:</strong> Download and Install on Windows and Mac from <a href="https://www.enterprisedb.com/downloads/postgres-postgresql-downloads"><strong><em>EDB postgres</em></strong></a></p><p><strong>On Ubuntu (WSL2):</strong> To install postgreSQL (client &amp; server) on linux, we use the below code. <strong><em>postgresq-contrib</em></strong> installs additional extensions.</p><pre>sudo apt update<br>sudo apt install postgresql postgresql-contrib</pre><p>The above install creates a user account postgres and a database postgres we can use to connect to the postgreSQL server.</p><p>We check the status of the server and start it if need be.</p><pre>sudo service postgresql status</pre><p>If need be start the server with</p><pre>sudo service postgresql start</pre><p>PostgreSQL allows us to use the <strong><em>createdb</em></strong>, <strong><em>dropdb</em></strong>, <strong><em>createuser</em></strong> etc commands with a valid user account. Thus we create a new user.</p><pre>sudo -u postgres createuser --interactive</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/397/1*dclGYx7Z9JX_EefRVEIvkA.png" /><figcaption>creating new user</figcaption></figure><p>We connect using account <strong><em>postgres</em></strong> to set password for our new user <strong><em>guser</em></strong>.</p><pre>sudo -u postgres psql postgres</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*-oB7pE8Kvew0Uru0ihxF1w.png" /><figcaption>change user ‘guser’ password</figcaption></figure><p>Now we can create a new database from bash and assign <strong><em>guser</em></strong> as the owner.</p><pre>sudo -u postgres createdb gdb --owner guser</pre><p>We can now connect to postgreSQL server with ‘guser’ using our database.</p><pre>psql -h localhost -p 5432 -U guser -d gdb</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/1*hfGPWCTE9XXKlp8i-VFKng.png" /><figcaption>connected to guser with gdb</figcaption></figure><p>We can perform <strong><em>SQL</em></strong> and <strong><em>psql</em></strong> operations as shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*I2VojWkQR4pwtfenXAXIvw.png" /><figcaption>example SQL and psql ops</figcaption></figure><p>We can exit <strong><em>psql</em></strong> using <strong><em>\q</em></strong> command.</p><p>To stop the server we use</p><pre>sudo service postgresql stop</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aab67fd84b97" width="1" height="1" alt=""><hr><p><a href="https://medium.com/postgresql-projects/sql-through-postgres-introduction-aab67fd84b97">SQL through Postgres — Introduction</a> was originally published in <a href="https://medium.com/postgresql-projects">PostgreSQL Projects</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>