<?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 Yasser Sinjab on Medium]]></title>
        <description><![CDATA[Stories by Yasser Sinjab on Medium]]></description>
        <link>https://medium.com/@ysinjab?source=rss-e8965733316c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Yasser Sinjab on Medium</title>
            <link>https://medium.com/@ysinjab?source=rss-e8965733316c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 16:27:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ysinjab/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[The beauty of concurrent programming in Go]]></title>
            <link>https://ysinjab.medium.com/the-beauty-of-concurrent-programming-in-go-d338c73418f2?source=rss-e8965733316c------2</link>
            <guid isPermaLink="false">https://medium.com/p/d338c73418f2</guid>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[concurrency]]></category>
            <category><![CDATA[go]]></category>
            <dc:creator><![CDATA[Yasser Sinjab]]></dc:creator>
            <pubDate>Thu, 15 Oct 2020 08:55:56 GMT</pubDate>
            <atom:updated>2020-10-15T08:55:56.441Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TwYcllYs3HR6cXISJ2s2dw.png" /></figure><blockquote>“Time is nature’s way of keeping everything from happening at once.”</blockquote><p>Any code you write will run sequentially on single machine. But let’s think more: can we do more than one task at a single point of time? I mean <strong>(concurrently). </strong>The answer is: yes.</p><p>Firstly let’s discuss why we need concurrency. There are many reasons but the main two are:</p><ul><li><strong>Performance</strong>: fast processes won’t be delayed or wait for slower components to do their jobs. The will focus on their tasks.</li><li><strong>Simplicity: </strong>Big tasks will be broken into small tasks where they can work in more efficient way, tested individually and fixed separately.</li></ul><p>So why some processes usually wait for each other? and why some of them are slow and others are fast?</p><p>Usually for one of two reasons: either the process is <strong>I/O bound: </strong>it is waiting for network or disk access, or it is <strong>CPU bound</strong>: where it is a number crunching process and doing a lot of calculation.</p><p>Go models concurrency as primitives in the language itself. But before we dive into concurrency patterns and those primitives let me answer: why concurrency is so hard?</p><ul><li><a href="https://stackoverflow.com/questions/34510/what-is-a-race-condition">Race condition</a></li><li><a href="https://en.wikipedia.org/wiki/Linearizability">Atomicity</a></li><li><a href="https://en.wikipedia.org/wiki/Synchronization_(computer_science)">Syncronization</a></li><li><a href="https://en.wikipedia.org/wiki/Deadlock">Deadlocks / Livelock</a></li></ul><h3>Go concurrency primitives</h3><h4><strong>Goroutines</strong></h4><p>Every go program has at least one goroutine: the main goroutine (it is automatically created when you run the process). Andother goroutines that can run concurrently to another part of the code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/45393a2c397994c3fc85421babea9d07/href">https://medium.com/media/45393a2c397994c3fc85421babea9d07/href</a></iframe><p>Note that goroutines are not OS threads. Read <a href="https://golang.org/doc/faq#goroutines">why goroutines instead of threads?</a></p><h4>The sync package</h4><p>This includes :</p><ul><li>waitgroup: To wait for multiple goroutines to finish, we can use a <em>wait group</em>. <a href="https://gobyexample.com/waitgroups">See example</a></li><li>Mutex: to safely access data across multiple goroutines. <a href="https://gobyexample.com/mutexes">See example</a></li><li>Cond: Cond implements a condition variable, a rendezvous point or goroutines waiting for or announcing the occurrence of an event (any arbitrary signal between two or more goroutines that carries no information other than the fact that it has occurred.)</li><li>Once: <a href="https://golang.org/pkg/sync/#example_Once">See example</a></li><li>Pool: <a href="https://golang.org/pkg/sync/#example_Pool">See example</a></li></ul><h4><strong>Channels</strong></h4><p>Channels are best used to communicate information between goroutines. It is a stream of information, like a river.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bfd7c150d398fefc3b46288e3d5d7127/href">https://medium.com/media/bfd7c150d398fefc3b46288e3d5d7127/href</a></iframe><h4>Select statement</h4><p>select is the glue that binds multiple channels together. select statements can help safely bring channels together with concepts like cancellations, timeouts, waiting, and default values. Please read <a href="https://gobyexample.com/select">select example</a> to know more about it.</p><h3><strong>Concurrency patterns in Go</strong></h3><p>Some of the popular patterns are:</p><h4>The for-select Loop</h4><p>This pattern is nothing more than something like this:</p><pre>for { // Either loop infinitely or range over something<br>    select {<br>        // Do some work with channels<br>        }<br>}</pre><p>Here is an example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f56bbf0516b3f8f828045081d8419606/href">https://medium.com/media/f56bbf0516b3f8f828045081d8419606/href</a></iframe><h4>Fan-In &amp; Fan-Out</h4><p>Usually this pattern is used when you have a pipeline that handle stream of data, but at one point of time one of the stages in the pipeline start becoming computationally expensive and taking long time to process. This impact the whole pipeline performance. What if we can run multiple goroutines that pull data from stream and attempt to parallelize the work on them?</p><p>This is what this pattern solve. Fan-out is the process of starting multiple goroutines to handle stream of data from the pipeline, and fan-in is the process of combining multiple results into one channel.</p><p>In the following example I wrote fibonacci number calculator which is expensive for some numbers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/44001aca24e18b7da02fec8834818a80/href">https://medium.com/media/44001aca24e18b7da02fec8834818a80/href</a></iframe><p>Hope this will help reader on how to write some beautiful code that can handle concurrency problems in an easy way. In next posts I will try to explore more patterns and share it with the community.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d338c73418f2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Leading a team is an opportunity: seize it]]></title>
            <link>https://ysinjab.medium.com/leading-a-team-is-an-opportunity-dont-miss-it-87e09a839043?source=rss-e8965733316c------2</link>
            <guid isPermaLink="false">https://medium.com/p/87e09a839043</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[team-building]]></category>
            <category><![CDATA[teamwork]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Yasser Sinjab]]></dc:creator>
            <pubDate>Sat, 30 May 2020 16:36:15 GMT</pubDate>
            <atom:updated>2020-06-10T06:32:41.714Z</atom:updated>
            <content:encoded><![CDATA[<p>One day I has to make a decision: either accepting a job offer to work ina field I always loved or to accept more responsibilities and lead a team of 6 developers. <em>“I saw how you could empower that intern and get the best out of him. I want you to do the same with the rest.”</em> That what my manager has told me when he negotiated me staying at the company with him to achieve the vision. Eventually I rejected the offer and I decided to stay. But why? I will share in this story the reasons.</p><p>Firstly, work has many types: solo, working in mid size team, and working in large size team. To me: I like all of them. For others, maybe they like to be solo developers. Every one of those types has positives and negatives:</p><ul><li><strong>Solo</strong>: I enjoy working solo in my side projects as I love to take my time experimenting, learning new things, and making mistakes. There is no pressure to deliver. I work at my own pace. I choose the technology and what programming language to use etc. It is good for nighty development with some background music or TV series.</li><li><strong>Mid-size teams</strong>: I would say midsize teams has between 2 to 4 members. Usually in mid-size teams everyone have multiple roles. I worked in projects where I was backend and mobile developer at the same time. I like the efficiency and delivery in such teams because I feel like I am in a SWAT team.</li><li><strong>Large-size teams</strong>: Velocity here is high. Tasks have a lot of dependencies. Other team members are waiting for you to deliver so they can start and this is so stressful. But let me tell you something: I love this stress as it makes me sharp to deliver stories with high quality. In large size teams the long hours of technical/business discussions give me the opportunity to learn from others and share my feedback with them. So I learn a lot in a very short time working in such teams.</li></ul><p><strong>Reasons why you should at least try team leadership</strong></p><ul><li><strong>Enjoy the ambiguity: </strong>Ambiguous problems will increase significantly when team members start sharing it with you. Those problems have no <strong><em>silver bullet</em></strong><em> </em>solutions. There is only the <strong><em>best answer</em></strong><em> </em>for the moment. Solving those problems in this case requires identifying the trade-offs and balancing them, which means more discussion with the team. Problems usually come from one developer but I prefer usually to invite others to join us in those discussions just for knowledge sharing and thinking out loud with them.</li><li><strong>You will learn how to build a self-driving team:</strong> Being a successful leader means building an organization that is able to solve the difficult problem by itself. This is more <strong>“people management”</strong> skill than being the technical wizard.</li><li><strong>You will learn how to delegate: </strong>Delegation is one of those skills you need to master in order to build a self-driving team. It is difficult to learn. I made so many mistakes: delegation to someone who is full of tasks, delegate to myself where some others have nothing to do. Think about delegation as you are sharing your plate with others. Being too generous will <strong>overload</strong> the team, increase <strong>stress</strong>, and the team will <strong>not be productive</strong>. Keep the tasks for yourself you will become a <strong>single point of failure</strong>, <strong>stressing</strong> yourself, and there will be <strong>no self-driving team</strong> as nobody is learning. You need to think about it as this plate is for everyone. You have a piece of it, other team members<strong><em>“deserve”</em></strong> to have a piece from it because they are <strong>leaders</strong> and they <strong><em>“deserve”</em></strong> to learn and grow.</li><li><strong>You will learn how to protect your team</strong>: Sometimes you will get into organizational politics, which may hurt the harmony of the team. Your responsibility is to protect them from any kind of hits.</li></ul><p>Leading a team is not always available. I sacrificed working on a field I like over growing my leadership skills. As a programmer I admit at the beginning it was so difficult as we love to work peacefully on our own tasks. But seeing the whole achievement of the team should be a reward as much as you fixed a bug.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87e09a839043" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Name mangling in Python]]></title>
            <link>https://ysinjab.medium.com/name-mangling-in-python-917bdef77c80?source=rss-e8965733316c------2</link>
            <guid isPermaLink="false">https://medium.com/p/917bdef77c80</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Yasser Sinjab]]></dc:creator>
            <pubDate>Thu, 20 Jun 2019 09:38:32 GMT</pubDate>
            <atom:updated>2019-06-20T09:38:32.035Z</atom:updated>
            <content:encoded><![CDATA[<p>I was reading about why it is better to avoid using two leading underscores to create a private attribute in Python class. Then I found that Python use what is called “Name mangling” Well what was interesting is it is a compiler feature. Let’s read its definition in <a href="https://en.wikipedia.org/wiki/Name_mangling#Python">wikipedia</a>:</p><blockquote>In <a href="https://en.wikipedia.org/wiki/Compiler">compiler</a> construction, <strong>name mangling</strong> (also called <strong>name decoration</strong>) is a technique used to solve various problems caused by the need to resolve unique names for programming entities in many modern <a href="https://en.wikipedia.org/wiki/Programming_language">programming languages</a>.</blockquote><p>Programming entities could be any class, function, or any other datatypes.</p><h4><strong>Private and protected attributes in Python:</strong></h4><p>For many programmers who is coming from static language background: the first thing we are gonna look for in Python is: where are the access modifiers? :D</p><p>Well first Python is dynamic language, they handle stuff a little bit differently. Let’s take an example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/224c71614624f3fce09163f4abddf566/href">https://medium.com/media/224c71614624f3fce09163f4abddf566/href</a></iframe><p>The point here is : if your concern is name clashes, use explicit name mangling instead of automatic name mangling (like: call it __The_Customer_first_name). Or use the underscore protected attribute and developers should respect the privacy of your attributes as they respect the CONSTANT_VARIABLE.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=917bdef77c80" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Events driven systems: takeaway nuggets for developers (Part 1)]]></title>
            <link>https://ysinjab.medium.com/events-driven-systems-takeaway-nuggets-for-developers-part-1-28f7bdd761b7?source=rss-e8965733316c------2</link>
            <guid isPermaLink="false">https://medium.com/p/28f7bdd761b7</guid>
            <category><![CDATA[system-architecture]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[event-driven-systems]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Yasser Sinjab]]></dc:creator>
            <pubDate>Mon, 27 May 2019 02:31:06 GMT</pubDate>
            <atom:updated>2019-06-11T17:56:30.859Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve been working on events driven system for almost 2 years. Within this time I learned many of the concepts, patterns, and practices for designing events driven architecture. In this story I will share very simple points that will help you understanding this architecture.</p><p><strong>1#</strong> <strong>The world is asynchronous:</strong></p><p>This is what happens when you go to Starbucks:</p><ul><li>You order -&gt;</li><li>The cashier dispatch your order by writing your name and drink on the cup -&gt;</li><li>While barista is preparing your drink you are doing the payment -&gt;</li><li>Now your drink is ready or you are going to wait for few minutes until it is ready</li></ul><p>Notice here that it may be fine for this process to be synchronous if everybody drinks Black coffee as it takes almost 5 seconds preparation: just pour a coffee in the cup. But Frappuccino takes an effort and time to be prepared and the process is going to be so slow.</p><p>Some systems has many independent services that collaborate with each other. As the number of services grows gradually, the web of synchronous interactions grows with them and issues (like <a href="https://en.wikipedia.org/wiki/Cascading_failure">Cascading failures</a>) might appear due to high load and services outages.</p><p>One of the solutions is to make sure SLA of any service is more than the SLA of the whole system. Other solution is to break down that synchronous call into multiple asynchronous calls through a message broker.</p><p><strong>#2 Service interaction through three way: <em>command</em>, <em>event</em>, and <em>query</em>:</strong></p><ul><li><strong>Command</strong> is any<strong> synchronous</strong> operation: in the Starbucks example above it is processing the payment. In command a <strong>response </strong>not always required.</li><li>Query: a request for data. Queries don’t change state but we always expect a <strong>response.</strong></li><li><strong>Event</strong>: events are used either for: <strong>transfer data</strong>, or <strong>notifications. </strong>Usually called “fire and forget” because <strong>we don’t expect a response. </strong>In Starbucks example above an event is when the cashier put the cup with your name in the queue.</li></ul><p>This categorize systems into two categories:</p><ul><li><strong>Request-driven systems:</strong> tightly couples services because functionalities are placed inside services.</li><li><strong>Events-driven systems: </strong>as data generated and moves between services the change happens at the end of any subscriber who is interested in this event.</li></ul><p><strong>3# No single service owns the whole process:</strong></p><p>Each service owns a small part, and these plug together through a chain of events. So each service does its work, then raises an event denoting what it did.</p><p>No service know the existence of any other service. This has an advantage. The service can change without affecting the whole process as long as you it generates the same event. For example, in the Starbucks example: the cashier (payment service) knows only that he should react to orders and create payment processed events and put the cup in the queue. If you pay by credit or cash, the generated event is the same.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28f7bdd761b7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I enjoy learning from my mistakes]]></title>
            <link>https://ysinjab.medium.com/i-enjoy-learning-from-my-mistakes-1091093ab494?source=rss-e8965733316c------2</link>
            <guid isPermaLink="false">https://medium.com/p/1091093ab494</guid>
            <category><![CDATA[self-improvement]]></category>
            <category><![CDATA[mistakes]]></category>
            <category><![CDATA[life-lessons]]></category>
            <dc:creator><![CDATA[Yasser Sinjab]]></dc:creator>
            <pubDate>Tue, 12 Feb 2019 18:50:50 GMT</pubDate>
            <atom:updated>2019-02-12T19:00:31.311Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>“Failure is instructive. The person who really thinks learns quite as much from his failures as from his successes.”</strong> <br>― <strong>John Dewey</strong></p><p>Growing up we were taught that mistakes must be avoided. Because of that we are scared of making any mistakes in our life, work, relationships etc.</p><p>Yes, we should avoid them, but.. come on we are humans!. Why giving a sh*t about them and stressing out if we accidentally made them. Actually this negativity what must be avoided, and be replaced with embracing our mistakes.</p><p>I always thought that admitting mistakes to myself or to other people is one my strongest skill that I taught myself hardly through the years. But what after that? feeling guilty? yes. anger at myself? yes. So admission still half the way through full embrace. <strong><em>Until</em></strong> I got extremely satisfied once I made one mistake that was so stupid. Seriously? How come? because I learned from it and that was the <strong>reward</strong>.</p><p><strong>Mistakes</strong> are learning resource. With <strong>learning</strong> comes growth. <strong>Growth</strong> expands your knowledge. Great <strong>knowledge</strong> is one key to <strong>wisdom</strong>. And here is one quote that I love about wisdom:</p><blockquote>“Knowledge comes, but wisdom lingers.” — Alfred Lord Tennyson</blockquote><p>Behind every mistake is a significant meaning. Go out and fail at something; make irrational decision; with every mistake a new lesson comes. But keep in mind: Making mistakes is okay, just not the same ones over and over again.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1091093ab494" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I started a job hunt board in Trello]]></title>
            <link>https://ysinjab.medium.com/i-started-a-job-hunt-board-in-trello-4d8bdb1288b9?source=rss-e8965733316c------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d8bdb1288b9</guid>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[augmented-reality]]></category>
            <category><![CDATA[self-improvement]]></category>
            <category><![CDATA[jobs]]></category>
            <category><![CDATA[job-hunting]]></category>
            <dc:creator><![CDATA[Yasser Sinjab]]></dc:creator>
            <pubDate>Tue, 29 Jan 2019 05:39:05 GMT</pubDate>
            <atom:updated>2019-01-29T06:34:27.446Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>“Every cloud has a silver lining”.</strong></p><p>I submitted my CV to a company that is building an AI-related product, Scape Technologies. Their website, before they updated it, was not clear about the exact idea behind the product. What I firstly got from it was what they are building is an augmented reality platform so anybody can use it and since I’m big fan of the whole idea of AR and its use in real world I got amazed and I applied. But it was more than that.</p><p>We had a call and we discussed the position. After that I went through their blog and I found that this team is going to change the world … literally ! “change the world”. Who would imagine that flying cars and drones that we used to watch in sci-fi movies could be real one day. It is not only that: they are building a virtual 3D map of every city on this earth !</p><p>Anyway, they sent me an assignment that has two questions: one about AWS CloudFormation, and one about image processing, or in one word OpenCV (The give me the freedom to choose the library but after some research OpenCV is the best). The assignment time was 1 hour and a half. Since I have no experience in none of these I prepared for few days before starting the assignment and had read some books. How much time I took to complete the assignment? <strong>7 hours, </strong>from 9pm till 4am. It is not about difficulty level: maybe It was better if I kept the perfectionism aside and stick to the time but instead I took my time to submit something at least valid and work.</p><p>They apologized after one week and decided to go with another candidate who already accepted the offer. Since I really loved their idea: I decided to create a job hunt board on <a href="https://medium.com/u/fb5dd2d116a1">Trello</a>. With simple six lists that demonstrate my upcoming plan to be at not only this company, but any company I dream to work in. We all dream to work at companies like Facebook or Google, but the question is: have we tried to match what they are asking for in jobs description? or have we tried to change any job opportunity from a dream into real?. That’s why I started this board. It will help me killing two birds, and maybe one, with one stone: Focusing on improving my skills in some technologies, and maybe got accepted. In both cases I win.</p><p>Now the keys to move one card from “Wish list companies” to “Done !” are: <strong>dedication</strong>, <strong>hard work</strong>, and <strong>determination</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wS9BVBGd_CGRDFmGBc4tbg.gif" /></figure><p>I hope my story will help you getting the job you dream about one day.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d8bdb1288b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker containers simply explained]]></title>
            <link>https://ysinjab.medium.com/docker-containers-simply-explained-ef5e5d158dcf?source=rss-e8965733316c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef5e5d158dcf</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Yasser Sinjab]]></dc:creator>
            <pubDate>Sat, 27 Oct 2018 17:45:03 GMT</pubDate>
            <atom:updated>2018-10-27T17:45:03.170Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eiU8lzUwh35_xqAIDR-bYQ.png" /></figure><p>A: What is a container?<br>B: It is like a VM. But it shares the OS kernel with other containers.<br>A: Since they or on the same OS, are they isolated?<br>B: I guess yes.<br>A: What are the mechanisms used to make them isolated?<br>B: Hmmm…. (No answer)</p><p>The answer for this question is container technology in a nutshell. Many developers start using containers without knowing how it internally works. And when you ask them: all what they know is analogy with VMs. In this story I will briefly explain how exactly containers can isolate processes if they’re running on the same operating system by using two mechanisms: Linux namespaces and Control groups.</p><h4>Linux namespaces:</h4><p>Namespaces take a single global resource and make it appear as a single owned resource to the container. Let’s take Users namespace as an example: On one of my AWS virtual machines, I listed all system users (my username is the last one ‘ysinjab’). Each container will have an isolated set of users and groups.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3025835ede43a1c6db8f5b5984e6ab7f/href">https://medium.com/media/3025835ede43a1c6db8f5b5984e6ab7f/href</a></iframe><p>Likewise, mount namespaces is used primarily to make the container as if it has its own filesystem. If you noticed in the previous gist, when we entered the container: the filesystem was rooted on “/”. But this is not the system actual root, it is the mount name spaces which made this possible for container to have its own root.</p><p>Here is a list of other namespaces used:</p><ul><li>UTS</li><li>PID (process)</li><li>IPC (inter process communication)</li><li>Network</li></ul><h4>Linux control groups (cgroups):</h4><p>cgroups is Linux kernel feature that is used to set limits on resources for processes and its children. That simply means every container (a process) is assigned to its own cgroups. The children here are those processes that are running inside that container. <br>What are the resources cgroups limit? Many including:</p><ul><li>CPU</li><li>RAM</li><li>Disk I/O</li><li>Network bandwidth</li></ul><p>If you run docker stats on one of your running containers you will see the reports that cgroups generate on resources:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a83bd851030e7ae00df93e2be6aa2c93/href">https://medium.com/media/a83bd851030e7ae00df93e2be6aa2c93/href</a></iframe><p>Hope that will help you understand how containers is built using Kernel features, and forget about the VM story when you need to explain this extraordinary technology to anyone :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef5e5d158dcf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ActiveRecord vs Datamapper in Python]]></title>
            <link>https://ysinjab.medium.com/activerecord-vs-datamapper-in-python-f7f13ffb6774?source=rss-e8965733316c------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7f13ffb6774</guid>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Yasser Sinjab]]></dc:creator>
            <pubDate>Fri, 19 Oct 2018 12:37:27 GMT</pubDate>
            <atom:updated>2019-02-04T16:19:17.699Z</atom:updated>
            <content:encoded><![CDATA[<h3>ActiveRecord vs DataMapper in Python</h3><p>Many programmers use ORM for data persistence, but also many don’t know the patterns these ORMs internally use. In this story I will show the difference between two famous data persistence patterns:</p><ul><li><a href="https://en.wikipedia.org/wiki/Active_record_pattern"><strong>Active Record</strong></a><strong>: </strong>The<strong> </strong>object in this pattern encapsulates two main things: <strong><em>data</em></strong> and <strong><em>behavior</em></strong>. Since all business logic in the domain object it is clear and obvious where to access the database. <a href="https://docs.djangoproject.com/en/2.1/topics/db/"><strong>Django ORM</strong></a><strong> </strong>is one the famous libraries that follow this approach</li><li><a href="https://en.wikipedia.org/wiki/Data_mapper_pattern"><strong>Data mapper</strong></a><strong>: </strong>a data mapper is layer that is responsible for transferring the data between a data store and in-memory objects. <a href="https://www.sqlalchemy.org/"><strong>SQLAlchemy</strong></a> follows this patterns.</li></ul><p>I will post two gists that includes clear examples of how the libraries mentioned above apply these patterns.</p><ul><li>SQLAlchemy</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4b9868383b86e3d3a8ecbfa98f57717/href">https://medium.com/media/b4b9868383b86e3d3a8ecbfa98f57717/href</a></iframe><ul><li>Django ORM:<br>I created a django project with an application called users. After I ran makemigrations and migrate for creating the tables, I applied the code in the following gist.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/31d318480b56ebe1631118e4fc9ed531/href">https://medium.com/media/31d318480b56ebe1631118e4fc9ed531/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7f13ffb6774" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Keep your Python code efficient]]></title>
            <link>https://ysinjab.medium.com/keep-your-python-code-efficient-bbe5a7943bb2?source=rss-e8965733316c------2</link>
            <guid isPermaLink="false">https://medium.com/p/bbe5a7943bb2</guid>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Yasser Sinjab]]></dc:creator>
            <pubDate>Fri, 12 Oct 2018 16:44:18 GMT</pubDate>
            <atom:updated>2018-10-26T08:18:52.131Z</atom:updated>
            <content:encoded><![CDATA[<p>High level programming languages are designed to be closer to human languages and further from machine language. They abstract us away from the direct interaction with the hardware, and Python is one of them. Computer programs are operations and bits that flows between hardware parts. If we could understand the flow and relationship between computer units and programs we can write highly efficient code with the exist of abstraction. In this article I will explain some of computer system fundamentals. Then I will give some tips for using Python data types wisely.</p><h3>Computer system architecture:</h3><p>Any computer system is made up of three main parts:</p><ul><li>Computing units ( CPU, GPU )</li><li>Memory units ( RAM, <a href="https://en.wikipedia.org/wiki/CPU_cache">CPU cache</a>, SSD, HDD)</li><li>Connections between them ( <a href="https://en.wikipedia.org/wiki/Front-side_bus">frontside bus</a>, <a href="https://en.wikipedia.org/wiki/Back-side_bus">backside bus</a> )</li></ul><p>One note I would like to mention is that <strong>CPU</strong> caches are designed to provide very fast access to data ( faster than accessing data in <strong>RAM</strong> ). Data size differs from level to level of the cache but it goes from kilobytes to megabytes. Data between CPU and its cache goes through <strong>backside bus</strong>. While data between RAM and CPU cache flows through <strong>frontside bus</strong>.</p><p>Memory units differ from each other is the speed of reading and writing data. One main factor that affect the speed is the way the data is being read: either <a href="https://en.wikipedia.org/wiki/Random_access"><strong>random</strong></a> or <a href="https://en.wikipedia.org/wiki/Sequential_access"><strong>sequential</strong></a>. This tiers of memory units is made to keep the data as close to the computing units with taking the latency of memory unit in consideration.</p><h4>Why not GPU as our main computing unit?</h4><p>Although GPU has parallel nature of executing operations: many calculations may happen simultaneously. But there is one limitation to use it as main computing unit: It is connected to memory units through another type of buses called: <strong>E</strong><a href="https://en.wikipedia.org/wiki/External_Bus_Interface"><strong>xternal bus interface</strong></a>. EBI connects peripheral devices with the CPU. One downside of EBI is that it is much slower than other buses.</p><p>This introduction is to explain that part of optimizing our code is knowing where our data is stored and how many times it is moved between various locations. Now let’s start with some tips of how to use some Python objects.</p><h3>Python data types:</h3><h4>Tuples</h4><p>Some facts about tuples:</p><ul><li>Tuples are immutable.</li><li>Tuples are cached in the Python runtime, which means there is no memory allocation request to the OS when creating a tuple.</li></ul><p>With their static nature and what is mentioned in point number 2 you can save your program a lot of time if you use it in highly scalable system or any application that analyze huge amounts of data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2afcea38de6bf228ef5d161159950df4/href">https://medium.com/media/2afcea38de6bf228ef5d161159950df4/href</a></iframe><h4>Lists</h4><p>Some facts about lists:</p><ul><li>Lists are dynamic and mutable.</li><li>When creating a list, the runtime request memory allocation from OS to allocate X size of memory.</li></ul><p>Linear search on a list has O(n) performance. So if you are planning to heavily search in any list, make sure it is sorted in advanced so this could reduce search performance to almost O(log n).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0bd4cb454700bb03bca42d2a065ed34/href">https://medium.com/media/b0bd4cb454700bb03bca42d2a065ed34/href</a></iframe><p>Since lists are dynamic and mutable, this has a cost on memory. List always keep extra memory in addition to the allocated one for increasing the performance of <strong>list.append(). </strong>If the list get bigger enough Python runtime will request more memory, but this time it will copy the whole original list and move it to the new allocated memory that has extra room. I did a small test of how append could affect time and size when the list is growing. What I found is before append reach the peak of time, the size got increase with something proportional to the number of items (e.g. the first time it increased 25 MB, the next time 50 MB, the one next is 100 MB and so on),</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1777470ef2aee6d91c039b9d1ccdfef7/href">https://medium.com/media/1777470ef2aee6d91c039b9d1ccdfef7/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*09ivKtzkUmiEOk2rYF2_NA.png" /><figcaption>Time of append and size of list with number of items in list</figcaption></figure><p>One way to workaround this issue is to pre-allocate the list.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd53593ff9690f9ac19664c1d2e3898a/href">https://medium.com/media/fd53593ff9690f9ac19664c1d2e3898a/href</a></iframe><h4>Dictionaries</h4><p>Some facts about dictionaries</p><ul><li>Dictionary is a collection of key-value pairs. The key must be a <a href="https://docs.python.org/3/glossary.html#term-hashable">hashable</a> object.</li><li>The complexity of insertions is similar to the previous types: O(1). But it is also dependent on the hashing function used. If it is slow to computer that will affect the performance. Comments in <a href="https://github.com/python/cpython/blob/master/Objects/dictobject.c">dictobject</a> C implementation has more details on this.</li></ul><p><strong>How dictionary is structured internally?</strong></p><p>Dictionary holds a hash table inside. This table is sparse. Python keeps at least 1/3 of the table empty. If it grows, the table will be resized and the whole content will be copied to another place where there is more room for extra items. Each item in this table contains two elements: the hash of the key and the reference to the value. Now what happens when looking up item by key is the following:</p><ul><li>Hash is calculated for the key.</li><li>Few bits are taken from the search hash and search starts. If the no hash is matched is found KeyError is thrown. If there is a match: search_key and found_key will be compared: if the they are not equal, a <strong>hash collision </strong>happens.</li><li>How python resolves hash collision? Another search starts again but with different fraction of bits until the keys are equal (please check perturb function in the C implementation). Then it will return the value.</li><li>If we are doing update or insert, the item will be inserted or overwritten.</li></ul><p>Lastly, dictionaries have memory overhead. Because there is a sparse hash table internally, dictionaries are not space efficient. For example, when we are loading millions of records in memory, using list or tuples to represent rows is way more efficient than dictionaries. I would refer to this <a href="https://stackoverflow.com/questions/472000/usage-of-slots">stackoverflow answer </a>that talks about how to save memory by using __slot__ attribute.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bbe5a7943bb2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>