<?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 Dave Amiana on Medium]]></title>
        <description><![CDATA[Stories by Dave Amiana on Medium]]></description>
        <link>https://medium.com/@ddamiana?source=rss-32103f4c576e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*OplTggkzJeE5Y8huGCdlVA.jpeg</url>
            <title>Stories by Dave Amiana on Medium</title>
            <link>https://medium.com/@ddamiana?source=rss-32103f4c576e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 13:47:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ddamiana/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[On Writing Unique Reference in C++]]></title>
            <link>https://medium.com/geekculture/on-writing-unique-reference-in-c-def51120bfdb?source=rss-32103f4c576e------2</link>
            <guid isPermaLink="false">https://medium.com/p/def51120bfdb</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[cpp]]></category>
            <dc:creator><![CDATA[Dave Amiana]]></dc:creator>
            <pubDate>Sun, 29 Aug 2021 11:02:52 GMT</pubDate>
            <atom:updated>2021-08-30T13:40:07.165Z</atom:updated>
            <content:encoded><![CDATA[<h4>Implementing Building Blocks of Reference Semantics: Unique Reference</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6uIr_pBTGM1m1MR8ty3pxg.jpeg" /><figcaption>Photo from Pexels.</figcaption></figure><p>Our previous discussion explores the anatomy of pointer types in C and C++ on par with hinting nuances of reference semantics. We discussed the use cases of raw pointers and smart pointers in modern C++ and found that there are degrees of aptness in choosing between automatic resource management over manual resource management. More specifically, we introduced std::unique_ptr&lt;T&gt; and demonstrated some of its functionalities.</p><p>This article discusses the design goals and implementation of std::unique_ptr&lt;T&gt;. However, instead of discussing the intricacies of the STL implementation in different C++ compiler distributions, we simplify this to express the design goals of a unique reference.</p><p>At the end of this article, we develop another layer of understanding with the functionalities of unique reference and implement our version of it.</p><h3>Design goals of unique reference</h3><p>Let us list down the requirements we must satisfy for implementing our version of the unique reference. Our implementation must satisfy the following.</p><ul><li>Must accept any type</li><li>Automatic resource management</li><li>Maintain the property of uniqueness</li><li>Pointer-like interface</li></ul><p>Our simple version of the std::unique_ptr&lt;T&gt; requires to be explicitly initialized with the object it refers to.</p><h3>Implementation</h3><p>Let us build up our implementation by fulfilling our design requirements one by one.</p><h4>Requirement: Must Accept any Type</h4><p>We begin with the simplest requirement *It must take any type*. We simply have to add a template parameter to our type (class) for this requirement to suffice this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XOtNuOyJnBP3eS9YRenm2w.png" /></figure><p>That’s it! We satisfied our first requirement.</p><h4>Requirement: Automatic Resource Management</h4><p>This is the elegant solution of the C++ abstraction mechanism that comes in: the answer is <a href="https://en.wikipedia.org/wiki/Resource_acquisition_is_initialization"><em>Resource Acquisition Is Initialization</em></a> or RAII.</p><p>RAII provides guarantees regarding the state of our class. Resource management is tied with class invariance the lifetime of an object. This is achieved by object constructors and destructors which are responsible for initialization and clean-up of resources.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hfa9vbE8_Q9QdYhflrPOQw.png" /></figure><p>The constructor is triggered when an instance of unique_reference is initialized -- that is why in other languages like <a href="https://docs.python.org/3/c-api/init_config.html">Python</a>, and <a href="https://docs.swift.org/swift-book/LanguageGuide/Initialization.html">Swift</a>, these are known as <em>initializers</em>. Meanwhile, destructors are triggered when an instance of unique_reference goes out of scope. Together, they serve our need for automatic resource management that gives us deterministic behavior which guarantees resource management. The deterministic behavior of our reference management gives superior property over implementing garbage collectors which may or may not clean up a piece of resource at the time an object went out of scope.</p><p>It seems that we managed our resources well. We initialized our pointer to nullptr upon construction and de-initialized it by deleting the contents of m_ptr. However, there is a subtle element of trouble that we still might leak our resources, even after setting m_ptr = nullptr. The compiler will not warn you with this, but you are shooting yourself in the foot.</p><p>To resolve this, we need to re-think our mental model of unique reference. At the time our object goes out of scope we want to destroy the object, not necessarily <em>delete</em> them abruptly. So we call the object’s destructor ~T().</p><p><em>Note that types that do not have user-provided destructors such as primitives are marked as </em><a href="https://en.cppreference.com/w/cpp/language/destructor"><em>trivial destructors</em></a>, which is why ~T() is valid for <a href="https://en.cppreference.com/w/cpp/language/types">primitives</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HRP_lF8c2dOIZg-9AQqVfA.png" /></figure><p>We’re doing great. Let’s keep going!</p><h4>Requirement: Maintain Property of Uniqueness</h4><p>For this, we want our unique reference to be able to transfer its ownership inside a function or a class when need be. By implementing the mechanism of transference, we need to maintain the property of uniqueness. We do so by incorporating <a href="https://bityl.co/8Fgd">move semantics</a>. There are two parts for enabling moveable ownership, our unique reference has to be: move constructible, and move assignable.</p><p>Let us work with our moveable constructors first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g9zl18iEihT8tCkelMD3MA.png" /></figure><p>Let us walk through what we are actually saying with the above snippet of code. First, we need to mark our constructors as explicit to avoid <a href="https://stackoverflow.com/questions/121162/what-does-the-explicit-keyword-mean">unexpected implicit conversions</a>. Then we make use of <a href="https://bityl.co/8G2V"><em>rvalue reference</em></a><em> </em>for our parameter which marks our class as move constructible. But before we handle move construction, we have to guarantee that upon construction we will not throw exceptions so we mark our noexcept specifier.</p><p>The body of our function is very trivial to implement. We want to take all the resources of our moved-from reference (other), and swap it with our moved-in object (this). That said, the second requirement (move assignable) is equally trivial to implement. We simply need to overload the assignment operator.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TiIM8otqv3xaOViO1HI5Qw.png" /></figure><p>We are essentially repeating the body of our assignment and constructor, so for consistency, let us implement a little helper function we declare in private which shall be responsible for swapping the objects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*145L5kShEfePIYYP19surQ.png" /></figure><p>Effectively, this results to:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FqhBziMY8Uw3g7vnIbEziQ.png" /></figure><p>Since we are discussing the constructors and assignment operators it is a good point to note about how to suppress them and why. The reason we want to suppress constructors are two folds: we want to explicitly mention that we do not intend this to happen, and we want the compiler to check if users try to access such modalities.</p><p>To do this, we simply write:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TXmu4yPeqQ0MF87iNPUQCQ.png" /></figure><p>Here, we suppressed copy-assignment and copy-construction since copying will defy the meaning of being unique.</p><h4>Requirement: Pointer-like Interface</h4><p>We need an interface to communicate with the state of our unique reference. For consistency, it has to resemble the interface of a pointer.</p><p>Recall that a pointer can be dereferenced with * and -&gt; operators. And we need &amp; operator to inspect the location of our pointer in memory. These are the basic operators we need to overload for our unique reference. To do this, we write:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QN6VDUiRAvMyFzszq35F_Q.png" /></figure><p>Let us walk through the three lines.</p><p>The first line returns a reference of *(this-&gt;m_ptr) which means that the content of m_ptr is accessed that which we can modify and read. The same idea goes with the arrow operator, we return a pointer to m_ptr&#39;s location in memory. The last operator is slightly different in that it returns the address of the pointer and not the referent. <a href="https://dcode.hashnode.dev/pointers-and-references-design-goals-and-use-cases">Recall</a> that a pointer has its own location in memory separate from the entities it points to.</p><h3>Putting it all together:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LjoL4AQJX1umyzuib8UdTw.png" /></figure><h3>Test Cases</h3><p>Time to see if we satisfied our design requirements:</p><p><a href="https://replit.com/@delvinjohn/UniqueReference#unique_reference.h">UniqueReference</a></p><blockquote>I’m not yet sure if the repl.it embedding works on your end. If this is inaccessible on your end, let me know.</blockquote><h3>Summary</h3><p>We fleshed out our design requirements and implemented our version of the unique reference to satisfy what we intend to do with unique references. Upon testing, we found that it sufficiently did what we want it to do: we now have the first piece of our automatic resource management!</p><p>Since that we implemented a simple unique reference class, try to think about how we can extend this for an array-like interface as your homework. Doing this part on your own gives you room to re-think what we did with our unique_reference.</p><p>Have fun hacking!</p><h3>References</h3><p>- Wikipedia contributors. (2021, May 21). Resource acquisition is initialization. In Wikipedia, The Free Encyclopedia. Retrieved 07:06, August 17, 2021, from <a href="https://en.wikipedia.org/w/index.php?title=Resource_acquisition_is_initialization&amp;oldid=1024395395">https://en.wikipedia.org/w/index.php?title=Resource_acquisition_is_initialization&amp;oldid=1024395395</a>.</p><p>- Python (2021). Python Initialization Configuration Reference Manual. <a href="https://docs.python.org/3/c-api/init_config.html">https://docs.python.org/3/c-api/init_config.html</a>.</p><p>- Swift (2021). Swift Language Guide. <a href="https://docs.swift.org/swift-book/LanguageGuide/Initialization.html">https://docs.swift.org/swift-book/LanguageGuide/Initialization.html</a>.</p><p>- cppreference.com (2021). Destructors. <a href="https://en.cppreference.com/w/cpp/language/destructor">https://en.cppreference.com/w/cpp/language/destructor</a>.</p><p>- cppreference.com (2021). Fundamental types. <a href="https://en.cppreference.com/w/cpp/language/types">https://en.cppreference.com/w/cpp/language/types</a>.</p><p>- StackOverflow (2010). What is move semantics? <a href="https://stackoverflow.com/questions/3106110/what-is-move-semantics">https://stackoverflow.com/questions/3106110/what-is-move-semantics</a>.</p><p>- StackOverflow (2009). What does the explicit keyword mean? <a href="https://stackoverflow.com/questions/121162/what-does-the-explicit-keyword-mean">https://stackoverflow.com/questions/121162/what-does-the-explicit-keyword-mean</a>.</p><p>- Triangles (2019). C++ rvalue references and move semantics for beginners. <a href="https://www.internalpointers.com/post/c-rvalue-references-and-move-semantics-beginners">https://www.internalpointers.com/post/c-rvalue-references-and-move-semantics-beginners</a>.</p><p>- Amiana, D. (2021). Pointers and References: Design Goals and Use Cases. <a href="https://dcode.hashnode.dev/pointers-and-references-design-goals-and-use-cases">https://dcode.hashnode.dev/pointers-and-references-design-goals-and-use-cases</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=def51120bfdb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/on-writing-unique-reference-in-c-def51120bfdb">On Writing Unique Reference in C++</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[On Pointer Types]]></title>
            <link>https://medium.com/geekculture/on-pointer-types-f3fc92206b98?source=rss-32103f4c576e------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3fc92206b98</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[cpp]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Dave Amiana]]></dc:creator>
            <pubDate>Mon, 23 Aug 2021 06:02:52 GMT</pubDate>
            <atom:updated>2021-08-23T06:02:52.164Z</atom:updated>
            <content:encoded><![CDATA[<h4>Peeking at Reference Semantics</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yK-LDwN9JNvHHj101gR7vg.jpeg" /><figcaption>Photo by <a href="https://www.pexels.com/@ron-lach?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Ron Lach</a> from <a href="https://www.pexels.com/photo/children-peeking-on-a-circular-window-8544496/?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Pexels</a></figcaption></figure><p>In this article, I aim to introduce the concept and motivation behind using pointers. There are breeds of C++ developers that only use smart pointers for safety reasons, others that only use raw pointers for performance benefits, and some that use both whenever they provide the utmost benefits. In this article, I aim to highlight the use-cases of pointers so you can decide when to use one.</p><p>Conceptually, a pointer is a kind of reference. That is, a pointer refers to a certain block of memory of which acts as an entry point. To access the contents or modify the value of a pointer, we <em>dereference</em> it. Many languages have pointer-like features. Our concern revolves around the context of C and C++. Note that all C functions are valid in C++ but the opposite is not true. For this reason, our section on smart pointers is only applicable to C++.</p><p>Pointers are the basic structure to achieve reference semantics. Pointers are handy for naming another entity to be attributed by the contents of the referent entity. A pointer may access and manipulate the contents of the entity that it is <em>pointed</em> to, consider:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3YOqTXvU3YqY6Z9fccGmcw.png" /></figure><p>Pointers are introduced in C for the following reasons:</p><ul><li>Inexpensive parameter passing.</li><li>Allocate memory for new objects on the heap.</li><li>Passing a function reference to a function.</li><li>Iterate over data structures.</li></ul><p>The same thing is true in C++. In fact, iterators (a component for iterating over C++ Containers) resemble the interface of a pointer. But C++ has more to offer with a different set of modalities one can express reference semantics. We will focus on the set of reference modalities known as smart pointers. But before that, let us present a compelling reason for using smart pointers by enumerating the problems of raw pointers.</p><h3>Raw Pointers</h3><p>Raw pointers are low-level types that pertain to a certain block of memory. As mentioned, pointers are entry points to access a value or modify it in a specific location in memory.</p><p>Some languages have restrictions on pointer types to a varying degree. For example, <a href="https://www.adacore.com/uploads_gems/03_safe_secure_ada_2005_safe_pointers.pdf">Ada</a> initializes a default value of their pointer types to null and makes a restriction for type conversions involving pointers mostly for type safety. While languages like <a href="https://www.youtube.com/watch?v=ci1PJexnfNE">Java </a>have banned the use of low-level pointer types to reduce programming error.</p><p>Therein creeps in the subtle shades of pointers. Now we ask what is the scene of pointer types in C?</p><p>In languages like C and C++, pointer types are very much used for low-level programming. Type conversion of pointer types has a varying degree of restrictions. In C, void * types are considered as raw pointer types which can be morphed into any type by an operation called typecasting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7N5Q5GHZMH4QOONHmpBdPA.png" /></figure><p>The above snippet demonstrates that a void * type can be cast into an int *, or <em>any</em> type in that regard. Albeit not apparent with the above example, this is useful for abstraction which is a matter that we will not talk about here.</p><p>Raw pointers are concrete implementation of the more abstract concept of reference. Unlike Ada, raw pointers in C/C++ are not initialized in a null value, although they can refer to null which is a safer way of using raw pointers: if not initialized with the address of a referent, initialize it with nullptr (in C++) and NULL (in C). The reason behind this is to achieve well-defined behavior and avoid bugs that can be very difficult to fix, let alone find.</p><p>Raw pointers will not impose anything so misusing or abusing it are very easy to commit.</p><h4>The Dangling Problem:</h4><p>Let us consider an instance that we are likely to encounter the dangling pointer problem. Let’s take a look at allocating and deallocating resources using new and delete function in C++ and malloc (calloc) or free in C.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ATN9KUQKNEhFiA6DWWXLHQ.png" /></figure><p>Note that delete or free functions only <em>remove</em> the contents of an entity, in this case, i. That is, dereferencing i still returns the memory location of i before it was deleted. This is problematic for it may introduce undefined behavior: dereferencing to an already freed memory is dangerous. To resolve this, we have to make sure that the i references to a well-defined location in memory hence we put i = nullptr (in C++) and i = NULL (in C) after deleting the contents of i to avoid critical mistakes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z8DnnBd0EB2l0AS_D_vYCQ.png" /></figure><p>Another problem comes with determining the owning pointer which can result in serious issues from resource leaks, undefined behaviors to security vulnerabilities. Which pointer is responsible for which entity? It is difficult to keep track of multiple references and make sure that at the end of the scope such references are correctly managed. There has to be a clear expression to determine the owning pointer. Because of this, C++ introduced a reference management system that revolves around the idea of <a href="https://docs.microsoft.com/en-us/cpp/cpp/object-lifetime-and-resource-management-modern-cpp?view=msvc-160">RAII</a>.</p><h3>Smart Pointers</h3><p>From the <a href="http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#???">C++ Standard</a> :</p><blockquote>Enforcing the lifetime safety profile eliminates leaks. When combined with resource safety provided by RAII, it eliminates the need for “garbage collection” (by generating no garbage). Combine this with enforcement of the type and bounds profiles and you get complete type- and resource-safety, guaranteed by tools.</blockquote><p>C++ introduced a set of classes for automatic resource management with very minimal to zero-cost performance penalties. Using these set of pointers has the following set of benefits:</p><ul><li>clarity of expressing ownership</li><li>guarantees that resources will not leak</li></ul><p>When appropriate, we should be using smart pointers for clearly expressing our intent with the kind of ownership we want to establish between the pointer and the entity it refers to. We have three smart pointers: std::unique_ptr&lt;T&gt;, std::shared_ptr&lt;T&gt;, and std::weak_ptr&lt;T&gt;. We can access these modalities in the &lt;memory&gt; header file.</p><p>Let us walk through and discover what these reference modalities have to offer. For our demonstration let us consider a class named Entity defined as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-5jxA0vx-43-wohOLPTtcg.png" /></figure><h4>Unique Pointer</h4><p>Unique pointer maintains that there is only one pointer responsible for a given resource in memory. The owning pointer is responsible for the clean-up and resource management.</p><p>Let us define an instance of Entity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vAou82vvnSBP7pxI3tjCVQ.png" /></figure><p>Now, let us consider passing the pointer by reference and with move constructors to see its effect on where Entity is destroyed. Passing the unique pointer by reference means that the unique pointer is extended to a function, hence the clean-up happens after the unique pointer goes out of scope from the main function where it has been declared.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Acv703phupJ80FLXn_vEmg.png" /></figure><p>Passing the unique pointer with move constructors is transferring ownership to the unique pointer defined in function f(). We can notice the behavior has we run the following snippet:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dxC4IP15m5huGftucwhsmw.png" /></figure><p>Since we transferred the ownership of e to entity, the clean-up happened as soon as the entity exits the function.</p><h4>Shared Pointer</h4><p>The shared pointer has an additional mechanism called reference counting where it keeps track of pointers that request for sharing resources. Each time another pointer asks for shared resources, the reference counter adds one and for every time it goes out of scope it removes one. At the time where the reference count is 0, it calls for the clean-up. We can observe this mechanism with the following code snippet:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GNpPBJzh3M5mfo3eCPN_CQ.png" /></figure><p>When I first encountered this, I thought that is all I need, unique pointers and shared pointers are all there is to it. Until I encountered this problem called circular references where the troubles of shared references kick in. It is possible to break the guarantees of the shared pointer by forming a loop of circular references which results in resource leaks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xaX6GLVPbzL311fq" /><figcaption>Photo by <a href="https://unsplash.com/@jeremyperkins?utm_source=medium&amp;utm_medium=referral">Jeremy Perkins</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>The Circular Reference Problem</h4><p>A circular reference has the form A→B, B→A. Let us put this into code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d-2umBzdRt4IsaKfxE5QDg.png" /></figure><p>Since A→B and B→A, the reference count will never resolve to zero — the condition which std::shared_ptr&lt;T&gt; does its clean-up. We can observe the reference counts by theuse_count() function. Let us modify the main function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5xRSU26XdfHvYe8YU7Htbg.png" /></figure><blockquote>How do we break the curse? Introducing Weak Pointers.</blockquote><h4>Weak Pointer</h4><p>A weak pointer is a special type of pointer in conjunction with shared pointers. With weak pointers, you can access the contents of the shared pointer without increasing the reference count. This is useful for observing the contents of a shared resource and most notably resolving the problem of circular reference.</p><p>Let us solve the problem of circular reference through weak pointers. This can be achieved by modifying either A::ab or B::ba pointers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BB3JLXFS9txOip18MENGSw.png" /></figure><h3>Summary</h3><p>C++ does not use automatic reference management by default following their design philosophy of the <a href="https://bit.ly/2VMyrka">zero-overhead principle</a>. One can enable automatic reference management in C++ by making use of smart pointers defined in the standard library. It gives you resource guarantees and safety. Other languages such as <a href="https://bit.ly/3s9LNTI">Swift</a> and <a href="https://bit.ly/2U8hlwM">Rust</a> have adhered to the same concept instead of making sophisticated garbage collectors, they do not produce any garbage at all. This memory management model makes a very compelling case of using smart pointers. But raw pointers still have their brightest moments up to date.</p><p>Prefer using pointers for performance-critical loops or when the scope is clear enough to determine which is the owning pointer for a given resource. Raw pointers give you few performance benefits, but it comes with the cost of manually keeping track of your pointers, resource safety becomes your responsibility.</p><p>Prefer using smart pointers for expressing ownership clearly. Smart pointers give you resource guarantees which get rid of your task to make sure that there will be no leaks.</p><p>The <a href="http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#???">standard</a> recommends the following:</p><ul><li>Look at pointers: Classify them into non-owners (the default) and owners. Where feasible, replace owners with standard-library resource handles (as in the example above). Alternatively, mark an owner as such using the owner from the <a href="http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#S-gsl">GSL</a>.</li><li>Look for naked new and delete</li><li>Look for known resource allocating functions returning raw pointers (such as fopen, malloc, and strdup)</li></ul><h3>References</h3><ol><li>Barnes, J. (2005). Safe Pointers. AdaCore. Retrieved from: <a href="https://www.adacore.com/uploads_gems/03_safe_secure_ada_2005_safe_pointers.pdf">adacore.com/uploads_gems/03_safe_secure_ada</a>…</li><li>Computerphile (2017). Why C is so Influential? Retrieved from: <a href="https://www.youtube.com/watch?v=ci1PJexnfNE">youtube.com/watch?v=ci1PJexnfNE</a>.</li><li>Microsoft Docs (2020). Raw Pointers (C++).</li><li>Microsoft Docs (2020). Smart Pointers (Modern C++).</li><li>Microsoft Docs (2019). Object lifetime and resource management (RAII).</li><li>Stroustrup, B. &amp; Sutter, H. (2021). C++ Core Guidelines. Retrieved from: <a href="http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#">isocpp.github.io/CppCoreGuidelines/CppCoreG..</a>???</li><li>Stroustrup, B. (2013). The C++ programming language. Pearson Education.</li></ol><p><em>Originally published at: </em><a href="https://dcode.hashnode.dev/on-pointer-types-peeking-at-reference-semantics"><em>https://dcode.hashnode.dev</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3fc92206b98" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/on-pointer-types-f3fc92206b98">On Pointer Types</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pointers and References: Design Goals and Use Cases]]></title>
            <link>https://medium.com/geekculture/pointers-and-references-design-goals-and-use-cases-a536a984ba4d?source=rss-32103f4c576e------2</link>
            <guid isPermaLink="false">https://medium.com/p/a536a984ba4d</guid>
            <category><![CDATA[cpp]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Dave Amiana]]></dc:creator>
            <pubDate>Thu, 19 Aug 2021 08:02:46 GMT</pubDate>
            <atom:updated>2021-08-19T08:02:46.370Z</atom:updated>
            <content:encoded><![CDATA[<h4>Other languages were made for banning pointers, are they really terrible?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZegRhF8XziuF4TQf" /><figcaption>Photo by <a href="https://unsplash.com/@ben_robbins?utm_source=medium&amp;utm_medium=referral">Ben Robbins</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>At first, it seems that C++ makes things more complicated by introducing yet another layer of abstraction. References seem to encapsulate the same set of functionalities as pointers. Both of these constructs are used to <em>refer</em> to another entity as they provide access points into manipulating the contents of the <em>referent</em> entity; they are both allocated on the heap.</p><p>With this, we are faced with the following questions:</p><ol><li>Are pointers and references the same thing?</li><li>Are there any techniques that pointers can only do and vice-versa?</li><li>When do we favor pointers over references and vice-versa?</li></ol><p>By the end of this article, I hope to disentangle these two concepts and aim to give a reason why references deserve their own right for building more robust higher-order concepts.</p><h3>Pointers</h3><p>Pointers are introduced in C. Pointers store the memory address of an entity of type T (where T is a template parameter that can be resolved to <em>any</em> type), as mentioned, it provides an access point for changing the values of the entity it points to. Consider the following snippet:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FpoBFJFcvYGrhZBVuee4Xg.png" /></figure><p>Pointers are great for making use of indirections that manipulate the contents within a certain block of memory. Let us modify the above code to demonstrate a series of indirection as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dlRCysMquUfZfim_nrNnNQ.png" /></figure><p>We can extend this by nesting them together:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EiOltv-KpkD6t6HuA248nA.png" /></figure><p>As we notice, the address of pointers is not the same as the address of its reference. This observation is because pointers have their own identity. Consequently, pointers can be reassigned to another variable more so they can tolerate null values: NULL and nullptr (prefer using nullptr if you are <a href="https://www.ibm.com/docs/en/i/7.3?topic=pointers-null">using pointers</a>). That is, int *x = nullptr is valid and will compile.</p><p>More so, pointers can iterate over arrays with pre- and post-increment operators, pre- and post-decrement operators, and subscript operators.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jgghjSl2c9kLHBP3CuS6LA.png" /></figure><p>As we notice, the address of pointers is not the same as the address of its reference. This observation is because pointers have their own identity. Consequently, pointers can be reassigned to another variable more so they can tolerate null values: NULL and nullptr (prefer using nullptr if you are <a href="https://www.ibm.com/docs/en/i/7.3?topic=pointers-null">using pointers</a>). That is, int *x = nullptr is valid and will compile.</p><p>More so, pointers can iterate over arrays with pre- and post-increment operators, pre- and post-decrement operators, and subscript operators.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1__azELGIQlP9M9MQUNffA.png" /></figure><p>As mentioned, pointers can be used for allocating values on the heap as well as writing in that location. Let’s consider allocating memory for an array block with a size 3:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A08XgsGb6V4OlzlzAEN_MQ.png" /></figure><h4>Reminders of Using Pointers</h4><ul><li>Pointers can be difficult to manage as they can be nested and combined without restrictions, this can result in a complicated piece of code that is hard to maintain.</li><li>Pointers may leak resources if not properly managed: you must ensure clean-ups when pointer types are no longer needed, and you should remember to deallocate resources on the heap when they are no longer relevant to your code.</li><li>Prefer using smart pointers: std::unique_ptr&lt;T&gt; u_ptr, std::shared_ptr&lt;T&gt; s_ptr, and std::weak_ptr&lt;T&gt; w_ptr over raw pointers when performance is secondary to safety or finer grain of control are unnecessary. Smart pointers allow you to automate clean-up through <a href="https://bityl.co/8BOl">RAII</a> with a minimal performance cost, in the case of u_ptr there is zero performance overhead.</li><li>For pointer objects ptr_obj or user-defined types, members can be accessed through arrow operator e.g. ptr_obj-&gt; function().</li></ul><h3>References</h3><p>References make things more convenient to express, it provides the necessary set of constraints for expressing <em>ownership semantics</em> — a topic that is beyond our concern, for now. C++ follows the design principle that solutions that adhere to the standards should be easier than the alternatives.</p><p>Now that we know about pointers, how do we contrast this with references?</p><p>References can be thought of as a <a href="https://bityl.co/8BUS">constant pointer</a> T const* c_ptr = &amp;obj and should not be confused with const T* ref = &amp;obj: The former allows the contents of the object to be modified but restricts the address to refer to obj, the latter reverses the effect and only restricts the obj to be modified.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KrqvW6AiJqcyoFaDfqcwCg.png" /></figure><p>To modify the content of x and set it to y we say:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Dl2PMKAoLyEdxBcSwpj7A.png" /></figure><p>The same effect is achieved with references. As a result, references bind to the location of the entity in memory. It allows the contents of an entity to be modified, but it <em>cannot</em> be reassigned and must be bound at initialization. Therefore, the reference of an entity assumes the entity of the original variable.</p><p>As mentioned, references can also allocate memory for a single entity on the heap.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*14hIxgIvfWF1vcBo-g5RoA.png" /></figure><h4>Reminders for using References</h4><ul><li>References cannot be assigned to nullptr.</li><li>References cannot iterate over arrays.</li><li>Returning references over local variables may cause undefined behavior (dangling references).</li><li>References must be bound to an existing entity.</li><li>References only allow for one level of indirection.</li><li>References express the intention clearly and concisely.</li><li>Since C++11 standards, references have been used more often as the elements for move semantics are <a href="https://en.cppreference.com/w/cpp/language/move_constructor">built from the notion of references</a> (lvalue and rvalue references).</li></ul><h3>Summary</h3><ul><li>Are pointers and references the same thing? No.</li><li>Are there any techniques that pointers can only do and vice-versa? Pointers are more flexible than references which can make your code complicated if not managed well. T const* ref achieves the same behavior of references, except for array referencing which gives us more reason for choosing references over pointers (when appropriate) as its semantics restrict iterating over array-like structures:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L5a_K0usEt3uox7hAuz0nQ.png" /></figure><p>Whereas array indexing with references will result in a compiler error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1cZtw9scdXmCD_SWHhs-qg.png" /></figure><ul><li>When do we favor pointers over references and vice-versa? Pointer types are generally useful for setting up a separate field of indirection capable of modifying the contents of multiple variables of the same type. Having the same pointer accessing multiple variables may be difficult to trace and reason with. It is preferred to maintain clarity over the convenience of typing one pointer to all variables of the same type. For this reason, making use of references is safer.</li></ul><p>Pointers are not really terrible, in fact, they are one of the greatest features we unlock in languages like C/C++, however, their power comes with a cost.</p><p>In conclusion, references are not just syntax sugar to cast T const*, it has its own design goals and purpose namely containing the address of declared entities. This improves the clarity of our intent, and in these situations, the C++ compiler is our friend.</p><p><em>Originally published at </em><a href="https://dcode.hashnode.dev/"><em>https://dcode.hashnode.dev/</em></a></p><ul><li>When do we favor pointers over references and vice-versa? Pointer types are generally useful for setting up a separate field of indirection capable of modifying the contents of multiple variables of the same type. Having the same pointer accessing multiple variables may be difficult to trace and reason with. It is preferred to maintain clarity over the convenience of typing one pointer to all variables of the same type. For this reason, making use of references is safer.</li></ul><p>Pointers are not really terrible, in fact, they are one of the greatest features we unlock in languages like C/C++, however, their power comes with a cost.</p><p>In conclusion, references are not just syntax sugar to cast T const*, it has its own design goals and purpose namely containing the address of declared entities. This improves the clarity of our intent, and in these situations, the C++ compiler is our friend.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a536a984ba4d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/pointers-and-references-design-goals-and-use-cases-a536a984ba4d">Pointers and References: Design Goals and Use Cases</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Designing functions: The building blocks of computer programs]]></title>
            <link>https://medium.com/geekculture/designing-functions-the-building-blocks-of-computer-programs-3721bf731447?source=rss-32103f4c576e------2</link>
            <guid isPermaLink="false">https://medium.com/p/3721bf731447</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[basics]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Dave Amiana]]></dc:creator>
            <pubDate>Wed, 16 Jun 2021 02:03:21 GMT</pubDate>
            <atom:updated>2021-06-16T02:03:21.645Z</atom:updated>
            <content:encoded><![CDATA[<h4>Back to Basics.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ctHOAIb12wOKKLTuCH0nPQ.jpeg" /><figcaption>Photo by <a href="https://www.pexels.com/@magda-ehlers-pexels?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Magda Ehlers</a> from <a href="https://www.pexels.com/photo/pile-of-white-and-black-boxes-1329318/?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Pexels</a></figcaption></figure><p>A function is an essential construct in programming. The language that we use to convey a message on the computer, functions closely resemble a verb: <em>“the nuts and bolts of the language”</em> (S. Pinker, 2007). Put it in another way, functions serve as the primary constructs for expressing a set computational procedure in a programming language.</p><p>It is better to break down the problem into manageable pieces. Solving the smaller part of the problem requires a computational procedure that we store in a function.</p><p>This article will introduce the things to consider in designing and organizing functions.</p><p>A function is a block of code that processes inputs and configures an output. One of the nice things about this is it breaks down our solution into a set of subroutines that we can reuse to solve other problems.</p><p>Indeed, simple algorithms can be stored in one function, sometimes, it branches off into two or more: <strong>the question is when and why do we need indirection?</strong> The most obvious reason for this is <em>code-reusability</em>. We need to make conscious efforts into making our codebase sustainable i.e. reusable. To achieve this, we have to delegate the simplest version of a task in a function. Our goal is to minimize the <em>boilerplate code</em> (sections of code that are repeated in multiple places with little to no variation), <strong>we follow the virtue of not repeating ourselves</strong>.</p><p>Functions are sufficient for developing sophisticated software systems. This technique is sometimes known as <em>modular programming</em>. This is one of the reasons why C is deemed elegant by some developers I know.</p><p>There are three major concepts in modular programming:</p><ul><li><em>Module</em> — a self-contained collection of functions that solves a problem (or subproblem).</li><li><em>Abstract Step</em> — A step in which some implementation details are unspecified. This step may define the routes where concrete functions may take place. In other words, it is a code block that delegates a group of functions necessary for solving the problem.</li><li><em>Concrete Step</em> — A realization of the abstract step that implements the logic for solving independent subproblems.</li></ul><h3>Software Design Process: Top-Down Approach</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/0*cY6Sd52cbZuRyjhe" /></figure><p>Figure 1.0. Hierarchical solution tree (Dale, N. B., &amp; Weems, C., 2014).</p><p>Steps for applying design principles in functions:</p><ol><li><strong>Understand the problem</strong>. State its input requirements as well as the specifications for expected output.</li><li><strong>Write the major steps for solving the problem</strong>. Make a hierarchical solution tree (as seen in figure 1) and define the major problems you need to solve. As you go down to the bottom, problems become more concrete and simpler.</li><li><strong>Decide if the problem can be broken down into independent subproblems that we can work on separately</strong>. It is often simple enough when you can see how to implement it directly in a language. If you feel overwhelmed by writing it in a language, you are probably bypassing one or more levels of abstraction — you need to step back and think through how you can simplify this by breaking down the problem.</li><li><strong>Ensure that each function has exactly one job</strong>. Their purpose should be obvious in its name (it makes your code easier to read and self-documenting, so we must assure that the function name should clearly state its purpose).</li><li><strong>Document solution process</strong>. Documentation helps to make our codebase easier to maintain.</li></ol><h3>References:</h3><ol><li>Pinker, S. (2007). Steven Pinker: What our language habits reveal. <a href="https://www.youtube.com/watch?v=LjQM8PzCEY0">TED</a>.</li><li>Dale, N. B., &amp; Weems, C. (2014). Programming and problem solving with C++. Jones &amp; Bartlett Publishers.</li><li>DeNero, J. (n.d.). <a href="https://composingprograms.com/pages/14-designing-functions.html">Composing Programs</a>.</li></ol><p><em>Originally published at </em><a href="https://dcode.hashnode.dev/designing-functions-the-building-blocks-of-computer-programs"><em>https://dcode.hashnode.dev</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3721bf731447" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/designing-functions-the-building-blocks-of-computer-programs-3721bf731447">Designing functions: The building blocks of computer programs</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Data Science Roadmap]]></title>
            <link>https://medium.com/geekculture/the-data-science-roadmap-8d915f0ef093?source=rss-32103f4c576e------2</link>
            <guid isPermaLink="false">https://medium.com/p/8d915f0ef093</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <dc:creator><![CDATA[Dave Amiana]]></dc:creator>
            <pubDate>Tue, 04 May 2021 02:02:21 GMT</pubDate>
            <atom:updated>2021-05-04T02:02:21.218Z</atom:updated>
            <content:encoded><![CDATA[<h4>Let’s Explore</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nRPpXgb2xZUk7A5_AeQD_g.jpeg" /><figcaption>Photo by <a href="https://www.pexels.com/@startup-stock-photos?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Startup Stock Photos</a> from <a href="https://www.pexels.com/photo/man-wearing-black-and-white-stripe-shirt-looking-at-white-printer-papers-on-the-wall-212286/?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Pexels</a></figcaption></figure><h4>What is Data Science?</h4><p>Data science seems to be a convoluted term that rose in popularity mostly tied with the advancements of machine learning frameworks. Some argue that <em>data science</em> is a term for an overpaid statistician, others imagine them to be a role one adapts from <em>software engineering</em>, while some see them as <em>businessmen with technical skills</em>. I’ve seen heated forums debating the ethos of this term. I found Field Cady’s definition of data science to be in the right spot where this tension can be settled.</p><blockquote>Data science means doing analytics work that, for one reason or another, requires a substantial amount of software engineering skills.</blockquote><p>At the heart of this practice lies a set of skills that makes one a data scientist.</p><h3>What are Data Scientists?</h3><p>There are three hats the guise of a data scientist revolves into.</p><p>Whereas a statistician is trained to do all the analytical methods, a data scientist extends their knowledge of applying statistical techniques for building the necessary tools in modeling a computational system. Data scientists make sure they covered the edge cases where no known tools are yet found to be useful. They apply their proficiency in computer programming where a traditional statistician might not have. A data scientist does not need statistical tools to get their work done.</p><p>In the guise of an Engineer. A data scientist has to be technically savvy. They have to know how to transform their data into something meaningful without relying too much on ready-made software. Covering the edge-cases means that exploring uncharted territories spawned with irregularities. A data scientist must cope up with irregularities. And one way to adapt is to develop the software skills in <em>handcrafting</em> their tools to cover the edge cases. Note that turning your data into something that is finally useful for your model is one of the <a href="https://www.elderresearch.com/blog/what-is-data-wrangling-and-why-does-it-take-so-long/">most crucial and tedious processes</a> of data science (and machine learning).</p><blockquote>This is also a good point to motivate anyone to hone software skills. Not only that you grow beyond the ready-made services provided in the software, but you also gain the freedom to go wherever you want to go. Unchained.</blockquote><p>Business people are oriented to the value of a product. Their sense is to follow whichever is essential to their business problem. Field Cady (2017), noted that what separates a good data science professional from a mediocre one is not up to their maths or engineering skills, it is about formulating the right question. The questions that we aim to solve roughly estimate the value of our product. In addition, business people are also good at with communicating other people. Likewise, a data scientist must tell us their most interesting insights in the form of a story, that does not limit discussion in a room of people who knows data science.</p><blockquote>No amount of technical competence or statistical rigor can make up for having solved a useless problem.</blockquote><h3>The Data Explorer’s Roadmap</h3><p>Now that we clarified the terms, let’s lay out our map in navigating our workflow as data explorers of the wild. I got this from François Chollet’s introduction to Deep Learning and Field Cady’s handbook for data scientists.</p><ol><li><strong>Define the problem</strong>. List down the questions you want to ask. This will be your guide for understanding the kinds of data you require. This is usually done in groups. This step is critical as it sets your objective, and you need to be very clear about it. Having this discussion on your team keeps everyone on the same page working on the same set of objectives.</li><li><strong>Gather relevant data sets</strong>. Check if there are blanks on your dataset. What does joining two datasets mean? Do they agree on one thing? This is also critical for it affects the quality of your output: you feed data in, and you get information out. If you feed your model with a bunch of garbage (having pathological patterns, too many outliers, etc.). In a notable paper from Microsoft researchers <a href="https://dl.acm.org/doi/10.3115/1073012.1073017">Michele Banko and Eric Bill (2001)</a> and the computer scientist <a href="https://bityl.co/6bZq">Norvig <em>et al.</em> (2009)</a>, data matters more to algorithms.</li><li><strong>Hack and Analyze</strong>. This is where it gets so bright and beautiful! What you do is you play with a bunch of knobs and twist them together randomly to see how one affects the other — that is the famous neural network architecture: the foundations of Deep Learning AI. On the other end, is a set of more rigorous algorithms from Statistics and Computer Science known as Clustering, Classification, our good old Regression, and dimensionality reduction: this comprises the <a href="https://bityl.co/6bdU">shallow ML architecture</a>.</li><li><strong>Communicate your results</strong>. At the end of it all: we should tailor our results in a coherent story. Make it compelling! That includes our intentions, and the results of our analysis put together in a format that anyone can understand. We don’t talk to the people in the room we work with anymore. We talk for the people. Make it visual.</li></ol><h3>References:</h3><ol><li>Cady, F. (2017). The Data Science Handbook. John Wiley &amp; Sons.</li><li>Chollet, F. (2018). Deep Learning with Python (Vol. 361). New York: Manning.</li><li>Géron, A. (2019). Hands-on machine learning with Scikit-Learn, Keras, and TensorFlow: Concepts, tools, and techniques to build intelligent systems. O’Reilly Media.</li><li>Banko, M., &amp; Brill, E. (2001, July). Scaling to very very large corpora for natural language disambiguation. In Proceedings of the 39th annual meeting of the Association for Computational Linguistics (pp. 26–33).</li><li>Halevy, A., Norvig, P., &amp; Pereira, F. (2009). The unreasonable effectiveness of data. IEEE Intelligent Systems, 24(2), 8–12.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d915f0ef093" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/the-data-science-roadmap-8d915f0ef093">The Data Science Roadmap</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Towards Exceptional Code]]></title>
            <link>https://medium.com/geekculture/towards-exceptional-code-e467a05b2e95?source=rss-32103f4c576e------2</link>
            <guid isPermaLink="false">https://medium.com/p/e467a05b2e95</guid>
            <category><![CDATA[design-thinking]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[design]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Dave Amiana]]></dc:creator>
            <pubDate>Mon, 26 Apr 2021 05:02:45 GMT</pubDate>
            <atom:updated>2021-04-26T05:02:45.713Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part of keeping our intentions intact is assuring that our program works well, that includes the occasions where our programs are guaranteed to fail.</h4><p>Imagine you are tasked to make an algorithm for the automation of airplane control systems. You closed the deal with a known airplane company. Your software is now used in 30% of all the modern plane control systems. This is an overly complex system that you worked with for years, but you forgot to specify on your program that under all circumstances, an airplane should never enter into a nosedive.</p><p>One night, you were called up by the company for an emergency. There’s a report on unexpected nosedives to have been caused by your software. You gathered your team to find out the bug that has been causing system failures. This is a notoriously difficult process for an overly complicated system. After weeks of investigating, someone from your team found out that there appears to be a lack of exception handling on your software.</p><p>Cases like these are testaments to how crucial exception handling is in our systems.</p><figure><img alt="Airplane view." src="https://cdn-images-1.medium.com/max/1024/0*73CvTNNdU0tKiyQ6" /><figcaption>Photo by <a href="https://www.pexels.com/@lennart-wittstock-94105?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Lennart Wittstock</a> from <a href="https://www.pexels.com/photo/airplane-windowpane-showing-city-buildings-316794/?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Pexels</a></figcaption></figure><h3>Discussion</h3><p>Exceptions provide a way to respond to unexpected events that our program encounters. There are two frames of reference for handling exceptions. They are the events within our control and those that are simply beyond our control. Learning this is important for designing large-scale software systems.</p><p>Events that are within our control should be our responsibility whereas, for the events that go beyond our scope, we should at least provide a clear error message indicating what went wrong. Error messages provide feedback to the user in a manner that is insightful enough so they can know how to fix the problem. This is key to good user experience design which I outlined here:</p><p>As developers, we ask ourselves: <em>on what conditions should our program throw an exception?</em> This is not an easy task. First of all, can you enumerate all cases for undefined behaviors of your program? In these cases, we follow a <em>big-picture</em> perspective. We translate the previous question as to <em>what is are the quintessential roles of my functions? What are they intended for?</em> A good design philosophy should insight clear intentions, as our products should be easy to use and difficult, if not impossible, to misuse.</p><p>With this in mind, we can guide how we should think about writing our code.</p><p>Let’s go back to our story. Assume, for simplicity’s sake, that our system contains the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/34028e60dfb656143093895cd002f3d4/href">https://medium.com/media/34028e60dfb656143093895cd002f3d4/href</a></iframe><p>Suppose that the above code has administrative control over the parts of the plane. This leads us to investigate the obj.automate() function. Upon digging on our code a little further we found this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/398454031e5887d395e5267809dfbfdf/href">https://medium.com/media/398454031e5887d395e5267809dfbfdf/href</a></iframe><p>Can you spot what went wrong with this function?</p><blockquote><em>We can’t guarantee that our system will not </em>nosedive<em>.</em></blockquote><p>Let’s improve this function by introducing a try-catch block wherein we can guarantee that the system terminates as soon as it meets a critical condition wherein obj.optimize() leads to a nosedive decision.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7431748b10bf0695d23fcf3d0e2c4f76/href">https://medium.com/media/7431748b10bf0695d23fcf3d0e2c4f76/href</a></iframe><blockquote><em>This block of code saves lives!</em></blockquote><p>Now we can guarantee that in the event where critical_conditions are met, the control will be passed on to the pilot.</p><h3>Takeaways</h3><p>Exceptional code should have:</p><ul><li>proper error handling that guarantees the intentionality of our code</li><li>clear and meaningful error messages are key to good design</li></ul><p>Notes:</p><ul><li>Programming languages have provided this feature, so depending on your language, you should check out the technical documentation on how to implement exception handling.</li><li>C++ code is used for illustrative examples as most modern control systems are implemented using C++, and I personally love the language!</li></ul><p><em>Originally published at </em><a href="https://dcode.hashnode.dev/towards-exceptional-code"><em>https://dcode.hashnode.dev</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e467a05b2e95" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/towards-exceptional-code-e467a05b2e95">Towards Exceptional Code</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Typed Annotations]]></title>
            <link>https://medium.com/geekculture/python-typed-annotations-1e3f3f5f6841?source=rss-32103f4c576e------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e3f3f5f6841</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Dave Amiana]]></dc:creator>
            <pubDate>Sat, 24 Apr 2021 14:46:16 GMT</pubDate>
            <atom:updated>2021-04-28T11:09:59.935Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*c9ZLAXYk56xvPzUd" /></figure><p>Python 3.10 just announced their <a href="https://docs.python.org/3.10/whatsnew/3.10.html">release</a> on April 10 this year. Most of the updates were done to improve the developer experience and maintainability of the codebase.</p><p>We enjoyed the fun of writing Python code for its readable syntax, and user-friendly language design. It was clearly meant for getting rid of type prefix you would normally write in other languages such as C++ or Java. Keep in mind that C++ and Java are compiled languages that necessarily impose a set of grammatical rules for mapping them onto a machine code that you can execute. But Python is a dynamically typed language where the interpreter can infer the type of the entities we are calling out on our function by the concept of <a href="https://bityl.co/6LB9">duck typing</a> — <em>if it walks like a duck and it quacks like a duck, then it must be a duck</em>. This gives us so much room to focus on the algorithm instead of worrying about an obscure programming syntax in expressing the logic of our code. This is okay for relatively small projects where we could just comment out the type of parameters we expect on our function(or method). But building a maintainable software system with people calls for a better solution than commenting out what their function expects.</p><p>Before we talk about typed annotations in Python, let us first appreciate the elegance of type prefix in other languages so we can get a sense of when to annotate our code. Whereas type prefix can introduce syntax overheads, it is built-in the language for a reason: (1) <a href="https://bityl.co/6LBU">parsing</a>, and (2) <a href="https://bityl.co/6LBT">type-safety</a>. In a way, type prefix guards whatever type our function expects to take in and the type it returns for we can generally think of a function as a black box that accepts and returns something. With an imposed typed restrictions to other compiled languages, it enables us to keep the intentionality of our code, that we can guarantee that it is serving its purpose. So, not only that we can clearly write (and read) what goes in and out of our function, but we can also ensure that our function takes in the right types that we specified.</p><p>But how can we adapt this to Python? That’s where type annotations come in.</p><p>In the following sections, we will explore some features of Type annotations that Python 3.10 supports. Before we begin, here’s how we can annotate a simple function in Python:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*Dgmgbxdrku2ujcDmH5o_TQ.png" /></figure><p>As we see in the annotated version of our λ function, it takes an integer value of x and returns a value of type float whereas the unannotated version may require some guessing into what λ function expects. Consider the same function written in C++:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*1eOxy1M6lnodGJWxc3ps8w.png" /></figure><p>The main benefit we get on type annotations in Python is readability and static analysis. The <a href="https://www.python.org/dev/peps/pep-0484/">PEP 484</a>, on Python 3.5 release specified that although Python may potentially support runtime type checking, Python will remain a dynamic language.</p><h3>What is Static analysis and how can we do that in Python?</h3><p>Static analysis tools are a way to easily detect vulnerabilities without executing a program. This provides an insight into our code without necessarily executing them which automates code quality maintenance. Static analysis tools also automate finding security problems at an early age. So far so great, but how can we use it on our IDE’s?</p><p>There are several types of static analysis that exist, and they have different purposes ranging from styling analysis to unused code detection. <a href="https://luminousmen.com/post/python-static-analysis-tools">Here’s an article</a> I found that explores the ecosystem for Python static analysis.</p><p>Now, let’s cover some features of type annotations we can do with Python 3.10.</p><h4>New type union operator</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BTfLeuJ2UD1ufpZDzLPrLQ.png" /></figure><p>The new union operator is accepted as the second arguments to isinstance() and issubclass() functions as in:</p><pre>&gt;&gt;&gt; isinstance(1, int | str)<br>True</pre><h4>Improved TypeAlias Annotation</h4><p>Type aliasing in Python can now be expressed explicitly. Compare:</p><pre># in previous versions<br>StrCache = &#39;Cache[str]&#39;  # a type alias<br>LOG_PREFIX = &#39;LOG[DEBUG]&#39;  # a module constant</pre><p>and</p><pre># in Python 3.10<br>StrCache: TypeAlias = &#39;Cache[str]&#39;  # a type alias<br>LOG_PREFIX = &#39;LOG[DEBUG]&#39;  # a module constant</pre><p>For more see: <a href="https://docs.python.org/3.10/whatsnew/3.10.html">docs.python.org/3.10/whatsnew/3.10.html</a>.</p><h3>Takeaways</h3><p>While type annotations may introduce syntactical overhead, it improves the readability of our code thereby keeping our intentionality intact. As developers, we want to make our codebase easy to use and difficult to misuse.</p><p><em>Originally published at </em><a href="https://dcode.hashnode.dev/python-typed-annotations"><em>https://dcode.hashnode.dev</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e3f3f5f6841" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/python-typed-annotations-1e3f3f5f6841">Python Typed Annotations</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[World of Forms: An Introduction to Object-Oriented Programming]]></title>
            <link>https://medium.com/geekculture/world-of-forms-an-introduction-to-object-oriented-programming-f4c63a2c4195?source=rss-32103f4c576e------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4c63a2c4195</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Dave Amiana]]></dc:creator>
            <pubDate>Thu, 22 Apr 2021 15:33:18 GMT</pubDate>
            <atom:updated>2021-04-22T15:33:18.182Z</atom:updated>
            <content:encoded><![CDATA[<h4>Abstraction, Encapsulation, Polymorphism, and Inheritance</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RHfJzYpWX10m0umNnu3FxA.jpeg" /><figcaption>By <a href="https://www.pexels.com/photo/crop-faceless-woman-kneading-clay-in-workshop-5302891/">Gabby K. from Pexels</a>.</figcaption></figure><p>Object-oriented programming (OOP) has become one of the most used programming paradigms since its conception. Part of the reason why the object-oriented approach is widely practiced is code-reusability. OOP emphasizes a group of concepts packed up together and their relations with other objects. The main idea behind this paradigm is to <em>bind</em> a template for the data and its associated behaviors.</p><pre>class Object:<br>        private:<br>            int int_data;<br>            string str_data;<br>        public:<br>            constructor();<br>            destructor();<br>            function get_string();<br>            function get_int();<br>            function set_str_data(string _arg);<br>            function set_int_data(int _arg);</pre><p>The pseudocode above shows some basic features of OOP. We can observe that the object has an internal (private) state, as well as the sorts of behaviors it can do externally (public). There are two general categories of OOP: class-based and prototype-based. In this article, we will discuss the differences between class-based, and prototype-based categories. Then we will talk about the core concepts of OOP.</p><p>Class-based OOP revolves around the concept that the manner of inheritance among classes happens as one object is combined with another object. In contrast, prototype-based object orientation extends functionality by reusing an existing object of which it serves as a prototype. A notable example of class-based object orientation is Java, while JavaScript is an example of prototype-based object orientation.</p><p>Consider implementing a <em>conceptual model</em> of an apple. In class-based object-orientation, we would have to group the general properties of fruit since an apple belongs to a kind of fruit. Then we combine these features to a model of an apple class where properties generic to an apple type are implemented. Contrast this with prototype-based object orientation, where we can reuse the resources of our fruit and morph them into a conceptual model of an apple by adding features generic to apples.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9mlZOm8-AQwmM9g1" /><figcaption>Fruits by <a href="https://www.pexels.com/photo/selective-focus-photography-of-apple-fruits-1352243/">Lukas from Pexels</a>.</figcaption></figure><p>In Java, we write this relationship as:</p><pre>abstract class Fruits{<br>    private String name;<br>    Fruits(String name){this.name = name;}<br>    //generic method and properties of fruits that are common to all fruits<br>}<br><br>class Apple extends Fruits{<br>    private String id;<br>    Apple(String id){this.id = id;}<br>    //generic method and properties of apple that are specific to all fruits<br>}</pre><p>In JavaScript, we write this relationship as:</p><pre>function Fruits(name){<br>    this.name = name;<br>    //generic properties of fruits that are common to all fruits<br>}<br>// adds generic functions common to all fruits<br>Fruits.prototype = {<br>    getName: function(){return this.name;}<br>}<br><br>function Apple(id){<br>    Fruits.call(this, &quot;Apple&quot;);<br>    this.id = id;<br>}<br>// adds generic functions common to all apples<br>Apple.prototype = {<br>    getID: function(){return this.id;}<br>}<br>//Apple inherits the properties and functions of Fruits<br>Apple.prototype = new Fruits();<br><br>// extending properties of Apple specific to Applies<br>Apples.prototype.constructor = Apples; </pre><p>Hence prototype-based OOP is otherwise known as class-less OOP.</p><h3>The Pillars of Object-Oriented Programming</h3><p>Object-oriented programming is based on the following concepts:</p><ul><li>Encapsulation</li><li>Abstraction</li><li>Inheritance</li><li>Polymorphism</li></ul><p>Let’s break this down.</p><p>Encapsulation is the process of binding the attributes and methods internal to the object. This concept effectively hides the implementation of some functions specific to an object. It makes sense to summon this concept by private keyword in Java.</p><p>Abstraction is picking out the general features among the objects that belong to that category which effectively forms a hierarchy of shared resources. Moreover, it effectively reduces the implementation of a core function for all classes. Without abstraction, your codebase would be filled with boilerplate code; these are blocks of code that are implemented in multiple places with little to no variation. A boilerplate is a significant overhead for development, and abstraction is key to getting rid of them.</p><p>Inheritance is the extension of the properties of one class to another. Think of piling up blocks of legos to form a new object. The Legos stacked on top of each other represent how the compiler process inheritance in a class-based OOP: they extend the features of one another.</p><p>Polymorphism is the idea of having multiple implementations to a function. It implies that a function can have many forms based on key arguments or parameter signatures of the function. There are two kinds of polymorphism for compiled languages: Overloading and Overriding. In Java, for example, the Java compiler deduces the type of an overloaded function at compile-time while an overridden function is deduced at runtime.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0ptc0cFtV_pMUtbe" /></figure><h4>Notes:</h4><p>For all intents and purposes, the JavaScript snippet is made to illustrate how one may implement inheritance. The writer did not keep in mind the ES6 standards which favored classes as a syntax sugar on top of their prototype-oriented system. This was mainly done for ease of use, but one must keep in my the JavaScript still maintained its prototype-based system. For the reader interested to learn about this, here’s an interesting article I found on Hackernoon:</p><p><a href="https://hackernoon.com/once-upon-a-time-in-javascript-inheritance-d24m3235">Once Upon a Time in Javascript: Classes and Inheritance | Hacker Noon</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4c63a2c4195" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/world-of-forms-an-introduction-to-object-oriented-programming-f4c63a2c4195">World of Forms: An Introduction to Object-Oriented Programming</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Elements of Programming: Fundamental Data Structures]]></title>
            <link>https://medium.com/geekculture/elements-of-programming-fundamental-data-structures-882a6e57245f?source=rss-32103f4c576e------2</link>
            <guid isPermaLink="false">https://medium.com/p/882a6e57245f</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Dave Amiana]]></dc:creator>
            <pubDate>Tue, 13 Apr 2021 10:20:47 GMT</pubDate>
            <atom:updated>2021-04-17T21:55:15.770Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Data Structures underlie everything we do in computer science: understanding them is critical to writing rigorous software and effective algorithms.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*L-pkWJBNTAACn6nK" /><figcaption>Photo by <a href="https://unsplash.com/@alinnnaaaa?utm_source=medium&amp;utm_medium=referral">Alina Grubnyak</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>There are two general ways of looking at data structures: concept and implementation. Ideally, they should serve you the sense in selecting an effective data structure for a given problem. Fundamental data structures manifest themselves naturally in most situations. The problem usually demands a certain data structure, while others could be represented in different ways. An effective data structure should simplify the problem. But that is only half of the story since a data structure must also ensure computational efficiency. We can simplify the problem by conceptually looking for an apt data structure while performance benefits are obtained by looking into the implementation.</p><p>Now that we are familiar with the essence of looking at the two broad lenses in selecting a data structure, I should formally introduce you to the characters. We can view data structures from abstraction — that we shall call from hereon then as Abstract Data Type — and implementation.</p><p>An Abstract Data Types (ADT) ought to describe a set of functionalities in a given data structure — they are written in a declarative manner. It is close to an algebraic structure in mathematics that outlines the rules and operations in a particular context [1]. The inspirations from mathematics are established within a class that contains a collection of values, and behaviors that support the operations that we can do within a structure. Such an abstract model hides the implementation logic. ADT is language-agnostic as it only describes the prototype of a data structure.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/247c71586c408a2f73958655885b5b70/href">https://medium.com/media/247c71586c408a2f73958655885b5b70/href</a></iframe><p>In programming a data structure with an abstract model (ADT), a good practice is to establish <a href="https://en.wikipedia.org/wiki/Loose_coupling">loose coupling</a> between modules that contain the ADT and the implementation specifics. The purpose is to maintain a conceptual map between programming logic and functionalities which improves the maintainability of our system.</p><p>Below is an example of implementing an ADT inside a language which in this case is C++ because the Standard Template Library (STL) is deemed mature and state of the art, it is a good reference for reading a good piece of software. However, due to its nuances and technical sophistication, we will only base our discussion on one of the core concepts of STL: containers.</p><p>Keeping this in a separate module improves maintainability and clarifies the intention of the developer before they implement the logic specific to that functionality. Do not worry about the new word <em>singly-linked list </em>because we would not talk about that here. For now, focus on how we wrote our ADT for describing the operations of the data structure — which in this case is a List.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3cd2d65ddc51ec48f9b0f37d41c5d699/href">https://medium.com/media/3cd2d65ddc51ec48f9b0f37d41c5d699/href</a></iframe><p>Meanwhile, the implementation specifics contain the quirks and tricks that ensure the operations ascribed in the ADT. From this perspective, it is important to know the quirks of your language to know the techniques that ensure safety and efficiency, such as referencing and memory management in languages like C/C++. For this matter, implementing the concepts defined in ADT closely works with the language; the programmer must be technically adept in the language.</p><p>In practice, these two lenses work together by establishing clarity first, then specifications.</p><h3>Fundamental Data Structures</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*n5IR6KA3dCmoWXXQ.jpg" /><figcaption>Euclid in Raphael’s <a href="http://commons.wikimedia.org/wiki/File%3ARaphael_School_of_Athens.jpg"><em>School of Athens</em></a><em> </em>(Wikimedia Commons).</figcaption></figure><blockquote>Much like the abstract and practical resemblance of Euclidean geometry to the world, ADT and its Implementation correspond in a manner where the former is purely ideal while the latter is closer with actuality.</blockquote><p>For this section, we briefly introduce the fundamental data structures and cite some of their use cases. We shall be introduced to the following data structures.</p><ul><li>List</li><li>Deque</li><li>Tree</li><li>Set</li><li>Map</li><li>Graph</li></ul><p><strong>Before we delve in a little further, we should keep in mind the Base functionalities of our data structures. </strong>The baseline for each structure has to support the following operations: it should be able to search an item, sort, insert, update, and delete items.</p><ul><li><strong>Search </strong>− Algorithm to <strong><em>find </em></strong>an item in a data structure.</li><li><strong>Sort </strong>− Algorithm to <strong><em>organize </em></strong>items in a certain order.</li><li><strong>Insert </strong>− Algorithm to <strong><em>insert </em></strong>items in a data structure.</li><li><strong>Update</strong> − Algorithm to <strong><em>update</em></strong><em> </em>an existing item in a data structure.</li><li><strong>Delete </strong>− Algorithm to <strong><em>remove </em></strong>an existing item from a data structure.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a3b30c534d39710a10d4fa82e4e2cf14/href">https://medium.com/media/a3b30c534d39710a10d4fa82e4e2cf14/href</a></iframe><h4>List</h4><p>The list is an abstract data type that represents a countable number of ordered values, where the same value may occur more than once. Lists can be ordered linearly or non-linearly. Non-linear lists can be implemented in a form of a Tree, Graph, or a Map. However, we distinguished them in their respective categories for they, themselves, have their own nuances. List, in this context, pertains to a linear list family.</p><p>A list data structure is useful when the notion of order is obtained, a value is allowed to have duplicates, and whenever we would like to do sorting and searching with our data set. The List ADT is implemented in the class of <a href="https://www.cplusplus.com/reference/stl/">Sequence containers</a> in C++ STL. It comprises the following: array, vector, deque, forwad_list, and list.</p><p>Conceptually, all other data structures can be implemented with lists [2], however, we want to categorize them for the sorts of structures they represent, which is useful for problems we encounter. (This is related to how algorithms are categorized which I laid out here:<a href="https://medium.com/swlh/making-sense-of-algorithms-general-perspective-c3ba626577ae"> Making Sense of Algorithms: A General Perspective</a>.)</p><p>A common structure when we talk about a list is called linked-list (implemented in STL as a list). It is applied in many use-cases such as deriving other structures, the links you visit in a web browser, or music playlists.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RB4qQl63FfDkNtN4" /><figcaption>Photo by <a href="https://unsplash.com/@fhavlik?utm_source=medium&amp;utm_medium=referral">Filip Havlik</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Deque</h4><p>Deque is a combination of queue and stack since the difference between these data structures is their ordering whereas the queue maintains a FIFO order, the stack keeps a LIFO order. Thus, deque support FIFO and LIFO ordering of a list.</p><p>FIFO means first-in, first-out ordering. The most common example would be to think of waiting in line in supermarkets. Sometimes we call this a queue where the policy established is first-come, first-served.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*va6QOwTag39DhuOn" /><figcaption>Photo by <a href="https://unsplash.com/@123juli?utm_source=medium&amp;utm_medium=referral">Julius Vincent</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>LIFO, on the other hand, stands for last-in, first-out ordering. Think of removing a book from a pile of books. You would have to remove the top book, iteratively until you found the book you want to read.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*P6yuO0aLd6H6hozz" /><figcaption>Photo by <a href="https://unsplash.com/@anniespratt?utm_source=medium&amp;utm_medium=referral">Annie Spratt</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Queues are used for maintaining a LIFO order of precedence in processing requests. A great example would be scheduling systems: the processing is done on a <em>first-come, first-serve</em> basis. CPU scheduling systems exploit the LIFO property of the queue [3].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QiX0NiXb7uXEdplR.png" /><figcaption>A sample <a href="https://en.wikipedia.org/wiki/Thread_pool">thread pool</a> (green boxes) with a queue (FIFO) of waiting for tasks (blue) and a queue of completed tasks (yellow). Image source: <a href="https://commons.wikimedia.org/">https://commons.wikimedia.org</a></figcaption></figure><p>The common use-cases of the stack resonate within the language such as the call stack wherein stack data structure that stores information about the active subroutines of a computer program.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-b5wXeJieY4fFAzt.png" /><figcaption>Call stack. Source: <a href="https://commons.wikimedia.org/">https://commons.wikimedia.org</a></figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc8f7872844e4186ef36632dfe074762/href">https://medium.com/media/dc8f7872844e4186ef36632dfe074762/href</a></iframe><blockquote>Moving on to more specialized data structures since they rely on the previous data structures. This is where it gets so exciting!</blockquote><h4>Trees</h4><p>A tree data structure is used to represent hierarchy or non-linear ordering. We commonly name them with what resembles a family tree. We will go over some common terminologies but keep in mind that it is not exhaustive.</p><ul><li>root — a root node is a starting point of a tree structure. It does not have a parent node.</li><li>parent — a parent node is an immediate predecessor of a node.</li><li>child — a child is a successor of a parent node</li><li>leaf — a leaf is located at the end of the tree. It does not have any children.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/180/0*13EokVYoOaxcBsL-.png" /><figcaption>Binary Search Tree. From <a href="https://en.wikipedia.org/wiki/Binary_search_tree#/media/File:Binary_search_tree.svg">Wikimedia Commons</a>.</figcaption></figure><p>There are many versions of trees, and they can be implemented in various ways. It is important to note that although C++ STL does not have a tree container, it does implement sets as a <a href="https://bityl.co/6Mhm">Binary Search Tree</a>.</p><p>A binary search tree (BST) is a particular type of tree that maintains a property of allowing only two children per parent node where the left child is always less than the parent while the right child is always greater than the parent [4].</p><p>Another kind of tree that is widely used in cryptography is known as the Merkle Tree in which every <a href="https://en.wikipedia.org/wiki/Leaf_node">leaf node</a> is labeled with the <a href="https://en.wikipedia.org/wiki/Cryptographic_hash_function">cryptographic hash</a> of a data block, and every non-leaf node is labeled with the cryptographic hash of the labels of its child nodes [5].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZJhDk-xR2a74pGKH.png" /><figcaption>An example of a binary hash tree (Merkle Tree). <a href="https://en.wikipedia.org/wiki/Merkle_tree#/media/File:Hash_Tree.svg">From Wikimedia Commons.</a></figcaption></figure><p>Compilers and interpreters [6] exploit the hierarchical structure and order of a tree. Parse trees are formal representations of a language that can be understood by computers.</p><h4>Set</h4><p>As we mentioned earlier, sets are implemented as trees. Sets are very useful for keeping unique elements in a given list, not to mention that they serve to be the foundation of mathematics — we know this from <a href="https://plato.stanford.edu/entries/set-theory/">set theory</a>. It follows that advanced mathematical concepts are realized within the structure of the set.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4002ec817053cb1c3cf3073ee57e66fb/href">https://medium.com/media/4002ec817053cb1c3cf3073ee57e66fb/href</a></iframe><h4>Map</h4><p>A map is a key-value pair data structure, other languages like Python call them dictionaries. A key is an index that you use to call its corresponding value.</p><p>The computer scientist, Brian Kernighan, deemed them as the most useful kind of data structure.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FqTZJLJ3Gm6Q%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DqTZJLJ3Gm6Q&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FqTZJLJ3Gm6Q%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/dab09cfedd07c4edc1dfff8c3200a97a/href">https://medium.com/media/dab09cfedd07c4edc1dfff8c3200a97a/href</a></iframe><p>The most notable application of maps is in <a href="https://www.cise.ufl.edu/~mschneid/Research/papers/HS05BoCh.pdf">database systems</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1a51de18e3835857d31da37906c7087/href">https://medium.com/media/a1a51de18e3835857d31da37906c7087/href</a></iframe><h4>Graph</h4><p>Finally, the broadest category of data structure is here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/0*n_atYiBEgAqHOXY6" /><figcaption>Hypergraph of the universe. Source: <a href="https://bityl.co/6Mnj">https://bityl.co/6Mnj</a></figcaption></figure><p>A graph is a generalization of Trees. An area of mathematics and computer science is devoted to exploring the universe of graphs. Among my personal favorites is the realization of graph theory in automated theorem proving and some theoretical foundations in Physics, as found in Stephen Wolfram’s project.</p><p>Graphs are everywhere, and we can represent nearly all problems with a graph since a tree is a special case of a graph and a linked list is a special case of a tree.</p><h3>Takeaways</h3><p>Now that we covered the fundamental data structures and their use cases, we learned that we can represent problems in various forms of data structure. We also covered the areas of applications where such data structures are found most crucial. And we laid out the abstract model for implementing these data structures. A fun way to explore this area of computer science is to try and implement them on your own.</p><p><em>If you want to engage on this topic with me, I’ll be posting a series on the quirky bits of implementing these data structures in detail soon so stay tuned!</em></p><h4>References</h4><ol><li>Dale, Nell; Walker, Henry M. (1996). <em>Abstract Data Types: Specifications, Implementations, and Applications</em>. Jones &amp; Bartlett Learning. <a href="https://en.wikipedia.org/wiki/ISBN_(identifier)">ISBN</a> <a href="https://en.wikipedia.org/wiki/Special:BookSources/978-0-66940000-7">978–0–66940000–7</a>.</li><li>Stephens, R. (2019). <em>Essential algorithms: a practical approach to computer algorithms using Python and C</em>. John Wiley &amp; Sons.</li><li>GeekforGeeks (2018). Applications of Queue Data Structure. <a href="https://www.geeksforgeeks.org/applications-of-queue-data-structure/">https://www.geeksforgeeks.org/applications-of-queue-data-structure/</a></li><li>Wikipedia contributors. (2021, March 31). Binary search tree. In <em>Wikipedia, The Free Encyclopedia</em>. Retrieved 08:24, April 13, 2021, from <a href="https://en.wikipedia.org/w/index.php?title=Binary_search_tree&amp;oldid=1015282423">https://en.wikipedia.org/w/index.php?title=Binary_search_tree&amp;oldid=1015282423</a></li><li>Becker, Georg (2008–07–18). <a href="http://www.emsec.rub.de/media/crypto/attachments/files/2011/04/becker_1.pdf">“Merkle Signature Schemes, Merkle Trees and Their Cryptanalysis”</a> (PDF). Ruhr-Universität Bochum. p. 16.</li><li>Nystrom, R. (2018). Crafting Interpreters. <a href="https://craftinginterpreters./"><em>https://craftinginterpreters.</em></a><em> com/[2. 8. 2020]</em>.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=882a6e57245f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/elements-of-programming-fundamental-data-structures-882a6e57245f">Elements of Programming: Fundamental Data Structures</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Language of Calculus (Part 1)]]></title>
            <link>https://medium.com/dave-amiana/the-language-of-calculus-part-1-e646876cf078?source=rss-32103f4c576e------2</link>
            <guid isPermaLink="false">https://medium.com/p/e646876cf078</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[philosophy]]></category>
            <category><![CDATA[mathematics]]></category>
            <dc:creator><![CDATA[Dave Amiana]]></dc:creator>
            <pubDate>Mon, 02 Nov 2020 00:50:37 GMT</pubDate>
            <atom:updated>2021-04-14T11:35:23.788Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Language of Calculus</h3><h4>The Story of Leibniz, his notations and ideas</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zrOIiwhTa6IPsbwnlonZbQ.jpeg" /><figcaption>Gottfried Wilhelm Leibniz. Image source: <a href="https://bityl.co/4FKD">https://bityl.co/4FKD</a></figcaption></figure><p>Gottfried Wilhelm Leibniz was a prominent German polymath of the 17th century. He made contributions not only in the field of mathematics, which his most prominent discoveries on the language of symbolic logic, and calculus were established, but also in philosophy, which he formally studied, and theology where he argued a rational stance for the existence of God. While Leibniz works in different fields were found to be foundational he was involved in controversies that although he was a member of the Royal Society and the Berlin Academy of Science, his grave went unmarked for 50 years.</p><p>This is the story of how Leibniz dreamt of expressing our thoughts through symbols that formally captures the <em>meaning </em>of sentences. A link to that of his works in Infinitesimal Calculus.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*0CNB7yrKW5WFFUmE" /><figcaption>Drawing of Leibniz’s calculating machine, featured as a folding plate in Miscellanea Berolensia ad incrementum scientiarum (1710). <a href="https://commons.wikimedia.org/wiki/File:Leibniz%27s_drawing_of_his_calculating_machine.jpg">Source</a>.</figcaption></figure><p>Among his numerous contributions, the language of Calculus is most suited for our discussion. Leibniz believed that much of human reasoning can be reduced to calculations of some sort[2].</p><blockquote>The only way to rectify our reasonings is to make them as tangible as those of the Mathematicians so that we can find our error at a glance, and when there are disputes among persons, we can simply say: Let us calculate<em>[calculemus]</em>, without further ado, to see who is right.</blockquote><p>Leibniz held the view that symbols were important for human understanding. His belief about the essential role of symbols and notations to a well-running logic, and mathematics, made him a precursor of semiotics[1]. He believed that formal operations such as logic and arithmetic can automate knowledge by a rule-based combination of symbols [2].</p><p>Leibniz took his idea further by constructing a <em>character </em>which he ascribed as <strong><em>real </em></strong>characters that represent an idea directly and not simply as the word embodying the idea. He proposed the creation of a <em>characteristica universalis </em>(universal characteristic) which was constructed on an alphabet of human thought. He imagined a formal language that can able to express abstract mathematical, scientific, and metaphysical ideas. By combining simple representations of thoughts, one can build some level of complexity (through abstraction).</p><p>Leibniz&#39;s idea of reasoning from symbolic representations remarkably foreshadows the later developments in modern logic which made him a prominent logician of his time. He is noted as one of the most important logicians between the times of Aristotle and Gottlob Frege[4].</p><p>In relation to Leibniz’s works on calculus, these ideas were remarkable for his choice of notations that enunciate the underlying concepts of the Infinitesimal Calculus.</p><h3>Leibniz’s Notation</h3><p>Leibniz introduced the integral sign, we know and love ∫ representing an elongated <em>S</em>, from its Latin word <em>summa</em>, and the d-operator used for differentials, from the Latin word <em>differentia</em>. Remarkably, Leibniz did not publish anything about his calculus until 1684. It is also worth noting that the notations introduced by Leibniz made the concepts of calculus more transparent.</p><h4>The Limit Operator</h4><p>The limit of a function is the value that a function approaches as in the input of Δ<em>x</em> approaches. Below is the definition of a derivative with respect to <em>x</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/364/0*pmvI7rfDrlMbNzpq" /></figure><p>A derivative, of a function, tells us about the rate of change of that function as the limit of Δ<em>x </em>approaches 0, or simply the tangent of a function; we can notice that Leibniz’s definition of a derivative is an approximation of a tangent by defining a secant which approaches to 0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*kos4NYG_bZKUdEPKO4O4_g.gif" /><figcaption>The derivative of a function as the limit Δx →0. <a href="https://i.pinimg.com/originals/92/8b/38/928b383581bf6d92947443ca3b83b8fe.gif">Source</a>.</figcaption></figure><h4>Notations for Higher-order derivatives and integrals</h4><p>In general, derivatives can be expressed using the d-operator which is placed below with the Langrangian differential operator <em>f ⁿ(x).</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/145/0*Cu7rB20YOJZ35Rs0" /></figure><p>This is a suggestive notational device that comes from formal manipulations of symbols, as in</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/228/0*qpw_AOdda9xD3lQb" /></figure><p>It is important to note that these equations are not theorems: they are simply definitions of notation. Leibniz’s notation allows one to specify the variable for differentiation (in the denominator). This is especially helpful when considering partial derivatives for higher-dimensions as in</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/90/0*dhcM1zENMIEKomy_" /></figure><p>where it denotes the second partial derivative of the function<em> f</em> with respect to <em>y</em>. And finally for denoting higher-order integrals with the Summa symbol which describes the volume under a surface. Leibniz’s notation reminds the notion of infinitesimal changes under curved surfaces which is then <em>compiled as the infinitesimal sum of the summa operator.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/0*fgN7zkI0Jfx8qhgX" /></figure><p>Derivatives and Integrals are related by the <a href="https://bityl.co/4GMr">fundamental theorem of Calculus </a>which is also suggestive of the above notation with the d-operator sitting on the other side of the <em>summa</em>.</p><h4>References</h4><p>[1]. Marcelo Dascal, <em>Leibniz. Language, Signs and Thought: A Collection of Essays</em> (<em>Foundations of Semiotics</em> series), John Benjamins Publishing Company, 1987, p. 42.</p><p>[2]. O. Schwartz (2019). In the 17th Century, Leibniz Dreamed of a Machine That Could Calculate Ideas. <a href="https://spectrum.ieee.org/tech-talk/artificial-intelligence/machine-learning/in-the-17th-century-leibniz-dreamed-of-a-machine-that-could-calculate-ideas">IEEE Spectrum</a>.</p><p>[3].<em> The Art of Discovery</em> 1685, Wiener 51</p><p>[4]. Lenzen, W., 2004, “Leibniz’s Logic,” in <em>Handbook of the History of Logic</em> by D. M. Gabbay/J. Woods (eds.), volume 3: <em>The Rise of Modern Logic: From Leibniz to Frege</em>, Amsterdam et al.: Elsevier-North-Holland, pp. 1–83.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e646876cf078" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dave-amiana/the-language-of-calculus-part-1-e646876cf078">The Language of Calculus (Part 1)</a> was originally published in <a href="https://medium.com/dave-amiana">Recursion</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>