<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Migwi Ndung'u </title>
    <description>The latest articles on Forem by Migwi Ndung'u  (@dmigwi).</description>
    <link>https://forem.com/dmigwi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F49648%2Fb080e2e3-7b10-4ac9-b8da-3a2cf26bc082.jpg</url>
      <title>Forem: Migwi Ndung'u </title>
      <link>https://forem.com/dmigwi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/dmigwi"/>
    <language>en</language>
    <item>
      <title>Authentication: Trust Vs Identity.</title>
      <dc:creator>Migwi Ndung'u </dc:creator>
      <pubDate>Fri, 28 Feb 2025 23:50:02 +0000</pubDate>
      <link>https://forem.com/dmigwi/authentication-trust-vs-identity-425l</link>
      <guid>https://forem.com/dmigwi/authentication-trust-vs-identity-425l</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foobmdawuyklv0eclv8ly.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foobmdawuyklv0eclv8ly.png" alt="Trust_Based_Authentication" width="577" height="302"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  🚀 Authentication
&lt;/h4&gt;

&lt;p&gt;Authentication is the mechanism of associating an incoming request with a set of identifying credentials. The credentials provided are compared to those in a database of the authorised users’ information.&lt;/p&gt;

&lt;h4&gt;
  
  
  🚀 Identity Vs Trust
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Identity&lt;/strong&gt; can be defined as existential attribute associated with a given object or entity. This attribute is independent, absolute, and constant throughout the object's life. &lt;strong&gt;Trust&lt;/strong&gt; on the other hand can be defined as an object/entity's acquired attribute that is relative and dependent on others. Trust is a derived attribute.&lt;/p&gt;

&lt;h4&gt;
  
  
  🚀 Traditional Authentication Protocols
&lt;/h4&gt;

&lt;p&gt;I refer to all authentication protocols that depend on a user's Identity as traditional because of the following serious flaws that are in-built in all of them:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Most platforms discourage authentication in an insecure environment. Secure environments are rare to find especially in restricted and/or public places like airports. Majority of the authentication platforms also cannot differentiate secure and insecure environments used by users.&lt;/li&gt;
&lt;li&gt;Validation of an identity simply means, "&lt;strong&gt;If you have the correct keys combination, then you must be the valid owner&lt;/strong&gt;". How the user gets the correct key combination is irrelevant to the protocol.&lt;/li&gt;
&lt;li&gt;They have no comprehensive ways to detect keys duplication. Valid keys are often used to grant unauthorised access. Most platforms can only detect duplication if a different device is used.&lt;/li&gt;
&lt;li&gt;Once unauthorised access is detected, most entities initiate their nuclear options which not only cut-off the affected user(s) but also subject them to extremely tedious proof of identity methods.&lt;/li&gt;
&lt;li&gt;Since identification credentials do not change that often, tracking someone's activities becomes very easy.&lt;/li&gt;
&lt;li&gt;Users' identity information is scattered among thousands of platforms which make it very hard and expensive to enforce data protection rules within a given jurisdiction i.e. &lt;a href="https://www.gdprsummary.com/gdpr-summary/" rel="noopener noreferrer"&gt;GDPR&lt;/a&gt; for platforms within European Economic Area. &lt;/li&gt;
&lt;li&gt;Authentication keys are supposed to either be memorised or managed by a third-party software which could be the source of a leak if not properly vetted before installation. Memorised keys often get lost if the user's memory becomes impaired.&lt;/li&gt;
&lt;li&gt;Most AI and Large Language Models have become so advanced that they can be said to have passed the Turing test. Deep fakes with near perfect abilities to replicate most biometric security features make it extremely hard for an identity-based authentication protocol to differentiate a human from a bot.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  🚀 Data-Age Authentication protocol
&lt;/h4&gt;

&lt;p&gt;This describes a data intensive authentication protocol that is based on trust where a cryptographically-signed key with a one-time-password feature in used. This trust key is issued and mutated by the trust organisation. For each successful authentication operation a new trust key with no user identifying data is used.&lt;/p&gt;

