<?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 Surya Reddy on Medium]]></title>
        <description><![CDATA[Stories by Surya Reddy on Medium]]></description>
        <link>https://medium.com/@devcharmander?source=rss-7742f0c6a317------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wLJi6X_l5yBkoqj00oI9tQ.jpeg</url>
            <title>Stories by Surya Reddy on Medium</title>
            <link>https://medium.com/@devcharmander?source=rss-7742f0c6a317------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 21:29:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@devcharmander/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[Neovim for journaling  ]]></title>
            <link>https://devcharmander.medium.com/neovim-for-journaling-9b5503dc341a?source=rss-7742f0c6a317------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b5503dc341a</guid>
            <category><![CDATA[journaling]]></category>
            <category><![CDATA[software-tools]]></category>
            <category><![CDATA[neovim]]></category>
            <category><![CDATA[mental-health]]></category>
            <category><![CDATA[tech-tools]]></category>
            <dc:creator><![CDATA[Surya Reddy]]></dc:creator>
            <pubDate>Sun, 03 Apr 2022 17:54:06 GMT</pubDate>
            <atom:updated>2022-04-03T18:12:57.216Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GaMTHO3USnyITfHB" /><figcaption>Photo by <a href="https://unsplash.com/@thoughtcatalog?utm_source=medium&amp;utm_medium=referral">Thought Catalog</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Benefits of journaling.</h4><p>This blog is not about that!</p><p>If you are like me, who loves Neovim and journaling, this blog is for you 😍</p><h4>The Paradox of choice</h4><p>I used to journal in Notion. It is a great tool with a lot of features, so much so, that I ended up spending more time beautifying my pages and playing around with features than writing my journal.</p><blockquote>Learning to choose is hard. Learning to choose well is harder. And learning to choose well in a world of unlimited possibilities is harder still, perhaps too hard.</blockquote><blockquote>– Barry Schwartz in his book The Paradox of Choice</blockquote><p>I learned recently that I can write my journal using Neovim with “<a href="https://github.com/vimwiki/vimwiki"><strong>vimwiki</strong></a>”</p><h3>Let&#39;s get started!</h3><p>This is what your journal would look like if you follow the instructions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0eSaKRpJOrBsndKvH35elw.gif" /></figure><p>Configuration:</p><p>You need 3 more plugins:</p><ul><li><a href="https://github.com/junegunn/goyo.vim">Goyo</a>: For distraction-free writing.</li><li><a href="https://github.com/junegunn/limelight.vim">Limelight</a>: To highlight the area under the cursor.</li><li><a href="https://github.com/preservim/vim-lexical">Vim-lexical</a>: Spell check and dictionary.</li></ul><p>Of course, these are optional, but I recommend you to use them for a minimalistic and distraction-free experience.</p><p>Apart from these plugins, you need some vim script to ease your journaling experience. (<em>explanation below</em>)</p><h4>Separation of concerns.</h4><p>We Software Engineers are fond of this concept and rightly so, you do not want to clutter your existing <em>vimrc</em> or <em>init</em> file with new plugins and scripts.</p><p>You can do this by using a separate Neovim configuration file for journaling and loading it with -u flag.</p><pre>alias journal = &quot;nvim -u ~/.config/nvim/journal.vim&quot;</pre><p>Once this is added to your zshrc or bashrc , you can use the command journal to start journaling.</p><h4>Pre-requisites</h4><p>Before I explain the configuration there are a few things I keep in my journal directory.</p><ul><li>A journal template as a markdown file.</li><li>A text file with some random quotes for daily motivation.</li></ul><p>The configuration above would enable you to load a template for a new journal entry by pressing &lt;space-l&gt; .</p><p>Here is a sample 📄</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*niHq92ORDNgMRoxpq5ozig.png" /></figure><h4>Now the config 🥁</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d958b4a83c9cf81514d669511bc6fe94/href">https://medium.com/media/d958b4a83c9cf81514d669511bc6fe94/href</a></iframe><p>The actual config is from line 128.</p><p>This is my current configuration file with some theme and key mappings which can be ignored.</p><h4>Explanation:</h4><p>LoadQuotes(): Loads a random quote from a file named “quotes”.</p><p>JournalHeader(): Creates a title for your journal entry in this format</p><pre>date mm/dd @ Title of your journal entry</pre><p>Line 143 sets markdown as the syntax. The default format for vimwiki is <a href="https://www.mediawiki.org/wiki/Help:Formatting">MediaWiki</a>. Use this config if you are comfortable with markdowns.</p><p>Line 145: Spell check locale values for vim-lexical</p><p>line 147–149: Automatically enables Vimwiki, Goyo and Limelight when you open Neovim.</p><p>Some useful shortcuts that I use:</p><ul><li>\ww Opens the journal’s index page. Think of this as a home page where you can write whatever you want. I use this to maintain my blog ideas and track the progress of my side projects.</li><li>\wi Opens the index page of the diary. This is where all the headings of your journal entries are placed. Think of this as a “<em>Table of contents”.</em></li><li>\w\w Creates a new journal entry.</li><li>\w\i Updates the Diary index page.</li><li>&lt;space-l&gt; Press &lt;space&gt; followed by ‘l’ to load the template.</li><li>enter on a selected word would create a link to another page.</li><li>backspace brings you back to the parent page.</li></ul><p>That&#39;s it! Enjoy journaling 📖 🖊</p><h4>Pro tip 💡</h4><p>You can use Github as your online journal store. 💁‍♂</p><ul><li>Create a private repo 💪</li><li>Use <a href="https://github.com/AGWA/git-crypt">Git-crypt</a> to encrypt your files. 😌</li></ul><p>If you are reading this and have never journaled before … Give it a try ❤️</p><p>During these unprecedented times, it is easy to feel that every day is just the same.</p><p>Journaling will help you slow down and reflect on life. It is great for one’s mental health 🤗 💅</p><p>References:</p><ul><li><a href="https://github.com/vimwiki/vimwiki">Vimwiki</a></li><li><a href="https://github.com/junegunn/goyo.vim">Goyo</a></li><li><a href="https://github.com/junegunn/limelight.vim">Limelight</a></li><li><a href="https://github.com/preservim/vim-lexical">Vim Lexical</a></li><li><a href="https://neovim.io/">Neovim</a></li></ul><p>Special thanks to the legend <a href="https://github.com/junegunn">Junegunn</a> for the awesome contributions to the OSS community ❤️</p><p>Let me know if you have any feedback! 🍻 ✌️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b5503dc341a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My experiences with Swedish  and Indian  work culture]]></title>
            <link>https://devcharmander.medium.com/my-experiences-with-swedish-and-indian-work-culture-f73c73cdc413?source=rss-7742f0c6a317------2</link>
            <guid isPermaLink="false">https://medium.com/p/f73c73cdc413</guid>
            <category><![CDATA[swedish-work-culture]]></category>
            <category><![CDATA[indian-work-culture]]></category>
            <category><![CDATA[work-culture-differences]]></category>
            <dc:creator><![CDATA[Surya Reddy]]></dc:creator>
            <pubDate>Tue, 07 Dec 2021 17:48:39 GMT</pubDate>
            <atom:updated>2021-12-07T17:48:39.572Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OBDWk-8X_4Dm1va0" /><figcaption>Photo by <a href="https://unsplash.com/@timmossholder?utm_source=medium&amp;utm_medium=referral">Tim Mossholder</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote><em>At first, a formal note to say that this blog is not about Sweden vs India.</em></blockquote><p>I recently moved to Sweden to work for a FinTech and am almost blown away and overwhelmed at the same time to experience Swedish work culture.</p><p>It has been 3 months since I moved here and this is a sensitive topic (obviously!). So, take it with a pinch of salt and don’t get offended 😅</p><blockquote>When people of different cultures work for the same company they do not know each other, they are uncertain about the other parts intention and the meaning of the words that are spoken. They might not understand the behaviour of the other and could even be offended by it. Knowing the culture of people we are working with plays a crucial part in strong cooperation and collaboration among people with different values and views of life.</blockquote><p>Here are my experiences …</p><h3>Flat hierarchy</h3><p>I have experienced a flat hierarchy in Sweden. People do not fear to express their thoughts. Everyone&#39;s opinion is respected. It&#39;s not weird to question your senior and an intern can challenge a CEO of the company if she/he feels her/his idea is better 💪</p><p>I know there are some cool startups in India that encourage people to open up, however, this kind of culture is very rare and scarce in IT companies in India.</p><p>In India, it is not uncommon for managers to take their employees for granted. During my bachelor time, I was constantly bothered by my manager to work at weekends for free. When questioned “<em>Why</em>” he would say</p><blockquote>“You are a Bachelor, what better things would you do over weekends ?”</blockquote><p>Saying NO has also impacted my performance appraisals.<br>As moronic and Ironical this statement sounds, this is a harsh reality in India mostly, in service-based companies.</p><p>In Indian society, there is a vertical hierarchy. The person with a heavier designation often has some level of dominance. You too would have encountered these <a href="https://www.focus.business/the-10-bad-hippos/">HiPPOs</a>.</p><p>To back my feeling, I researched a bit and came across <a href="https://en.wikipedia.org/wiki/Hofstede%27s_cultural_dimensions_theory">Hofstede’s cultural dimensions theory</a>.</p><p>One of the dimensions from his theory is called the <strong>Power Distance Index(PDI)</strong>. It means <strong><em>the extent to which less powerful members of organizations accept and expect that power is distributed unequally.</em></strong></p><p>India scores 77 in PDI as compared to Sweden 31. This less score implies that more people in that country feel that the power is distributed equally.</p><h3>Work-life balance</h3><p>People emphasize work-life balance in Sweden.</p><p>Knowing when to stop working is one of the things I am still learning from Swedes. <br>Swedes prioritise personal time as much as they prioritise work. Your manager would not ask you weird favours of working on weekends or odd timings for free. People do spend more time only when the job demands it.</p><p>While talking with my colleagues here, I learned that people give greater importance to their hobbies. <br>Retrospectively, I always felt that I didn’t have enough time for my hobbies, but in reality, I always had time for my hobbies but I never prioritized my hobbies over my work. This might be because, for me, the definition of success was to win by competing with others and outperforming everyone.</p><p>This closely relates to Hofstede’s dimension of <strong>Masculinity(MAS). </strong>It<strong> </strong>is defined as <strong><em>“a preference in society for achievement, heroism, assertiveness and material rewards for success”. Its counterpart represents “a preference for cooperation, modesty, caring for the weak and quality of life”.</em></strong></p><p>📊 India scores 56 in MAS where Sweden scores 5.</p><blockquote>Masculinity is extremely low in Nordic countries: Norway scores 8 and Sweden only 5. In contrast, Masculinity is very high in Japan (95), and in European countries like Hungary, Austria and Switzerland influenced by <a href="https://en.wikipedia.org/wiki/German_culture">German culture</a>. In the Anglo world, masculinity scores are relatively high with 66 for the United Kingdom for example. Latin American countries present contrasting scores: for example, Venezuela has a 73-point score whereas Chile’s is only 28. — Wikipedia</blockquote><h3><strong>Individualism</strong></h3><p>I felt Swedes are a bit more reserved than Indians. Indian colleagues open up among their peers pretty quick. It is very common in India that someone would lend you a helping hand even before you asked for help 🤗</p><p>It is also very common that your colleagues would wait for you to finish your work so that you can have your lunch together. It is a cultural thing where we find it rude not to do so. <br>This is not common in Sweden and It takes a long time to develop such good personal relationships with your peers.</p><p>My observation can be measured with the dimension of Individualism(IDV)</p><blockquote>IDV: This index explores the “degree to which people in a society are integrated into groups”. <br>Individualistic societies have loose ties that often only relate an individual to his/her immediate family. They emphasize the “I” versus the “we”. Its counterpart, collectivism, describes a society in which tightly-integrated relationships tie extended families and others into <a href="https://en.wikipedia.org/wiki/Ingroups_and_outgroups">in-groups</a>. These in-groups are laced with undoubted loyalty and support each other when a conflict arises with another in-group.</blockquote><p>India scores 48 📉 whereas Sweden scores 71 📈</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HQxgZMOAehQAwHBovaRKuQ.png" /><figcaption>Hofstede’s dimensions</figcaption></figure><h3>Salary hikes</h3><p>This is another aspect which might be completely different in both the countries. In Sweden, salaries are pretty much standard. There might not be a substantial difference in salaries even when you switch companies.</p><p>In India, especially in Bangalore, I would not be surprised if someone gets a 100 –150 % hike in a job switch 😆</p><h3>And … Fika!!!</h3><p>A widely practised culture in Sweden where people come together for a cup of Coffee and Cinnamon buns and have a good time. It usually happens at mid-afternoon at my office and It is often considered rude not to join Fika. I love Coffee and I love Fika ❤️</p><p>In India too, people come together for a quick snack and coffee and have a good time. They just don’t call it Fika 😄</p><p><em>Again, these are my opinions and I have no intentions to offend anyone 🙂<br>I hope this would give people a fair idea of what to expect if he/she is considering Sweden for work.</em></p><h4>References:</h4><ul><li><a href="https://en.wikipedia.org/wiki/Hofstede%27s_cultural_dimensions_theory">https://en.wikipedia.org/wiki/Hofstede%27s_cultural_dimensions_theory</a></li><li><a href="https://www.hofstede-insights.com/product/compare-countries/">https://www.hofstede-insights.com/product/compare-countries/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f73c73cdc413" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Design pattern in Golang — Prototype]]></title>
            <link>https://devcharmander.medium.com/design-pattern-in-golang-prototype-e864522e4eeb?source=rss-7742f0c6a317------2</link>
            <guid isPermaLink="false">https://medium.com/p/e864522e4eeb</guid>
            <category><![CDATA[golang-design-patterns]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[software-design-patterns]]></category>
            <category><![CDATA[prototype-pattern]]></category>
            <dc:creator><![CDATA[Surya Reddy]]></dc:creator>
            <pubDate>Thu, 12 Aug 2021 12:19:01 GMT</pubDate>
            <atom:updated>2021-08-13T07:13:23.146Z</atom:updated>
            <content:encoded><![CDATA[<h3>Design pattern in Golang — Prototype</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8l7hJ1i_OyqgF6nvLEdn2A.jpeg" /></figure><p>In a real-life scenario, a complex object (e.g. Car, Phone) is not created from scratch. We use the existing design and modify it.</p><p>The prototype pattern follows the same principle.</p><blockquote>An existing (partially or fully completed) design is a prototype.</blockquote><p>To implement the Prototype pattern we need to know <strong><em>Deep Copying</em></strong>.</p><h4>What is Deep Copying?</h4><p>It&#39;s a fancy term to copy data from one object to another.</p><h4>Why is it fancy?</h4><p>Because there is a catch!<br>If an object has a property that is a reference (pointer) to another object. We cannot just perform a direct copy.</p><p>Let&#39;s take a look at this example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fmKf5xYC3pRW4oyfXjH3Fw.png" /></figure><ul><li>Since Name is a passed as a value type, it is copied successfully.</li><li>The address is a reference type so even when we create a new employee2 we still are referencing the same Address instance of employee1 . (see the output)</li></ul><p>We can achieve Deep Copying in 2 ways, As we go through these 2 approaches, you would realise that deep copying through serialization (approach 2) makes more sense (<em>Sorry for the spoilers</em>)</p><h4>Approach 1 — Copy function</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9315cfce7566750527c84a5d01c3a6f5/href">https://medium.com/media/9315cfce7566750527c84a5d01c3a6f5/href</a></iframe><p>The code is self-explanatory, we created a DeepCopy() ( 15–20) as part of Address and performed a deep copy on Address .</p><p>If we run this code, we see correct results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9lD6qe3vlNnNUM3M5E4lpw.png" /></figure><p>Approach 2 — Copy through serialization</p><p>The downside of <em>approach 1 </em>is, for every new reference type property, we need to create a Copy function. Imagine extending Employee with a new reference type property called Contract !<br>We need to write a new Copy() for Contract so that the contract object can be deep copied.</p><p>Now, you can already imagine why Copy through serialization is better.<br>When you serialize an object and deserialize it into another object, all the new references are initialized properly without the developer writing too much code.</p><p>Let us see this example.</p><p>Imagine a scenario where you need to create Person objects working in the same company. The Person struct has 2 reference type properties WorkAddress and HomeAddress. Instead of creating 2 clone() functions (like approach 1), we create a DeepCopy() through serialization, that can clone one object into another.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/afc42b7998be9420fa7d4bcf6feddcbb/href">https://medium.com/media/afc42b7998be9420fa7d4bcf6feddcbb/href</a></iframe><p>So, in the code above, line 27-34 we used binary serialization to encode an object and create a copy/clone (line55).</p><p><strong><em>Note</em></strong><em>: It doesn’t matter what type of serialization you are using to apply this pattern.</em></p><p>In conclusion, we learned that the Prototype Pattern is achieved with deep copying. <br>The approaches discussed here are not written in stone. Let me know if you have a better approach to implement deep copying!</p><blockquote>A good software developer doesn’t try to fit his/her code into a specific design pattern. He/She adheres to SOLID principles.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e864522e4eeb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Design Patterns in Golang- Factory]]></title>
            <link>https://devcharmander.medium.com/design-patterns-in-golang-factory-6164c4e0b43f?source=rss-7742f0c6a317------2</link>
            <guid isPermaLink="false">https://medium.com/p/6164c4e0b43f</guid>
            <category><![CDATA[factory-pattern]]></category>
            <category><![CDATA[golang-design-patterns]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[software-design-patterns]]></category>
            <dc:creator><![CDATA[Surya Reddy]]></dc:creator>
            <pubDate>Thu, 12 Aug 2021 07:18:59 GMT</pubDate>
            <atom:updated>2021-08-12T07:59:35.489Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://devcharmander.medium.com/design-patterns-in-golang-the-builder-dac468a71194">In our previous blog</a>, we learned that in the <em>Builder pattern</em>, we create an object (struct instance) piece by piece.</p><p>As a developer, you get into situations where you want to create the whole object at once. In these situations, you can apply the <em>Factory pattern</em>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FfwfbJvRNHb5sI%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FfwfbJvRNHb5sI%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FfwfbJvRNHb5sI%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3363eadf6bc0a5ba44c4975bdf37fa8/href">https://medium.com/media/e3363eadf6bc0a5ba44c4975bdf37fa8/href</a></iframe><blockquote>“ Factory pattern is a software design pattern where we create the whole instance at once”</blockquote><h4>When to use this?</h4><p>It is used when the creation of an object becomes complex.</p><h4>What do you mean by “complex”?</h4><ul><li>When an object has a lot of properties to be filled properly.</li><li>Scenarios where a lot of properties carry default value.</li></ul><h4>How can we implement a Factory pattern?</h4><p>There are 4 ways to implement a Factory pattern.</p><ul><li>Factory function</li><li>Interface Factory</li><li>Factory Generator</li><li>Prototype Factory</li></ul><h4>Factory Function</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9829792763ee0cb2fe71dd5f7af6a2cb/href">https://medium.com/media/9829792763ee0cb2fe71dd5f7af6a2cb/href</a></iframe><p>From this example, it is clear that the “factory function” is a constructor.</p><p><strong>Quick explanation:</strong><br>Since we would be creating Person objects for “girls hostel” it is better to create a factory function NewGirl() which can create person objects with pre-populated gender value.</p><h4>Interface Factory</h4><p>Instead of returning an object (instance of a struct), we can return an interface that complies with the object.<br>This is really familiar to us in our day to day work.</p><p>See this example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/03c168f527b1703f90e20b6b9d738037/href">https://medium.com/media/03c168f527b1703f90e20b6b9d738037/href</a></iframe><ul><li>Imagine a scenario where we need to create an interest calculator</li><li>Based on the “type” we create a calculator instance with different underlying behaviour.</li><li>In the above example, based on the type, the NewCalculator() factory function returns a simpleInterest or compoundInterest instance and their underlying logic changes in their respective Calculate() function.</li></ul><h4>Factory Generator</h4><p>As the name suggests this is used to generate “<em>factories</em>”.<br>For example, we want to create factories for employees based on roles.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/62fe088eff0b07f7620632bdbe5f2ea2/href">https://medium.com/media/62fe088eff0b07f7620632bdbe5f2ea2/href</a></iframe><p>In functional approach line 12-29 :</p><ul><li>We create separate factories based on roles and then we can create instances using those factories. ( <em>“churning out developers from </em><em>developerFactory”</em>)</li><li>Notice that the factory itself is of the type func so that it can be passed to other functions, which is essentially the base of functional programming.</li><li>Since the factory is type func , it can be consumed easily by other functions.</li><li>In this approach is that the factory itself cannot mutate an object. e.g. developerFactory.AnnualSalary = 100 is illegal.</li></ul><p>In structural approach 31-50 :</p><ul><li>We create a separate factory struct EmployeeFactory .</li><li>We create a constructor of EmployeeFactory .</li><li>We define a Create() as a member of EmployeeFactorythat returns an Employee object.</li><li>The Advantage of this approach is the factory can mutate the object. <br>e.g. bossFactory.AnnualIncome = 500 is legal.</li><li>Since EmployeeFactory is a special type unlike developerFactory (line:20) the end-user consuming this type should know what function/s ( Create in this case ) are exposed. This can be done using interfaces.</li></ul><p>We will discuss the Prototype Factory pattern when we dive into the Prototype pattern.</p><blockquote>In conclusion, a factory pattern is a combination of some glorified constructors who can help in the wholesale construction of an object. (Oversimplified).</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6164c4e0b43f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Go Builder Pattern —  The Functional Way]]></title>
            <link>https://devcharmander.medium.com/go-builder-pattern-the-functional-way-e40f347017ce?source=rss-7742f0c6a317------2</link>
            <guid isPermaLink="false">https://medium.com/p/e40f347017ce</guid>
            <category><![CDATA[programming-paradigms]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[functional-programming]]></category>
            <dc:creator><![CDATA[Surya Reddy]]></dc:creator>
            <pubDate>Mon, 11 Jan 2021 17:43:09 GMT</pubDate>
            <atom:updated>2021-01-11T18:00:07.126Z</atom:updated>
            <content:encoded><![CDATA[<h3>Go Builder Pattern — The Functional Way</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U_PDdmH-wHmIJSHD1MKf9w.jpeg" /></figure><p>So, in my previous blogs, we talked about Builder Facets and Builder Parameters.</p><p>Read them here:</p><ol><li><a href="https://devcharmander.medium.com/design-patterns-in-golang-the-builder-dac468a71194">Builder Facets</a></li><li><a href="https://devcharmander.medium.com/go-builder-pattern-builder-parameters-637cd3f46240">Builder Parameters</a></li></ol><p>One way to extend the builder that you already have is by using a Functional Programming approach!</p><p>Let’s take the same example that we used in my <a href="https://devcharmander.medium.com/design-patterns-in-golang-the-builder-dac468a71194">previous blog</a>.</p><p>We want to create an Employee object step by step using a functional approach, that would look something like this!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e4241c28a2f165f74cb64bffa4201025/href">https://medium.com/media/e4241c28a2f165f74cb64bffa4201025/href</a></iframe><p>To achieve a fluent API like this in “go” is really simple.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/646da2db831f3fbdbbd28c98bd87c941/href">https://medium.com/media/646da2db831f3fbdbbd28c98bd87c941/href</a></iframe><h4><strong>Explanation:</strong></h4><ol><li>We add a property to the Builder struct that takes an array of actions. (line-16)</li><li>Every builder’s member function adds an action to the above property. (line 20–41)</li><li>The Build() function iterates through all the actions and executes it on an Employee object. (line 44–50)</li></ol><h4>In Summary:</h4><p>Builder patterns are useful but sometimes can be a pain in <em>wrong</em> places. The upside is being able to create complex objects more easily with control over what properties to expose and what to hide from the end-user, but the downside is whenever a new property is added we need to create a new function to set the value.</p><p><strong>Builder Facets</strong> can be used to functionally break the builder in smaller sub-builders that can work in tandem to create a complex object.</p><p><strong>Builder Parameters</strong> can be used to have control over the properties that we want to expose to our developers.</p><p><strong>Functional</strong> way of creating builders enable us to create fluent APIs that are easy to read.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e40f347017ce" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Go Builder Pattern — Builder Parameters]]></title>
            <link>https://devcharmander.medium.com/go-builder-pattern-builder-parameters-637cd3f46240?source=rss-7742f0c6a317------2</link>
            <guid isPermaLink="false">https://medium.com/p/637cd3f46240</guid>
            <category><![CDATA[builder-pattern]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[go]]></category>
            <dc:creator><![CDATA[Surya Reddy]]></dc:creator>
            <pubDate>Mon, 11 Jan 2021 17:38:26 GMT</pubDate>
            <atom:updated>2021-01-11T18:01:27.349Z</atom:updated>
            <content:encoded><![CDATA[<h3>Go Builder Pattern — Builder Parameters</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aX8wNs_oVQ4ZZDUzowiolg.jpeg" /></figure><p>So in the previous blog, we talked about <a href="https://devcharmander.medium.com/design-patterns-in-golang-the-builder-dac468a71194">Builder facets</a>. In this blog, let&#39;s understand the Builder parameters.</p><h3>Builder Parameters</h3><h4>What?</h4><p>Builder parameters help us to restrict usage of struct properties and functions directly.</p><h4>Why?</h4><p>Sometimes we want to restrict users from accessing the properties and functions of a struct directly.<br>We provide them with our APIs instead.</p><h4>Show me the code!</h4><p>Sure!</p><p>Imagine, we have to create a new feature which can send emails, and you don’t want your developers to start messing with your email object. You hide it with Builder parameters.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/11f8cad11e5a64b72404bf14a5586c6c/href">https://medium.com/media/11f8cad11e5a64b72404bf14a5586c6c/href</a></iframe><p>We see that we have a utility function SendEmail that takes a func (action) as a parameter and executes some functions like To(value string), From(value string) etc.</p><blockquote>Also, notice that we don’t have access to the email struct nor the actual function that sends an email.</blockquote><p>We start with creating a private struct and a private function</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d7f5e6cc3438cf871ede5cec11e14aaa/href">https://medium.com/media/d7f5e6cc3438cf871ede5cec11e14aaa/href</a></iframe><p>Now we define our builder struct and utility function</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/33c3a28fbec088792564ed7588038000/href">https://medium.com/media/33c3a28fbec088792564ed7588038000/href</a></iframe><p>and finally, we define our member functions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b90e2b40dae030f3a1de05da41e5b43/href">https://medium.com/media/6b90e2b40dae030f3a1de05da41e5b43/href</a></iframe><p>Putting it all together!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d754a0fdc3443cba3237a21170d70df5/href">https://medium.com/media/d754a0fdc3443cba3237a21170d70df5/href</a></iframe><h4>Explanation</h4><p>When SendEmail() is invoked, a builder object is created(line-29) and that object’s reference is passed to an action(line-69). All the member functions of the builder are executed(71–74) and a private sendEmail() (line-31) is called at the end.</p><blockquote>Notice that there are implicit validations in place for email ids (37 and 48).</blockquote><p>The user can use this API without bothering about the implementation and validation logic to create a complex object.</p><h4>Next:</h4><p>Functional Builders: <a href="https://medium.com/@devcharmander/go-builder-pattern-the-functional-way-e40f347017ce">https://medium.com/@devcharmander/go-builder-pattern-the-functional-way-e40f347017ce</a></p><h4>Previous:</h4><p>Builder Facets: <a href="https://devcharmander.medium.com/design-patterns-in-golang-the-builder-dac468a71194">https://devcharmander.medium.com/design-patterns-in-golang-the-builder-dac468a71194</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=637cd3f46240" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Design patterns in Golang — The Builder]]></title>
            <link>https://devcharmander.medium.com/design-patterns-in-golang-the-builder-dac468a71194?source=rss-7742f0c6a317------2</link>
            <guid isPermaLink="false">https://medium.com/p/dac468a71194</guid>
            <category><![CDATA[go]]></category>
            <category><![CDATA[programming-paradigms]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Surya Reddy]]></dc:creator>
            <pubDate>Mon, 11 Jan 2021 17:26:17 GMT</pubDate>
            <atom:updated>2022-05-09T09:14:07.562Z</atom:updated>
            <content:encoded><![CDATA[<h3>Design patterns in Golang — The Builder</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3LJm0IAOHv7fOJuzdDEqFw.png" /></figure><p>I always wondered, <em>how should we apply our very dear “Design Patterns” in Golang?</em></p><p>Object-Oriented Programming in Go is weird. If you are a Java or a C# developer, you would find a lot of similarities in applying SOLID principles in your code. But Go is special and special for a reason.</p><p>We would be taking a closer look at how we can implement some famous design patterns in Go.</p><h3>Builder pattern</h3><p>The motivation behind the Builder pattern is to create a complex object piece-by-piece. Our goal in this blog is to provide APIs to create complex objects step-by-step.</p><h4>Why?</h4><p>Some objects are easy to create with a simple constructor while others need a lot of ceremonies.</p><h4>When do we need this?</h4><p>When you don’t need your end-user to provide millions of details in parameters of a constructor and you want to make his/her life easy by providing them with a simple way to create a complex object.</p><h4>How?</h4><ol><li>Builder facets</li><li><a href="https://medium.com/@devcharmander/go-builder-pattern-builder-parameters-637cd3f46240">Builder parameters</a></li><li><a href="https://medium.com/@devcharmander/go-builder-pattern-the-functional-way-e40f347017ce">Functional builders</a></li></ol><h3>Builder facets</h3><h4>What?</h4><p>They are more than one builder working in tandem to create an object.</p><h4>Why?</h4><p>Sometimes, our object is complex and the creational process requires more than one builder class. Segregating the builder into multiple builders also gives us control over the properties of a struct that a user can use.</p><h4>Show me the code!</h4><p>Ok!</p><p>Suppose we want to create a fluent API that builds a person object like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ef42965446013ee9325a6f4faf7ad87/href">https://medium.com/media/4ef42965446013ee9325a6f4faf7ad87/href</a></iframe><p>We start with creating a Person struct and 3 builders PersonBuilder PersonAddressBuilder and PersonJobBuilder</p><blockquote>Notice that thePersonAddressBuilder and PersonJobBuilder refer to PersonBuilder</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5952812721394644e685daea645a2634/href">https://medium.com/media/5952812721394644e685daea645a2634/href</a></iframe><p>Next, we would declare the constructors for these builders.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26c2492d3ad31606f6202c84d01ca46c/href">https://medium.com/media/26c2492d3ad31606f6202c84d01ca46c/href</a></iframe><blockquote>Notice how Lives() and Works() refer to PersonBuilder while initalization</blockquote><h4>Now, why this is important?</h4><p>This would enable us to set properties of Person which is part of PersonBuilder</p><h4>Ok, how would we set properties now?</h4><p><em>Glad you asked!</em><br>We would create some behaviours/functions/methods for PersonAddressBuilder and PersonJobBuilder that sets the properties of thePerson</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c8b8bcbb00d7a7806b90becc7f2444f/href">https://medium.com/media/9c8b8bcbb00d7a7806b90becc7f2444f/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/76a4fba366a08661cca3e5433a3a247d/href">https://medium.com/media/76a4fba366a08661cca3e5433a3a247d/href</a></iframe><p>and finally, a “Build” method that returns a Person object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/934010c8d371df7daddf6aa6eb2f15ac/href">https://medium.com/media/934010c8d371df7daddf6aa6eb2f15ac/href</a></iframe><p>So, putting it all together!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8f20a69a4945ac29ee9a6fcb745dc07/href">https://medium.com/media/b8f20a69a4945ac29ee9a6fcb745dc07/href</a></iframe><h4>Explanation</h4><p>Once an object of PersonBuilder is created we switch to Lives() that returns a PersonAddressBuilder which have member functions like At() and WithPostalCode() , since we are returning pointers in all the function definitions we can chain our function calls together (line 91–97)</p><p>This way we can jump between different builders and use their corresponding member functions to create a complex object.</p><p>The result (<em>trivial</em>) looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*So2qIUuM_ezQ28tzp2o07A.png" /></figure><h4>Next:</h4><p>Builder Parameters: <a href="https://devcharmander.medium.com/go-builder-pattern-builder-parameters-637cd3f46240">https://devcharmander.medium.com/go-builder-pattern-builder-parameters-637cd3f46240</a></p><p>Functional Builders: <a href="https://medium.com/@devcharmander/go-builder-pattern-the-functional-way-e40f347017ce">https://medium.com/@devcharmander/go-builder-pattern-the-functional-way-e40f347017ce</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dac468a71194" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>