&lt;p&gt;To successfully implement this protocol, the following entities must mutually authenticate each other:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;em&gt;Trust Organisation&lt;/em&gt; - A 3rd party that holds users' personal identification information on behalf of the target system(s).&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Target Authentication System&lt;/em&gt; - Requires the trust organization approval to successfully validate a user's trust key.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;User&lt;/em&gt; - Carries a trust key that is only backward traceable to the parent trust organisation and is mutated after every successful authentication.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This authentication protocol makes it nearly impossible to identify a specific user during the authentication process and ensures all the authentication operations are unique for the specific trust organisation.&lt;/p&gt;

&lt;h4&gt;
  
  
  🚀 Strengths of Data-Age authentication over the Traditional Authentication Protocols.
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Advancements of the modern technologies in NFC, powerful GPU's and Ready AI models make it very easy to rollout the protocol in a large-scale. The NFC can used to store an OTP trust key while the AI models and powerful GPU's can be used scale up the efficiency of a trust organisation.&lt;/li&gt;
&lt;li&gt;The OTP nature of the trust key after every successful authentication means that duplicate valid trust keys cannot exist simultaneously.&lt;/li&gt;
&lt;li&gt;Validation using trust key simply means, "&lt;strong&gt;The trust key you have and how you use it, determines how much of the valid owner you are&lt;/strong&gt;". By default, the protocol assumes that every user is malicious/a bot and only grants the necessary permissions depending on the kind of trust held.&lt;/li&gt;
&lt;li&gt;Since personal information is only managed by a few trust organisations on behalf of very many target systems; more user-friendly disaster recovery and business continuity policies can be implemented cheaply.&lt;/li&gt;
&lt;li&gt;The trust key is exclusively stored in an NFC tag, allowing characters longer than an average human being can memorise, to be mutated after every successful authentication.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.gdprsummary.com/gdpr-summary/" rel="noopener noreferrer"&gt;GDPR&lt;/a&gt; can be best enforced on the few trust organisations that meet the strict requirements needed to safely and securely handle sensitive personal data. This allows a user to be 100% aware of how their personal information is being used.&lt;/li&gt;
&lt;li&gt;Since target systems can no longer identify an individual user, they can monetise the data acquired from the authentication operations with zero risk to the users.&lt;/li&gt;
&lt;li&gt;Mutual authentication for all the three entities involved, implies that any entity that misbehaves it can be punished by the rest. Trust Organisation with malicious users will not be accepted by the Target System, Trust organisation can reject all authentication requests from a malicious target system. Users can also be rejected for being associated with malicious Trust Organisations or Target Systems.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  🚀 Conclusion
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Identity-based protocols consider the security of the authentication Keys as the individual responsibility of a specific user. The Target Authentication System has minimal to no consequences of mishandling users' sensitive data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Trust-based protocol considers the security of the authentication keys belonging to a specific user as a collective responsibility of all the entities involved. All the entities involves must be responsible in how they handle the sensitive users' data otherwise grave consequences with follow them.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>authentication</category>
      <category>identity</category>
      <category>trust</category>
    </item>
    <item>
      <title>Blockchain Technology: The future is here</title>
      <dc:creator>Migwi Ndung'u </dc:creator>
      <pubDate>Thu, 08 Mar 2018 01:43:17 +0000</pubDate>
      <link>https://forem.com/dmigwi/blockchain-technology-the-future-is-here-513f</link>
      <guid>https://forem.com/dmigwi/blockchain-technology-the-future-is-here-513f</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpmo2qwavcihoch0141zl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpmo2qwavcihoch0141zl.png" alt="Blockchain is the future" width="800" height="560"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For quite some time I have tried to consciously avoid the blockchain technology topic but I can't afford to ignore it anymore. I have also heard so many people call bitcoin a bubble in the financial markets that will autocorrect with time but now I beg to differ with people in the above school of thought.&lt;/p&gt;

&lt;p&gt;Blockchain is a new form of technology used as the underlying technology supporting  the Bitcoin ecosystem as listed by Satoshi Nakamoto in the bitcoin &lt;a href="https://bitcoin.org/bitcoin.pdf" rel="noopener noreferrer"&gt;whitepaper&lt;/a&gt; published in 2008. Therefore blockchain is a decentralized ledger/record of transactions that is accessible to all involved parties and cannot be altered unless genuine transactions are being added.&lt;/p&gt;

&lt;p&gt;The next question that we are all asking ourselves is, &lt;strong&gt;"How did blockchain gain such a huge adoption in that short time span? "&lt;/strong&gt;. To answer the above, question we need to revisit the history about trading and financial transactions. &lt;/p&gt;

&lt;p&gt;Barter trade was the way of life before money was invented. Someone used to exchange item A with item B if at all there was a consensus that both items A and B held the same value. This was problematic especially if item A and B did not hold an equal value.&lt;/p&gt;

&lt;p&gt;Some brilliant people came up with the concept of money that was widely accepted because it held a definite value that could be subdivided without losing its original value. Governments and banks took up the role of managing the money which was converted to the various currencies that we use today. They made the currencies become a &lt;strong&gt;medium of exchange&lt;/strong&gt;, &lt;strong&gt;store of value&lt;/strong&gt; and &lt;strong&gt;a unit account&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Using money, governments and banks have misused the &lt;strong&gt;trust&lt;/strong&gt; bestowed to them by the common people concerning the financial transactions. Money is nowadays used to control people which wasn't the original use and intention of the money.&lt;/p&gt;

&lt;p&gt;Cryptocurrencies through blockchain were introduced to enable people make  financial transactions almost anonymously though a system that was designed to be foul proof. This means that entities making financial transactions need not trust each other as none of them has higher control of the system that the other.&lt;/p&gt;

&lt;p&gt;It also becomes easier and safer to make transactions as every successful transaction made, is stored in a database who copies are available to all participants. Its cheaper too as several middlemen in the Banking system are eliminated. The only limitation of the current versions of crypto-currencies is that they are too volatile. Their net value can increase or fluctuate within a split of a second.&lt;/p&gt;

&lt;p&gt;I believe that crypto-currencies represent just a tip of the iceberg of what that can be achieved through the blockchain technology. It sort of proves a concept that true decentralization is the future. A lot of services that are currently centralized e.g. land ownership registry can be made easier to administer if they are fully decentralized using the blockchain technology.&lt;/p&gt;

&lt;p&gt;I believe that we can make life better with blockchain technology. &lt;em&gt;I believe blockchain technology is the future&lt;/em&gt;&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>bitcoin</category>
      <category>alreadybigthing</category>
    </item>
    <item>
      <title>Mocking Methods in Go</title>
      <dc:creator>Migwi Ndung'u </dc:creator>
      <pubDate>Sun, 17 Dec 2017 05:00:55 +0000</pubDate>
      <link>https://forem.com/dmigwi/mocking-methods-in-go-5fg</link>
      <guid>https://forem.com/dmigwi/mocking-methods-in-go-5fg</guid>
      <description>&lt;p&gt;It goes without saying that a battalion of soldiers is as strong as their weakest link. In this context, a piece of code is free of bugs and other issues as its weakest point. &lt;strong&gt;Kent Beck&lt;/strong&gt; from facebook once visited us at Andela to give a talk on TDD and throughout his session, it was clear that unit testing is critical part of the software development.&lt;/p&gt;

&lt;p&gt;Languages like Python provide standardised libraries and frameworks that make it easy to mock methods and functions inside an impure function or method. With python unit tests are pretty easy thus achieving a 100% test coverage is the norm.&lt;/p&gt;

&lt;p&gt;Go or Golang is a light weight language that is not C based. Its syntax is pretty easy, I like to refer to golang as a "&lt;em&gt;Pythonized version of Java&lt;/em&gt;" due to the similarity of concepts &lt;em&gt;imported&lt;/em&gt; from both Java and Python. Golang does not have an official package that supports mocking of methods during unit testing. &lt;/p&gt;

&lt;p&gt;Mocking in golang is done with the help of &lt;a href="http://www.golangbootcamp.com/book/interfaces" rel="noopener noreferrer"&gt;interfaces&lt;/a&gt;. Mocking in unit testing is important as it ensure that variables, methods and functions modified outside the scope of the function being tested do not affect the test output.&lt;/p&gt;

&lt;p&gt;Here is the implementation of mocking.go&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;/** mocking.go **/&lt;/span&gt;

&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="c"&gt;// Values defines interface to be used in mocking&lt;/span&gt;
    &lt;span class="n"&gt;Values&lt;/span&gt; &lt;span class="k"&gt;interface&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;GetVolume&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;
        &lt;span class="n"&gt;GetSurfaceArea&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c"&gt;// Measurements defines the measurements used to calculate&lt;/span&gt;
    &lt;span class="c"&gt;// the surface area and volume of a cube or a cuboid.&lt;/span&gt;
    &lt;span class="n"&gt;Measurements&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;Length&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;
        &lt;span class="n"&gt;Width&lt;/span&gt;  &lt;span class="kt"&gt;int&lt;/span&gt;
        &lt;span class="n"&gt;Height&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c"&gt;// GetVolume calculates and returns the volume of a cube or a cuboid&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;Measurements&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;GetVolume&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Height&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Length&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Width&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// GetSurfaceArea calculates and returns the surface area of a cube or cuboid&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;Measurements&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;GetSurfaceArea&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Length&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Width&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Length&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Width&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Height&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Width&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// GetVolumeAndArea fetches and returns the volume and the area&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;GetVolumeAndArea&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="n"&gt;Values&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetVolume&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetSurfaceArea&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// program execution starts here&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;area&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;volume&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;

        &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;Measurements&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;Length&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;Height&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;Width&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;  &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;volume&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;area&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;GetVolumeAndArea&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Volume : %d , Area : %d &lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;volume&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;area&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;GetVolumeAndArea&lt;/code&gt; function accepts an interface as its input parameter. This means that any receiver (&lt;em&gt;struct used to create a method&lt;/em&gt;) that implements &lt;code&gt;GetVolume&lt;/code&gt; and &lt;code&gt;GetSurfaceArea&lt;/code&gt; also implements the &lt;code&gt;Values&lt;/code&gt; interface.&lt;/p&gt;

&lt;p&gt;Mocking of &lt;code&gt;GetVolume&lt;/code&gt; and &lt;code&gt;GetSurfaceArea&lt;/code&gt; is done by passing their customized implementations through the struct that acts as their receiver.&lt;/p&gt;

&lt;p&gt;Below is how mocking of &lt;code&gt;GetVolume&lt;/code&gt; and &lt;code&gt;GetSurfaceArea&lt;/code&gt; should be done using interfaces. No extra libraries or frameworks needed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;/** mocking_test.go **/&lt;/span&gt;

&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"strconv"&lt;/span&gt;
    &lt;span class="s"&gt;"testing"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c"&gt;// MockTest helps implement our customized GetVolume and GetSurfaceArea&lt;/span&gt;
&lt;span class="c"&gt;// needed to mock the original implementation in mocking.go&lt;/span&gt;
&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;MockTest&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Elem&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// GetVolume returns the volume of a cube&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;MockTest&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;GetVolume&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Elem&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Elem&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Elem&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// GetSurfaceArea returns the surface area of a cube&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;MockTest&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;GetSurfaceArea&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Elem&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Elem&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="m"&gt;6&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// TestGetVolumeAndArea tests the functionality of GetVolumeAndArea&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;TestGetVolumeAndArea&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;testing&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="k"&gt;map&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;MockTest&lt;/span&gt;&lt;span class="p"&gt;][]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;MockTest&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;Elem&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="m"&gt;125&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;150&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="n"&gt;MockTest&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;Elem&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="m"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;24&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="n"&gt;MockTest&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;Elem&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;6&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Cube side length "&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;strconv&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Itoa&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Elem&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;testing&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;volume&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;area&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;GetVolumeAndArea&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;volume&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Errorf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Expected volume to be equal to %d but was equal to %d "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="n"&gt;volume&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
                &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;FailNow&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;

            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;area&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Errorf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Expected area to be equal to %d but was equal to %d "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="n"&gt;area&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
                &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;FailNow&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Apart from mocking, interfaces also helps in separating of concerns such that pieces of code/functions/methods that communicate with each other can be made to run independent of each other.&lt;/p&gt;

&lt;p&gt;They also help hide the underlying implementations that should not be exposed to the outside world especially when building an API.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;For any &lt;strong&gt;Clarifications&lt;/strong&gt;, &lt;strong&gt;Corrections&lt;/strong&gt; or &lt;strong&gt;Complements&lt;/strong&gt; reach out to me via Email on mailto:&lt;a href="mailto:migwindungu0@gmail.com"&gt;migwindungu0@gmail.com&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>unittests</category>
      <category>mocking</category>
      <category>interfaces</category>
    </item>
    <item>
      <title>No Regrets At All</title>
      <dc:creator>Migwi Ndung'u </dc:creator>
      <pubDate>Sat, 16 Dec 2017 11:55:04 +0000</pubDate>
      <link>https://forem.com/dmigwi/no-regrets-at-all-g5</link>
      <guid>https://forem.com/dmigwi/no-regrets-at-all-g5</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmirpt7zn4t38vp0ir3g2.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmirpt7zn4t38vp0ir3g2.jpg" alt="No Regrets" width="226" height="247"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Seven years ago(2010) I was preparing to seat for my KCSE (Kenya Certificate for Secondary Examination) exam as from November 21st, which marks the end of the secondary education in Kenya. After the exam, one is then ushered into the real unforgiving world where they can choose to hustle (&lt;em&gt;do Jua Kali/informal jobs&lt;/em&gt;) or continue with their education to college and take a course depending on what they scored in the KSCE exam.&lt;/p&gt;

&lt;p&gt;While preparing to do my KCSE exam, I knew for sure that I had to go to college whatever the cost and do an engineering course. Earlier on, we had a career fair day and I zeroed in on a Bachelor's degree in Computer and Electronics. In preparations to me joining the degree course, I had kept several chunks of scrap electronic parts and other items that would have made my on boarding as smooth as possible. Once in a while I used to land myself in an argument with my mum as after trying to build something with my scrap electronic parts, I left other electronic parts scattered all over the house.&lt;/p&gt;

&lt;p&gt;The KSCE exam was successful, sadly when the results came back I couldn't join my dream course because my grades were below the cut line. I sought advice from a certain lecturer who advised me to take a Bachelor's degree in Computer Science and hopefully one year later into the course I could easily switch into my engineering degree. The lecturer forgot to tell me that his idea could only work if I was admitted into a university that offered both degrees.&lt;/p&gt;

&lt;p&gt;The university selection was done by a government parastatal called JAB now called &lt;a href="http://kuccps.net/" rel="noopener noreferrer"&gt;KUCCPS&lt;/a&gt; and I was posted to a college pretty far away from where I initially wanted to school. A few weeks after getting admitted, the reality dawned on me. All I could be able to do in the new college was computer science and I took my time before I fully settled and accepted to do it as a course and a career. I even tried to do an inter-university transfer but was rejected.&lt;/p&gt;

&lt;p&gt;In the second year, I came to discovered the feeling of commanding a piece of code to do as instructed. My first piece code was a "Hello World" program in C and it felt like God had delegated to me some of his powers that he used to say, let there be light and there was light. I felt in computer science unlike engineering I was only limited by my imagination. My Procedural Programming lecturer explained during one of his lectures that several years might pass by before a change to the qwerty keyboard is made a standard but a software built in a very short time may transform lives. He basically informed us that a hardware change takes time before its effect can be felt but we had in our hands the power to transform the world with a software change.&lt;/p&gt;

&lt;p&gt;With time I learnt by myself how to write code in Java through googling overnight when the noise level was lowest and the WIFI speed was fastest at the college WAPs (Wireless Access Points). I built an application that could help in transferring files since I couldn't afford a quality USB flash disk then. For my final year project, I created a hide and seek game inside a maze.&lt;/p&gt;

&lt;p&gt;Building softwares has given me the best of memories and fun times. I have taken almost a full day to debug a piece of code only to find that a semicolon fixed the bug. I felt so great after fixing the bug that I can't trade the feeling with anything. If I never did software development, I am sure I would have had one extra regret in the list of the things I never did on my death bed.&lt;/p&gt;

&lt;p&gt;It has been five years since I wrote my first hello world program in C. So far I have no regrets about failing to join an engineering course. Software development has given me a greater purpose to live. The climax of my career is going to be when I build a product that has both software and hardware components of a computer. I am currently proficient in Python and Go. I will be taking a C refresh course soon then venture into hardware programming later on. Once done with this, I will have lived my life to the fullest.&lt;/p&gt;

</description>
      <category>inspiration</category>
      <category>noregrets</category>
    </item>
  </channel>
</rss>
