<?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 Ismail Gok on Medium]]></title>
        <description><![CDATA[Stories by Ismail Gok on Medium]]></description>
        <link>https://medium.com/@ismailgok?source=rss-2c6f21657997------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*rYY3PqJoAijUlj0kg6gKSA.png</url>
            <title>Stories by Ismail Gok on Medium</title>
            <link>https://medium.com/@ismailgok?source=rss-2c6f21657997------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 11:20:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ismailgok/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[Access Control in Swift]]></title>
            <link>https://ismailgok.medium.com/access-control-in-swift-c447da58afe?source=rss-2c6f21657997------2</link>
            <guid isPermaLink="false">https://medium.com/p/c447da58afe</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[access-control]]></category>
            <category><![CDATA[accessibility]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[encapsulation]]></category>
            <dc:creator><![CDATA[Ismail Gok]]></dc:creator>
            <pubDate>Fri, 03 Dec 2021 13:38:33 GMT</pubDate>
            <atom:updated>2021-12-03T13:38:33.105Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, we are going to get familiar with access control keywords. I believe that the most of the new developers does not know about the concept of access control well enough. When I first learnt about software development with Java, I admit that I also didn’t know enough about access control or encapsulation. Although it does not seem as an important concept at first, it can be a determination point if your code is clean or not.</p><p><strong>Disclaimer</strong>: This article will mostly be an interpretation of the Access Control documentation of the official swift website. I will try to simplify the parts that I see important and disregard the less important parts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5MbAZfq9InsYY6PKDrltfQ.jpeg" /></figure><p>The main idea of the access control is that every class, struct, enum, function or property (which I will call them entities from now on) should be visible only to the entities that they somehow interact with.</p><p><a href="https://docs.swift.org/swift-book/LanguageGuide/AccessControl.html">Official Swift website</a> describes access control restrictions as follows;</p><blockquote><em>Access control</em> restricts access to parts of your code from code in other source files and modules. This feature enables you to hide the implementation details of your code, and to specify a preferred interface through which that code can be accessed and used.</blockquote><p>Some access levels are in the scope of the whole module, and some are in the source file the code lives in. I believe that, in order to make everything easier to grasp, we need to know what is called a module or a source file.</p><h4>Module vs Source File</h4><p>A <strong>module </strong>can be called to a single application or a framework that can be distributed as a single component. This distribution might be an application that is published as a single unit or a framework that can be included into another framework or application using the “<em>import</em>” keyword.</p><p>A <strong>source file</strong> is a single swift file that can contain one or more Swift entities (classes, structs, enums, properties etc.)</p><p>To be more practical; when we start the Xcode and create an “App”, we create a single module containing bunch of swift files from the start that can be seen on file hierarchy from the left side of the screen. Each of the file is called a <em>Source File</em>, and the whole application can be called a <em>Module</em>.</p><p>After clearing the meanings of a module and a source file , we can proceed to getting familiar with access levels.</p><h3>Access Levels</h3><p>Access Levels are the keywords used for determining the access control type of an entity. These levels can be relative to either the source file or the whole module that contains the source files.</p><p>I will be ordering the access level in respect to their restriction level. The first one is the least restrictive and the last one is the most.</p><h4>Open Access</h4><p>Open access is the least restrictive access level allowing the entities to be used from all modules. The entities having the <strong>open</strong> keyword in front of them can be called or used from any other module like an application importing your module as a library or framework.</p><h4>Public Access</h4><p>Public access is almost identical to open access with a subtle difference about inheritance. The official swift website describes the difference as follows;</p><blockquote>Open access applies only to classes and class members, and it differs from public access by allowing code outside the module to subclass and override, as discussed below in Subclassing. Marking a class as open explicitly indicates that you’ve considered the impact of code from other modules using that class as a superclass, and that you’ve designed your class’s code accordingly.</blockquote><h4>Internal Access</h4><p>Internal access lets the entities be used from any source file in the same module that they live in. This means that an internal entity can be called or used from any other source file – for example from a different controller – that resides in the same module.</p><p>This access level is the <strong>default level</strong> in Swift. If you don’t put any keyword in front of your entities, the swift compiler acknowledges that entity as internal.</p><h4>File-private Access</h4><p>Fileprivate access level is used for making an entity reachable from inside of a source file. If there are more than one class, structs or enums in the source file, an entity marked as fileprivate can be used from all of them as long as they are in the same source file.</p><h4>Private Access</h4><p>Private access is the most restrictive access level in Swift. In this access level, entity which has the private keyword, can only be accessed from the same enclosing declaration or its extension. For example, a fileprivate function can only be used in the same class, struct or enum that lives in or their extensions.</p><p>When you designing a framework or a library, use internal (default access level) in order to hide the implementation of your entities from the code importing your framework, use private or fileprivate for more encapsulation. You need to mark an entity as open or public only if you want it to become part of your framework’s API.</p><h4>Special Cases</h4><p>There are some special cases where the access levels of entities have to respect the access level of the entities associated with them.</p><p>Access level of a <strong>function </strong>has to be equal to the access level of the most restrictive entity that is either its parameter or return type.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a0cf820b7710dc9e56c7d2b8efd5039/href">https://medium.com/media/1a0cf820b7710dc9e56c7d2b8efd5039/href</a></iframe><p>If we create a internal function with parameters or return types (like above) with more restrictive access levels, the compiler would give an error since the function’s access level has to comply to the entity having the most restrictive access level.</p><p><strong>Enums </strong>also has a special case when it comes to access levels. You cannot mark the cases with an access level. Each case gets the enum’s access level automatically. For example if we specify an enum as public, all of the cases would be public as well.</p><p><strong>Subclassing </strong>follows a similar rule. When you subclass a parent class in the same module or in a different module, the subclass cannot be less restrictive then its parent class (superclass). That means, if we want to inherit an internal class, we would have to declare the subclass as internal, fileprivate or private. We cannot make the subclass a higher access level like public or open.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a9eaab9456a8d70613a244d631be77e1/href">https://medium.com/media/a9eaab9456a8d70613a244d631be77e1/href</a></iframe><p><strong>Overriding </strong>sometimes makes access control hard to understand for the subclassing. If both superclass and the subclass in the same module, we could override any class member (method, property, initializer, or subscript) that’s visible in a certain access context. However, if we want to subclass from another module, we could only override a class member marked as <em>open</em>.</p><p>When we subclass a class, we can override a more restrictive class member and make it less restrictive. For example, we can override a fileprivate function and make the override function as internal as long as it respect the access level of its class. We can see the example below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1468badc07d24f59c098f307c06f9845/href">https://medium.com/media/1468badc07d24f59c098f307c06f9845/href</a></iframe><p>One special case I can talk about is with<strong> getters, setters and subscripts</strong>. Getters, setters and subscripts get the same access level with the entity (constant, variable, property etc.) they belong to.</p><p>One useful information with getters and setters, you can set a lower access level to the setter than its corresponding getter in order to restrict the write functionality of the entity. That way, we can make a property (or variable) readable from other classes in respect to its access level, but restrict changing its value to a specific scope. Here is an example;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00bf3a8777170a7fe1dac785643b8c3b/href">https://medium.com/media/00bf3a8777170a7fe1dac785643b8c3b/href</a></iframe><p>Lastly, I want to mention how access control of <strong>extensions </strong>work and to set their access levels. You can extend any class, struct and enum in any context that they are accessible and any entity defined in that extension gets the same access level of the object being extended in the default. If any internal type would be extended, the entities added to the extension would get the access level of internal as well. Similarly, any fileprivate type’s extension would get fileprivate access level as default and any private type’s extension would get private access level as default. One special case for that, if we want to extend a public type, any entity that we add to extension would be internal by default.</p><p>Alternatively, if you want to declare an access level to the extension, the entities added to that extension would get that access level by default. However, you can still override the access levels of the entities added to the extension by marking their access levels explicitly.</p><p>In my opinion, access control is a basic but extremely fundamental concept of Swift that every iOS developer should know. I hope this article was helpful and easy to understand. Stay healthy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c447da58afe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Property Observers in Swift 5]]></title>
            <link>https://ismailgok.medium.com/property-observers-in-swift-5-f4b2cd3dbe6c?source=rss-2c6f21657997------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4b2cd3dbe6c</guid>
            <category><![CDATA[willset]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios-programming]]></category>
            <category><![CDATA[didset]]></category>
            <category><![CDATA[property]]></category>
            <dc:creator><![CDATA[Ismail Gok]]></dc:creator>
            <pubDate>Fri, 26 Nov 2021 13:25:39 GMT</pubDate>
            <atom:updated>2021-11-26T13:25:39.364Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I will be explaining what are property observers in Swift 5, how to utilize them and give some examples for their most used cases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dYU27-OqQNtK9RwyUlpErQ.png" /></figure><p>Firstly, I want to briefly talk about what are properties. Properties are variables or constants that are stored in a class or a struct instance. They are used to store valuable information that can or cannot be changed at later stages of the application run time for classes or structs.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f1e4028bf702d04a2831552955d7e055/href">https://medium.com/media/f1e4028bf702d04a2831552955d7e055/href</a></iframe><p>When we initialize Person struct, we set values of these properties in order to get information from Person instance in functions later.</p><p>Property Observer — as the name suggests — creates an observer to a specific property to listen for changes and make the corresponding action when a change happens. There are two property observers called <strong>willSet </strong>and <strong>didSet </strong>in Swift 5. They behave similarly with few differences.</p><h4>willSet</h4><p>When we add <em>willSet property observer</em> to a property, it listens for changes as any observer does and calls the code inside its block when a change for that property is <strong>about to</strong> happen. It usually used for doing something just before the value of related property is changed. Here is an example to make it clearer.</p><p>Let’s say we want to implement a neat iOS application for our friend John that celebrates his birthdays. We create a Person class with two properties of name and age. Name is a constant since his name most probably won’t be changing. Age property will increment by 1 for his every birthday. We will assure that functionality with a function called <em>incrementAge()</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a0c8c8846382e8336d66b5ab6c18981/href">https://medium.com/media/0a0c8c8846382e8336d66b5ab6c18981/href</a></iframe><p>We attached a willSet observer to the age property in order to print the value of the age property when its value is changed. Now, times have past and John’s birthday has come. Our app called <em>incrementAge</em>() function and set the value of age property from 33 to 34. Just before changing old value to its new value, <em>willSet property observer</em> will be triggered and execute its code block. Therefore, in the sample code above, the print statement will print out “<strong>age is 33</strong>”.</p><p>willSet property observer intercepted the value change before the value of the property is changed, and executed the code below. So, the value of age property was still 33 at the moment the willSet block is executed. Let’s say we also want to get the new value of the property and do something with both old and the new value. There is a hidden property of willSet that gives us such ability.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dca717fc4aa311e04cb8558b445f3f34/href">https://medium.com/media/dca717fc4aa311e04cb8558b445f3f34/href</a></iframe><p>The <strong>newValue </strong>keyword stores the value that the property is about to be changed to. Since willSet will be triggered before change action of value of the property happens, the property of “age” is still the old value and the “newValue” property of willSet has the new value. Therefore, the print statement from the above example prints out: “<strong>the old age was 33 and the new age is 34</strong>”.</p><h4>didSet</h4><p>Similar to willSet property observer, <em>didSet</em> also listens to changes for the specific property, but unlike willSet, <em>didSet </em>is triggered after the value of the property is changed. Here is the same example from above with <em>didSet </em>property observer attached to the <em>age </em>property.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac4912c69eb40af545ecb32b714e158b/href">https://medium.com/media/ac4912c69eb40af545ecb32b714e158b/href</a></iframe><p>This time, we attach a <em>didSet property observer</em> to the age property of Person class. When John’s birthday comes, i<em>ncerementAge()</em> function would be invoked and increase the value of the age property from 33 to 34. Since the didSet property observer is triggered after the change is happen for the property, the print statement above will print “<strong>age is 34</strong>”.</p><p>Since the <em>didSet </em>property observer is called after the change for value of the property happens, it print the value of <em>age </em>as 34 which is the value of age property after incrementing. There is also a hidden property in didSet in order to get the value before the change happens.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ad24785636754c1e91978931a64836c/href">https://medium.com/media/8ad24785636754c1e91978931a64836c/href</a></iframe><p>The <strong>oldValue </strong>property in the <em>didSet </em>block stores the <em>old value</em> (the value of the property before the change happens). Hence, the print statement above prints out “<strong>the new age is 34 and the old age was 33</strong>” to the console.</p><p>There are a lot of use cases that these property observers really helps out. One particular example for this is implementing an observer pattern to this class in order to broadcast the changes to other classes such as other <em>UIViewControllers </em>to notify the change. One other use case of property observers is when they are used to reload the <em>UITableView </em>when the main data source for this table view changes. Here is a real life example from an application.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1bbd87c6bc7ace338f076a815b54d72b/href">https://medium.com/media/1bbd87c6bc7ace338f076a815b54d72b/href</a></iframe><p>Brief explanation of the code above; We create two properties, one for all the universities and other is for the universities that are searched by entering some keyword. They have both a <strong>didSet </strong>property observer in order to observe the changes, and reload the table view to show the searched universities or the whole university array when their value is changed. We attach a <em>SearchController </em>to our <em>UITableViewController </em>to add the search functionality. After that, we create the other related function such as <em>UITableViewDelegate</em> and <em>DataSource </em>functions to make the functionality above work.</p><p>With adding the <em>tableView.reloadData()</em> in didSet blocks for our properties, whenever the user types a letter into the search bar, the value of <em>searchedUniversities </em>property changes and triggers the didSet block to reload the table view. That way, the user can see searched universities in the table view as they change.</p><p>I hope this article was helpful. Property Observers are simple but powerful concepts to be utilized in iOS applications. Stay healthy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4b2cd3dbe6c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let’s Git Familiar — Part 3: Git Workflows]]></title>
            <link>https://medium.com/swlh/lets-git-familiar-part-3-git-workflows-f3593e3c4e56?source=rss-2c6f21657997------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3593e3c4e56</guid>
            <category><![CDATA[workflow]]></category>
            <category><![CDATA[repository-management]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[git-workflow]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Ismail Gok]]></dc:creator>
            <pubDate>Wed, 17 Nov 2021 11:43:14 GMT</pubDate>
            <atom:updated>2021-11-17T11:43:14.178Z</atom:updated>
            <content:encoded><![CDATA[<h3>Let’s Git Familiar — Part 3: Git Workflows</h3><p>This story is the third part of a series on Git Version Control System Fundamentals. You can access to <a href="https://ismailgok.medium.com/lets-git-familiar-part-1-5de13a6ad7b5">Part 1 of the series here</a>, and to <a href="https://medium.com/swlh/lets-git-familiar-part-2-9657a2b80090">Part 2 of the series here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Jl2VDHVzFBDdXggRprziUg.png" /></figure><p>In this part, I will introduce <em>git workflows</em> and explain their advantages and disadvantages in certain scenarios.</p><p>There are six widely used workflows when it comes to managing team projects. Some may be more suitable than others in certain situations. I will briefly explain their usages and talk about their pros and cons. Let’s git started!</p><h3>1. Centralized (Basic) Git Workflow</h3><p>In earlier days, the centralized version control systems like SVN were more popular. When distributed version control systems like Git became more widely used, people started to transition from SVN to those systems like Git. <strong>The Centralized Workflow</strong> simply follows the idea of a centralized version control systems such as SVN. It uses a central repository to serve as the single point-of-entry for all changes to the project. There is only one master branch and members push their local commits onto this branch and use it to deploy to the staging and production environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*otT50CH1Y4ehSuJQuIHNQw.png" /><figcaption>This image is taken from: https://zepel.io/blog/5-git-workflows-to-improve-development/</figcaption></figure><h4>Pros</h4><ul><li>It is easy to understand for a new learner or a recent SVN user</li><li>If used properly there should not be any merge conflicts to deal with</li><li>Easy to managed for small teams</li></ul><h4>Cons</h4><ul><li>Hard to recover from any mistakes</li><li>It gets complicated and messy to manage when the development team gets larger</li><li>It limits the multiple task at the same time on the repository when it comes to bug fixes and deployments</li></ul><h3>2. Feature Branching Git Workflow</h3><p>Centralized workflow is usually suitable for one or few developers working on the same project. Once your team of developers gets more then few people, it is better to stay away from centralized workflow. That is when the <strong>feature branching workflows</strong> comes into place. In feature branching workflow, a separate branch should be created for every feature of the project. The developers can implement their feature changes into their dedicated feature branches, and when they are done with the development, they can merge their respective feature branches to the main branch that the production code lives in. Ideally, a branch should have a lifespan of a few hours.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zb5uMFkdE3K5nHnolAaytQ.png" /><figcaption>This image is taken from: https://zepel.io/blog/5-git-workflows-to-improve-development/</figcaption></figure><h4>Pros</h4><ul><li>The main branch always has finished code</li><li>Makes it easy to develop and maintain features without disturbing the main branch</li></ul><h4>Cons</h4><ul><li>When more than one developer work on the same feature it can get hard to manage the future branch</li><li>If a future branch lifespan gets longer, it can make the merging difficult with a lot of conflicts</li></ul><h3>3. Trunk-based Development Git Workflow (Develop Branch)</h3><p><strong>Trunk-based Development Workflow (or Develop Branch Workflow)</strong> is similar to the feature branch workflow with a subtle change of using another branch called trunk (or develop). This branch is a parallel branch to the main (or master) branch, that is rebased from central repository when some features will be made to the next code release. Since it is rebased from main branch before a new feature is implemented, it acts as a working copy of the central repository. The changes from the feature branches are merged to the trunk branch first with resolving any conflicts that occurred during the process. The key part is, the release-ready code is tested again as a whole in this branch before merging it onto the main branch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eEYmh3IaRX6Fotb0bKldHg.png" /><figcaption>This image is taken from: https://zepel.io/blog/5-git-workflows-to-improve-development/</figcaption></figure><h4>Pros</h4><ul><li>The release-ready code is tested as a whole with all the new features added before merging with main branch</li><li>Main branch is kept as clean as possible</li><li>It allows to make minor and swift code changes without caring about breaking the main branch</li></ul><h4>Cons</h4><ul><li>Adds complexity to the management of the repository with requiring extra steps</li><li>Requires a developer to manage the conflicts locally</li><li>Requires regular updates to make the main branch up to date</li></ul><h3>4. Personal Branching Git Workflow</h3><p><strong>Personal Branching Workflow</strong> is similar to feature branching. The only difference is, there is one branch per user instead of per feature. This allows developers have their separate branches to commit and do other actions more freely. Developers can use their own branch for small changes like bug fixes or implementing parts of the features they are responsible for. This workflow strategy is good for small teams in which every team member develops a part of the whole application.</p><h4>Pros</h4><ul><li>Developers can experiment more freely</li><li>It makes the branch management easier since there is only one branch per team member</li><li>Easy to implement small changes to the code like bug fixes etc.</li></ul><h4>Cons</h4><ul><li>Does not give flexibility like feature branching when implementing big features</li><li>If the application has a lot of features developing at the same time, this workflows makes repository management difficult</li></ul><h3>5. Forking Git Workflow</h3><p><strong>Forking Workflow</strong> is usually used for the projects in which a huge number of developers contribute. The best example for Forking Workflow is open-source projects like on GitHub. When a developer forks a project, a copy of the project is created as a separate repository in his/her account. That way, the developer can use his/her own server-side repository for the project instead of using only a single server-side repository as the central source of the project like other workflows. A remote path for the official repository is added to the repository that is cloned to the local system. Once the developer makes the changes to its copy repository, he/she creates a pull request to notify the original central repository owner to review the code changes and merge them if it is accepted.</p><h4>Pros</h4><ul><li>It is a great and secure way to manage the open-source project repositories</li><li>The central repository owner has the full control of its code to merge only the high quality contribution</li><li>Makes it easy to maintain the repository for large teams</li></ul><h4>Cons</h4><ul><li>It is a longer process compared to the other workflows</li></ul><h3>6. Gitflow Git Workflow</h3><p><strong>Gitflow Workflow</strong> does not bring anything new to the table. It is very similar to Trunk-based Development Git Workflow with two additional branches, Release Branch and Hotfix Branch. As in Trunk-based development workflow, the main(master) branch is always releasable to the production code in Gitflow Workflow. Again, similar to Trunk-based development workflow, every feature is committed to the development(develop) branch.</p><p>The first difference is, when the team decides to publish a feature to the main branch, the developer first creates a release branch where testing and bug fixing occur before being merged back to the develop branch to make the develop branch as the latest source of the production code. After all the test are done and the code is secure enough to go to the production, then the release branch is merged to the main branch and the feature goes live.</p><p>The second difference comes to place when there is an urgent need for a swift bug fix to the production code. When the team requires a quick fix on the running code, a hotfix branch is created from the main branch, the required patch is applied on the code, and then it merges back to main branch directly. Only the Hotfix branch is created from and merged directly onto the main branch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AXbAL5H9KvDbBycrvHWqFA.png" /><figcaption>This image is taken from: https://zepel.io/blog/5-git-workflows-to-improve-development/</figcaption></figure><h4>Pros</h4><ul><li>The release branch makes the reviewing and conflict resolving process easier</li><li>With the hotfix branch, it is easy and quick to make small bug fixings</li><li>This workflow is great for large teams since it is secure and easy to manage</li></ul><h4>Cons</h4><ul><li>The team should be careful when hotfixing since it can cause a problem directly to the production code</li><li>It is a longer process compared to more basic workflow</li></ul><p>I hope this article was helpful. This was the last part of the<strong> Let’s Git Familiar</strong> blog post series. You can check out the <a href="https://ismailgok.medium.com/lets-git-familiar-part-1-5de13a6ad7b5">first</a> and the <a href="https://medium.com/swlh/lets-git-familiar-part-2-9657a2b80090">second</a> ones if you haven’t already. Stay healthy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3593e3c4e56" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/lets-git-familiar-part-3-git-workflows-f3593e3c4e56">Let’s Git Familiar — Part 3: Git Workflows</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Retain Cycles and Memory Management in Swift]]></title>
            <link>https://medium.com/better-programming/retain-cycles-and-memory-management-in-swift-fb6226165b17?source=rss-2c6f21657997------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb6226165b17</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Ismail Gok]]></dc:creator>
            <pubDate>Wed, 10 Nov 2021 08:40:43 GMT</pubDate>
            <atom:updated>2021-11-15T17:53:13.170Z</atom:updated>
            <content:encoded><![CDATA[<h4>Build performant iOS applications</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aalD7rY8wzab8eoE" /><figcaption>Photo by <a href="https://unsplash.com/@sharkovski?utm_source=medium&amp;utm_medium=referral">Kirill Sharkovski</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this article, I would like to explain what the concepts of retain cycle and memory management are, and how you can improve your iOS app by simply knowing these concepts.</p><p>In Swift or any other OOP language, every instance is either a value type or a reference type.</p><p>Value type instance means whenever you want to create a variable from that instance and assign that variable to another one, it follows a concept called pass by value which means that it copies the value of the variable to another.</p><p>The change on one of them wouldn’t affect the other one because the original value was copied to the other instance and the copied value is still the same.</p><p>On the other hand, a reference type instance follows the concept of pass by reference which means that the value would not be copied but both of the variables would point to the same memory space. If one changes, the other one also changes because the values in that memory space would change.</p><p>Let me throw in a simple example to make it all clearer. Here is a value type example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8afd5c1b44ba1ef3d0cfb39ac2c4289a/href">https://medium.com/media/8afd5c1b44ba1ef3d0cfb39ac2c4289a/href</a></iframe><p>Since structs are value types, when we create a variable using a struct and assign it to another variable, Swift only copies the value of the first variable to the second one. If we want to change a property in the first variable, and print both of them as above, we can see that the first print statement prints out Audi and the second print statement still print out Mercedes.</p><p>Here is a Class example for the purpose of visualizing reference types:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3315a6420beb014bc3fda4c902f8d60f/href">https://medium.com/media/3315a6420beb014bc3fda4c902f8d60f/href</a></iframe><p>First we create a variable out of Car class and assign it to another variable. Since classes are reference types, both variables (car1 and car2) points to the same memory address. When we change the brand property of car1 variable to Audi and print both variables brand properties, both<strong> </strong>print statements print out Audi.</p><p>Once we make everything clear on value and reference types which are fundamental concepts to understand memory management, we can go on to the real stuff.</p><p>Swift compiler deals with the memory management of value types (structs and enums).</p><p>In most of the scenarios, the compiler also deals with the memory management of classes which are reference types. However, you should be aware of some cases that classes cause memory problems that the compiler could not handle itself.</p><p>Normally when a reference type — for example “a class” — is done being used, the compiler would deallocate the instance, hence its space would be freed from the memory.</p><blockquote><em>Reminder: In OOP, we could assign class variables to other class variables. That assignment is called pass by reference. It means that the reference of the instance would be copied to another variable, not the value of it.</em></blockquote><p>This concept can cause some memory problems because more than one instance points to the same memory space, therefore the compiler itself cannot resolve when to deallocate the instances from the memory. In this scenario, Swift uses a concept called Automatic Reference Counting (ARC) to make the compiler’s task easier.</p><h4>Automatic Reference Counting (ARC)</h4><p>The idea behind the automatic reference counting is simple. Swift keeps track of the references created in the code by counting the references each class instance have in order to know when it is safe to deallocate the class instance from the memory.</p><p>ARC makes sure that a class instance isn’t deallocated as long as a property or variable has a strong reference to it. I will explain it on an example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c75a9f6bd1dd4ba44888ec7a4da2f770/href">https://medium.com/media/c75a9f6bd1dd4ba44888ec7a4da2f770/href</a></iframe><p>First let’s assume that John wants to buy a new car. He creates that object for the car using the class above. Whenever a new car object is created, the init<strong> </strong>function assigns the brand name and prints it.</p><p>When John wants to sell his car, the object would be deallocated from the memory, therefore the deinit<strong> </strong>function would be triggered.</p><p>Now, in order to demonstrate ARC in a practical example, we will create some instances from the MyNewCar<em> </em>object above.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5d295a549ce6f4a6c7c61eb5ae9c9f99/href">https://medium.com/media/5d295a549ce6f4a6c7c61eb5ae9c9f99/href</a></iframe><p>We created three variables of type MyNewCar and did not initialized them. First we initialize one of the variables with our MyNewCar class constructor.</p><p>This operation prints Porsche is being initialized statement because a memory space in allocated for the reference of the class object hence init method will be invoked when we first initialize the object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/683a0b4e7736b56d1ab8c92483c29ceb/href">https://medium.com/media/683a0b4e7736b56d1ab8c92483c29ceb/href</a></iframe><p>After that, we assign the porsche<em> </em>variable<em> </em>to the other two variables as above. I will explain what happens in the background of this assignment in the following paragraphs.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f772d87cdaf651b3c29670dae34f675/href">https://medium.com/media/9f772d87cdaf651b3c29670dae34f675/href</a></iframe><p>Then, we assign the porsche and mercedes variables to nil. Again, I will explain what happens in the background of this assignment in the following paragraphs.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf9b8bcded6c22d55e41fa15b645a59b/href">https://medium.com/media/bf9b8bcded6c22d55e41fa15b645a59b/href</a></iframe><p>Lastly, we set the last instance of that class (which is ford) to nil.</p><p>Only after when all instances of the same object is removed, the object is truly deinitialized<em> </em>and it is deallocated from the memory. Hence it prints out the statement in the deinit function.</p><p>Now, what exactly happened in this example? Did we create an object and copy it to the two other objects? This question is actually answered in the second paragraph of this article.</p><p>Classes are reference types and they are stored in the heap parts of the memory. When you assign two or more instances to the same class object, the content of the object wouldn’t be copied, they only point on the same address on the memory. So, no to copying values, only addresses from the memory object is contained.</p><p>Main concern of the example was to explain the concept of Automatic Reference Counting (ARC). ARC count the number of strong references to an object. When an instance is created and initialized from a class ARC is 1 for that object. When that instance is assigned to two other instances, ARC would be 3 (a<em>fter assigning porsche to two other objects</em>).</p><p>When we set the two of the instances to nil, we remove their connection to the memory address that contains the object. They don’t point to that address anymore. ARC would be 3–2 = 1 for that object again. Since ARC is still more than zero, that class object wouldn’t be deallocated and would still live in the memory.</p><p>Only when we set the last object that points to the object (which is the ford<em> </em>object), the ARC would be zero and deinit function of the class would be invoked and the reference of the class would be deallocated from the memory.</p><h4>Strong vs Weak vs Unowned</h4><p>What is strong reference? We will briefly look on what makes a reference strong or weak.</p><p><em>I will only briefly mention the concepts of strong, weak and unowned references in this article. For further explanation, I will be writing another article only on this concept.</em></p><blockquote>In Swift, a variable can be declared as <em>strong</em>, <em>weak </em>or <em>unowned </em>in terms of reference it makes.</blockquote><p>In order to make a variable strong, you don’t need to write anything in front of the declaration. Strong references protects the object which points to, from getting deallocated by ARC. As long as an object has a strong reference, it cannot be deallocated from the memory even if the screen containing the object has popped from the navigation stack.</p><p>For example, every variable in the examples above is making strong references since there are no keywords like weak or unowned.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*6ckwxMS823wjVZFpMfk6jg.png" /><figcaption>Image by author</figcaption></figure><p>In contrast to strong references, a weak reference does not protect referred object from getting deallocated from memory when there is no strong reference points to it.</p><p>Weak references also does not increase the ARC count when pointing to an object. When there is no strong reference pointing on an object even if there are weak references pointing, ARC would be zero and it would be deallocated from memory making the weak references variable nil, hence all weak referenced variables must be optionals. In order to make a weak reference, we need to declare the variable as a var<strong> </strong>and put a weak<strong> </strong>keyword in front of it.</p><p>As mentioned above, weak referenced variable will be nil when there is no other strong reference left pointing on the object, therefore it must be a mutating variable. That means it cannot be a constant (it cannot be declared as a “let”).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*A6yTWls7nfluyhS1R_ypBA.png" /></figure><p>An<strong> </strong>unowned reference is very similar to a weak reference except some subtle differences. Both unowned references and weak references does not increase the ARC when pointing on an object.</p><p>However, an unowned referenced object does not have to be an optional like weak referenced object does in Swift and they only should be used when you are certain that the reference will never be nil once it has been set during initialization<em>.</em></p><p>This means that, unowned referenced object does not zero out when the object is deallocated from memory when there is no strong references on that object. This creates a concept called<em> dangling pointer</em> which every Swift developer should be aware of.</p><p>Therefore, unowned referenced object should be used like <em>implicitly unwrapped optionals</em>. I won’t be explaining the concepts of dangling pointer and implicitly unwrapped optionals since their details are not must-knows for this memory management article. I will be explaining them in details on an another article.</p><p>I assume that all is clear with the Automatic Reference Counting terminology. The next big thing is what happens if we do not pay attention to this ARC concept and how it hurts the performance of our application.</p><h4>Retain Cycles and Memory Leaks</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*ZCKr4aOSXmNuToIby3ILAg.png" /><figcaption>Image by author</figcaption></figure><p>We all know — at least now :) — in order to deallocate an object from memory, its ARC value must be zero. However, when some two object refers each other via strong references, they prevent the compiler from deallocating either object because their ARC value would always be 1. That is called a retain cycle.</p><p>Memory leak occurs when an amount of allocated memory space cannot be deallocated for some reason in iOS applications, the usage of memory for that application always grows while the app is running. Memory leaks may be very critical since they can use up all the memory reserved for the application quickly and making the iOS operating system force shut down the application.</p><p>Retain cycles often cause memory leaks since all of the objects that caused retain cycles cannot be deallocated from memory. I will give a small example for demonstrating how we can cause a retain cycle and an app with potential memory leaks.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/abac5225ebb26384d3969c17ccbba8b4/href">https://medium.com/media/abac5225ebb26384d3969c17ccbba8b4/href</a></iframe><p>Firstly, let’s say that John wants to buy a new car once again. In order to help him, we write a Car<em> </em>class like above. The class has two properties; one is brand<strong> </strong>which has the type of String, and the other one is driver<strong> </strong>which has the type of Person.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e9b20505b1db9e1b2c9bf7d4b7399d95/href">https://medium.com/media/e9b20505b1db9e1b2c9bf7d4b7399d95/href</a></iframe><p>In parallel, we write a Person<em> </em>class that has two properties; name<strong> </strong>and car. Both classes have initializer and deinitializer functions for creating and destroying the objects that derived from these classes. When either of the objects are destroyed (or set to nil) deinit<em> </em>function should be invoked and print a responding statement.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b5471e448df40f0199457cd31893b775/href">https://medium.com/media/b5471e448df40f0199457cd31893b775/href</a></iframe><p>After writing the classes, we initialize both of them using their initializers. Now, we need to set a driver<strong> </strong>to the Car instance (mercedes), and set a car<strong> </strong>to the Person instance (john). We do exactly that in line 5 and 6. That makes ARC values for both Car and Person object instances (which are mercedes<em> </em>and john) to 1.</p><p>When our job is done with them and we want to free their resource from memory, we want to destroy both of the objects like in line 8 and 9. We expect their ARC values should decrease to 0 and compiler to free their resource from memory. However, we don’t see any print statements from deinit functions of both classes. What went wrong is, we caused a retain cycle.</p><p>Since there are two strong references that refers to each other, Swift compiler cannot free their resources from the memory hence cannot decrease their ARC values when we set them to nil. For example; when we set mercedes<em> </em>instance to nil, the compiler cannot decrease its ARC to 1 because a Car object is still referencing the mercedes and vice versa.</p><p>In order to prevent this retain cycle, we need to declare at least one of the variable as weak or unowned. We can break the retain cycle with adding a weak<strong> </strong>keyword before either the driver<em> </em>property of the Car class or the car<em> </em>property of the Person class.</p><p>That was a short introduction to the retain cycles and memory leaks in order to understand the importance of the memory management concept in Swift. I will be adding more blogs about memory management and similar topics since it is a crucial concept to learn about in my opinion.</p><p>I hope this article can be a help for understanding the fundamental parts of memory management concepts running mostly behind the scene and help you implement high performance iOS applications. Stay healthy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb6226165b17" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/retain-cycles-and-memory-management-in-swift-fb6226165b17">Retain Cycles and Memory Management in Swift</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Delegation Pattern in Swift]]></title>
            <link>https://ismailgok.medium.com/delegation-pattern-in-swift-5c2ad4cbecec?source=rss-2c6f21657997------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c2ad4cbecec</guid>
            <category><![CDATA[uikit]]></category>
            <category><![CDATA[delegation-pattern]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[delegation]]></category>
            <category><![CDATA[protocol]]></category>
            <dc:creator><![CDATA[Ismail Gok]]></dc:creator>
            <pubDate>Wed, 03 Nov 2021 08:16:15 GMT</pubDate>
            <atom:updated>2022-07-07T04:59:23.177Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>I decided to make this article a part of a design pattern series for iOS development. This will be the first article for the series and the most used one as my opinion.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*4wzFIrkgFzsL37Uq6AKzWw.jpeg" /></figure><p>Some can argue that design pattern is the essence of the object oriented programming since they are well structured solutions to common algorithm problems. In this article, I will try to explain the Delegation Design Pattern with real life code examples used in my own iOS projects.</p><p>One of the core concepts of iOS programming with Swift is Delegation. In order to really grasp the idea of Delegation in Swift, one should be familiar with Protocols in Swift.</p><p>When I started to learn Swift for iOS development. First, I didn’t really comprehend what a protocol is. It was a weird terminology for me that I did not see in any other software development language before. I mean that if someone is familiar with one or two software development language, the one can be familiar with the terminologies like class or struct but a protocol was an unknown word for me. Although it sound different, If you work with JAVA or a similar OOP language there is a very simple explanation what a Protocol is; “Interface.” Like interfaces in most OOP languages, protocols are blueprints that the classes, structs or enums that conforming the protocols can do. It carries the signatures of functions and properties that the conforming objects have to implement. As you can see, they are pretty much interfaces of the other common languages.</p><p>For more formal explanation what protocols are here is the explanation of <a href="https://docs.swift.org/swift-book/LanguageGuide/Protocols.html">swift.org</a>;</p><blockquote>A protocol defines a blueprint of methods, properties, and other requirements that suit a particular task or piece of functionality. The protocol can then be adopted by a class, structure, or enumeration to provide an actual implementation of those requirements. Any type that satisfies the requirements of a protocol is said to conform to that protocol.</blockquote><blockquote>In addition to specifying requirements that conforming types must implement, you can extend a protocol to implement some of these requirements or to implement additional functionality that conforming types can take advantage of.</blockquote><p>To sum all of the explanations up, here is a most basic example of a simple protocol in swift.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb10be79a6bab7cbe10277ae32d18e7d/href">https://medium.com/media/bb10be79a6bab7cbe10277ae32d18e7d/href</a></iframe><p>There is a lot more to know about protocols but the explanation above should be enough to grasp the essence of it in order to understand delegation pattern.</p><p>Once one get to know protocols, we can proceed to Delegations, what are they, where and when to use them. Delegation is a concept that mostly used in Protocol Oriented Programming (POP). The concept of delegation is widely used in original Apple libraries in Swift. One simple example for this is UITableView. When one wants to show some data in a row by row manner, one can use a preconfigured view type called UITableView and in order to manipulate the rows in the UITableView, the containing controller needs to conform UITableViewDelegate protocol. Apple always designs their views in a protocol oriented way and uses a lot of delegates like in UITableView.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/68eba987ba04939947dee6953b7ed291/href">https://medium.com/media/68eba987ba04939947dee6953b7ed291/href</a></iframe><p>Even in the most simple usages of an UITableView in Swift, we need to conform to Apple’s UITableViewDelegate protocol to manipulate the cell actions as above. For example; to determine what happens when someone tap on the cell of the UITableView. Apple delegated this action handling to the UITableViewDelegate Protocol with the usage of Delegation Pattern.</p><p>After understanding that Apple really loves delegation pattern, now it is time to understand when and where it is best used.</p><p>As the name implies, delegate means transferring some responsibilities to some other object. Most common practice of this responsibility transfer is when we use UITableViewController with Custom UITableViewCells. I am going to explain this concept with a widely used example with real life scenarios.</p><p>Let’s say that you are creating an app that contains a row by row information like a list of movies. The easiest way to implement that is to use a UITableView, right? Also, one can like some movies more than others, and want to implement that functionality to your app. In custom cell view, you add a “Like icon” to the cell. The idea is when someone taps the like icon, the app should add that movie into the favorite movies list since you want to display only favorited movies eventually. No one wants to see only awful movies, right?</p><p>Now, your “like icon” — which should be a button to be tapped conveniently — is in the UITableViewCell which is in a different swift file then your <em>UITableView</em>. So the liking or adding to favorites action should be trigger from <em>UITableViewCell </em>but you do not want to store <em>FavoriteMovies </em>Array in the <em>UITableViewCell </em>file right? Because it not specific per cell, it belong to the whole table view. So, we should somehow send the “adding to favorites” (or liking) responsibility to the main UITableView from the UITableViewCell. This is the time that delegations come to place.</p><p>Let’s see this with an example first, then explanation will come later. I will use Swift UIKit with programmatic approach.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7047752b618585398c82b3f7ca52a7cc/href">https://medium.com/media/7047752b618585398c82b3f7ca52a7cc/href</a></iframe><p>After adding a Favorite (or Like) button to the cell view, we need to create a protocol to be conformed according to delegate pattern later. We need to add the signature of the action we want to perform when the favorite button is tapped on with the Cell parameter, which in our case is <strong>handleFavoriteTapped(_ cell: MovieCell)</strong>. We would like to pass the object which we want to get the required information from to the parent object, and that object is the Movie object in our case, but I like to pass the whole cell object for the ability to access more information of the class if required.</p><p>When declaring the protocol, I extend it from <em>AnyObject </em>in order to allow it to be conformed only from classes. The reason I want the protocol can only be conformed from class is because I want to declare the instance of my protocol as a weak variable, since weak cannot be applied to non-class type. The usage of weak is primarily for preventing potential memory leaks and retain cycles. (We will be explaining the concepts of memory leaks, retain cycles in another blog post)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd3d249ef38914d6e7afbac2c7c36d0b/href">https://medium.com/media/fd3d249ef38914d6e7afbac2c7c36d0b/href</a></iframe><p>After creating the protocol, we need an instance of it in the cell class since we will call the function from it when the favorite button is tapped. (<em>weak var delegate: MovieCellDelegate?)</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1bef91ee94c548aeac579716d611eaec/href">https://medium.com/media/1bef91ee94c548aeac579716d611eaec/href</a></iframe><p>The only thing left is to call the function in our protocol from the handleFavoriteButtonTapped() when the favorite button is tapped.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b793e7b4329a91fce62b6a13738410ea/href">https://medium.com/media/b793e7b4329a91fce62b6a13738410ea/href</a></iframe><p>Afterwards, we need to register the parent UIViewController class as the delegate for the <em>MovieCell</em> class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0500d80b24bd4035318b0f247da68fcd/href">https://medium.com/media/0500d80b24bd4035318b0f247da68fcd/href</a></iframe><p>The only thing left to do is, in order to use the delegated action from another class, we need to conform the <em>MovieCellDelegate </em>protocol and implement the <em>handleFavoriteTapped </em>function signature as follows.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b1a69d1acdbb2769076c5cc2b9508d21/href">https://medium.com/media/b1a69d1acdbb2769076c5cc2b9508d21/href</a></iframe><p>This was the most common usage of the delegations in Swift. To sum up, you want to perform an action in child object, UITableViewCell and you want to change something with this action on parent object, here a.k.a UITableView. You delegate the responsibility of the action from the child object to the parent object like above.</p><p>In the last part, I would like to discuss the benefits of using the delegation design pattern. Because the example from above is only one of the solutions to this problem, however I think is the best one. The main benefit of delegating certain decisions and behaviors to the parent object from the child object is creating a decoupled model with low dependency. Hence, it becomes much easier to support multiple scenarios without creating large classes just to provide all the required behaviors in the child objects.</p><p>As I mentioned, delegation is just one way of doing this data passing. There are multiple ways that we could have implemented the same behavior above. I will mention some of the alternative ways to implement the same result below.</p><h4>Using Notifications instead of Delegation</h4><p>There is another pattern that can be used to pass data to other objects called Notification Pattern. You could easily attach a <em>notifier </em>onto movie object in each cell and once the movie object is changed, it could pass the information to the observer objects. That could work but there are two major downsides to this approach.</p><p>First is, notification patterns are used for broadcasting information. That means that, if there is many-to-one or one-to-many relationship using notifications is logical, since we pass the data in one-to-one manner, using delegations is more convenient.</p><p>Secondly, one should be careful using notifications, because notifications — if not used correctly — are CPU-intensive tasks. A simple task like above, there is no need for heavy lifters like notifications.</p><h4>Using Closures instead of Delegation</h4><p>A viable alternative for the delegation pattern is simply using <em>closures</em>. Instead of calling a delegate function, the delegating class calls a closure that’s defined beforehand as a property on the delegating class. You could easily use closures when passing data from one object to another asynchronously. Closures, like delegation, can provide lightweight and decoupled solutions to this problem. The only downside would be, if your logic grows to much, closures could make a mess in regards to readability.</p><p>This was a simple explanation on what delegation is and how to utilize them the most. There are still a lot to offer of delegations though. I hope this has been helpful. Stay healthy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c2ad4cbecec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let’s Git Familiar — Part 2]]></title>
            <link>https://medium.com/swlh/lets-git-familiar-part-2-9657a2b80090?source=rss-2c6f21657997------2</link>
            <guid isPermaLink="false">https://medium.com/p/9657a2b80090</guid>
            <category><![CDATA[git]]></category>
            <category><![CDATA[git-workflow]]></category>
            <category><![CDATA[version-control]]></category>
            <category><![CDATA[version-control-system]]></category>
            <category><![CDATA[git-commands]]></category>
            <dc:creator><![CDATA[Ismail Gok]]></dc:creator>
            <pubDate>Fri, 25 Dec 2020 12:56:23 GMT</pubDate>
            <atom:updated>2021-11-08T11:26:48.578Z</atom:updated>
            <content:encoded><![CDATA[<h3>Let’s Git Familiar — Part 2: Git Fundamentals 2</h3><p>This story is the second part of a series on Git Version Control System Fundamentals. You can access to <a href="https://ismailgok.medium.com/lets-git-familiar-part-1-5de13a6ad7b5">Part 1 of the series here.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Jl2VDHVzFBDdXggRprziUg.png" /></figure><p>In the last part, I tried to answer the questions “what is git version control ?” and “what it is for ?”. Besides those, I introduced basic and most commonly used git commands. In this part, I wanted to talk about more advance git commands and how to utilize them. Let’s begin.</p><p>We can start with the command that helps us getting the latest changes from the remote repository. We went over “git pull” command in the last part but I did not mention “git fetch” command. You can examine the changes on the remote repository with the <em>fetch</em> command before writing them onto your local repository with the <em>pull</em> command.</p><pre><strong>git fetch &lt;remote_name&gt;</strong> // gets all the branches from the remote git    // repository</pre><pre><strong>git fetch &lt;remote_name&gt; &lt;branch_name&gt;</strong> // gets the specific branch  // from the remote git repository</pre><p>Example usage:</p><pre><strong>git fetch test_remote test_branch</strong> // gets the test_branch</pre><p>We mentioned branches before but we did not talk about how to create or manage them. What is branches?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*K6E4fCcgAbGm2SGAUb2nLQ.png" /></figure><p>Let’s go to Atlassian website and see how they described branches.</p><blockquote>Branching is a feature available in most modern version control systems. Branching in other VCS’s can be an expensive operation in both time and disk space. In Git, branches are a part of your everyday development process. Git branches are effectively a pointer to a snapshot of your changes. When you want to add a new feature or fix a bug — no matter how big or how small — you spawn a new branch to encapsulate your changes. This makes it harder for unstable code to get merged into the main code base, and it gives you the chance to clean up your future’s history before merging it into the main branch.</blockquote><p>You can access the full branching page here: <a href="https://www.atlassian.com/git/tutorials/using-branches"><em>https://www.atlassian.com/git/tutorials/using-branches</em></a></p><p>You can create branches using either of the two commands below.</p><pre><strong>git branch &lt;branch_name&gt;</strong> // Creates a new branch at local repository //with a specific name</pre><p>After creating the branch with the <em>git</em> <em>branch</em> command, you need to manually switch the new branch with <em>git checkout </em>command to given branch name.</p><pre><strong>git checkout &lt;branch_name&gt;</strong> // Switches the specific branch</pre><p>The second way to create a branch and switching to it can be done with a combination of those two commands.</p><pre><strong>git checkout -b &lt;branch_name&gt;</strong> // Creates a new branch at local repository with a specific name and switches to it.</pre><p>Afterwards, you need to push the branch to the remote repository using <em>git</em> <em>push</em>.</p><p>You can list all the branches in your repository using;</p><pre><strong>git branch</strong> // Lists all the branches</pre><pre><strong>git branch -a</strong> // Lists all the remote branches</pre><p>Let’s say you are done with a branch. You can delete the branch adding <em>-d</em> or <em>-D</em> at the and.</p><pre><strong>git branch -d &lt;branch_name</strong>&gt; // deletes the specific branch</pre><pre><strong>git branch -D &lt;branch_name&gt;</strong> // force delete the specified branch, // // even if it has unmerged changes.</pre><p>You can also rename the current branch.</p><pre><strong>git branch -m &lt;new_branch_name&gt;</strong> // Renames the current branch to the // specific branch name</pre><p>Assume that you created a branch, made some changes and you want to persist those changes to the Master branch. There is an operation called branch merging. In order to show you its fancy explanation let me quote from Atlassian website. (You can find further information here: <a href="https://www.atlassian.com/git/tutorials/using-branches/git-merge">https://www.atlassian.com/git/tutorials/using-branches/git-merge</a>)</p><blockquote>Merging is Git’s way of putting a forked history back together again. The git merge command lets you take the independent lines of development created by git branch and integrate them into a single branch.</blockquote><blockquote>Note that all of the commands presented below merge into the current branch. The current branch will be updated to reflect the merge, but the target branch will be completely unaffected. Again, this means that git merge is often used in conjunction with git checkout for selecting the current branch and git branch -d for deleting the obsolete target branch</blockquote><p>Okay, we understand that merging branches means we integrate two separate branches into one, but how does it work? Let me show you with some basic examples.</p><p>Let’s assume that your team published an application to web. After some time, there have been some complaints that your web app has some bugs and the issue is assigned to you. What you need to do is to code a hotfix immediately. So, you should create a branch. Let’s say you name the branch with a tag, new-fix (git command:<em> git checkout -b new-fix master</em>) You worked on the bugs and write the code that fixes them. After some thrill testing, you commit your changes and your code is ready to be published to the production. Your production code is on the “<em>Master” </em>branch, and your hotfix is on “<em>new-fix”</em> branch and they are needed to be merged.</p><pre><strong>git checkout master</strong> // Switches the current branch to Master branch</pre><pre><strong>git merge new-fix</strong> // Merges new-fix branch onto Master branch</pre><p>And it is done. You successfully merged “<em>new-fix”</em> branch onto “<em>Master” </em>branch. Of course sometimes merging does not go as smooth as this one. There can be some changes on Master branch that your new branch does not have. These situations raise conflicts. When a conflict happens, you need to apply a <em>Merge Conflict Resolution</em> operation, meaning you need to select which changes to keep and which ones to discard with <strong>merge commit </strong>command.</p><p>Since we discussed branches, we ought to mention rebase command too. You can find detailed explanation here: <a href="https://www.atlassian.com/git/tutorials/rewriting-history/git-rebase">https://www.atlassian.com/git/tutorials/rewriting-history/git-rebase</a>. In short terms, git rebase helps you change the base commit of the remote repository to a specific commit with the command below. (It sets the start point of the branching history)</p><pre><strong>git checkout feature</strong> // Switches the current branch to “feature” // <br>// branch</pre><pre><strong>git rebase master</strong> // Aligns the history of the Master branch with // // “feature” branch</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*ZEtQyiI8of3JeZ-VyPBgmg.jpeg" /></figure><p>There are three more commands that I want to mention that can manipulate the flow of commit sequences: <em>Checkout</em>, <em>Reset </em>and <em>Revert </em>commands. Let’s first begin with <em>Checkout</em> and <em>Reset.</em></p><p>Let’s imagine a situation that you made some changes on Master branch and commit the changes. Both HEAD ref and Master ref pointers point on that commit, meaning that both last commit you have made and the last commit of the Master is the same one. <em>(your last change) </em>On the other hand, there is a previous commit that you want to go back to. You have two options. First is to use <em>git checkout</em> command. (Note: Usually checkout command is used to switch between branches as in <strong>git checkout &lt;branch_name&gt;</strong> but if you want to point the HEAD ref onto a previous commit in the current branch you can use <strong>git checkout &lt;commit_name&gt;</strong>.) The second option is to use <em>reset </em>command. git reset command points both HEAD and Master ref onto a specific commit. There is an image below to visualize the information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*R_av4T7fBlHWzk_UXIJmQw.png" /></figure><p>You can get further information about <em>git reset</em> from <a href="https://www.atlassian.com/git/tutorials/undoing-changes/git-reset">https://www.atlassian.com/git/tutorials/undoing-changes/git-reset</a></p><p>Another useful command is git revert. Let me again first quote the formal explanation of the command from Atlassian web site:<a href="https://www.atlassian.com/git/tutorials/undoing-changes/git-revert">https://www.atlassian.com/git/tutorials/undoing-changes/git-revert</a></p><blockquote>The git revert command can be considered an &#39;undo&#39; type command, however, it is not a traditional undo operation. Instead of removing the commit from the project history, it figures out how to invert the changes introduced by the commit and appends a new commit with the resulting inverse content. This prevents Git from losing history, which is important for the integrity of your revision history and for reliable collaboration.</blockquote><p>Reverting should be used when you want to apply the inverse of a commit from your project history. This can be useful, for example, if you’re tracking down a bug and find that it was introduced by a single commit. Instead of manually going in, fixing it, and committing a new snapshot, you can use <em>git revert </em>command to automatically do all of this for you.</p><p>Unlike <em>git checkout (with a commit_Id not with a branch name)</em>and <em>git reset </em>the undo action been made with git revert does not change the location of the ref pointers. The revert operation takes a commit and inverses the changes that commit brings. That operation creates a new inversed commit (reverted commit) and like a regular commit creation, the HEAD ref points to the newly created commit.</p><pre><strong>git revert HEAD</strong> // inverses the changes from the last commit</pre><p>A figure of branches is shown below to describe the states before and after <em>git revert</em> command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*47j9Ss1hYn4SConFqeaz4A.png" /></figure><p>Before I end my article, I wanted to mention one last git command. Git or any other version control system is used for keeping the changes of your records and one useful thing is to get the logs about those changes. You can use <strong>git log</strong> command to see the history of your repository. For example; after the revert commit if you use <em>git log</em> command to see the changes have been made onto the branch, you will notice the line: <em>&lt;commit_id&gt; revert “commit description”.</em></p><p>There are still many git commands like <em>git show</em>, <em>git reflow</em> etc. but I wanted to mention commonly used ones since the article is too long as it is. So if you want to learn more about git commands, I encourage you to check them out.</p><p>I will introduce <em>git workflows</em> to you and give some real world examples to best utilize the Git Version Control. Stay healthy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9657a2b80090" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/lets-git-familiar-part-2-9657a2b80090">Let’s Git Familiar — Part 2</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Web Scraping Example in Python using BeautifulSoup]]></title>
            <link>https://medium.com/analytics-vidhya/web-scraping-example-in-python-using-beautifulsoup-ed7db83d690?source=rss-2c6f21657997------2</link>
            <guid isPermaLink="false">https://medium.com/p/ed7db83d690</guid>
            <category><![CDATA[beautifulsoup]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[web-scrapers]]></category>
            <dc:creator><![CDATA[Ismail Gok]]></dc:creator>
            <pubDate>Wed, 16 Dec 2020 06:51:28 GMT</pubDate>
            <atom:updated>2020-12-21T17:48:31.856Z</atom:updated>
            <content:encoded><![CDATA[<p>Once I was developing a React Native Mobile App, I need tons of data serving my need from the “World Wide Web” and had very little time to get them. (No time to write with hand manually.) I have done some research as someone eager to learn new technologies, found the concept of Web Scraping. After more research, I give a Python Web Scraping library called BeautifulSoup a chance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dLbW76S3hEhmyNi2nSew6w.jpeg" /></figure><p>In this story, I will try to explain how to perform basic web scrapping using Python and BeautifulSoup library using my own code as an example.</p><p><em>A side note, Web scrapping is not illegal if you use it ethically. It should not be if you use the data that is already publicly available to all but beware of all the ethical aspects. I.e. causing an overload to a site’s bandwidth and disrupt its traffic due to too many web scrapper bots can have some illegal consequences.</em></p><p>Let’s first try to get familiar with the concept of Web Scraping, shall we? To keep this story short I will quote from Wikipedia, you can find <a href="https://en.wikipedia.org/wiki/Web_scraping#:~:text=Web%20scraping%2C%20web%20harvesting%2C%20or,or%20through%20a%20web%20browser.">the full version here.</a></p><blockquote><strong>Web scraping</strong>, <strong>web harvesting</strong>, or <strong>web data extraction</strong> is data scraping used for extracting data from websites. Web scraping software may access the World Wide Web directly using the Hypertext Transfer Protocol, or through a web browser. While web scraping can be done manually by a software user, the term typically refers to automated processes implemented using a bot or web crawler. It is a form of copying, in which specific data is gathered and copied from the web, typically into a central local database or spreadsheet, for later retrieval or analysis.</blockquote><p>Wikipedia says the term “<em>While web scraping can be done manually by a software user, the term typically refers to automated processes implemented using a bot or </em><strong><em>web crawler</em></strong><em>.</em>” It says web crawler here but I think we also should know the difference between web scraping and web crawling.</p><p>Simply,<strong> web scraping</strong> is the action of extracting data from websites in an automated manner. It’s a programmatic analysis of a web page to download information from it. Example: Let’s say you want to extract the price of a specific product from an e-commerce website. You code yourself a web scraper to get the HTML from the e-commerce website programmatically.</p><p>On the other hand,<strong> web crawling</strong> is often slightly different technique. It’s basically an internet bot that systematically browses (read crawls) the World Wide Web, usually for the purpose of web indexing. You load a seed URL to a crawler and it indexes every subdomain of that URL and copy the data for further analysis. Example: the search engines uses web crawling to index the everything on the internet.</p><p>After that basic introduction, we can move on to the coding example. This small application is developed in Python using BeautifulSoup library as the web scraping library.</p><p>First thing first. We need to import relevant libraries.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f962fc7ed8e13f86aa68c22ad8b5eb43/href">https://medium.com/media/f962fc7ed8e13f86aa68c22ad8b5eb43/href</a></iframe><p>Import <strong>BeautifulSoup</strong> in order to use the famous web scrapper library. Import <strong>urllib.request</strong> in order to open up HTTP requests to specific URLs. More detailed explanation: <a href="https://docs.python.org/3/library/urllib.request.html">https://docs.python.org/3/library/urllib.request.html</a>.</p><p>Further, import <strong>re</strong><em> </em>(used for regular expressions)<em> </em>or any other module if you need to parse data from URLs.</p><p>After the imports, the first thing to do is to get the main URL and open a connection to that URL. I wanted to store the data I got from the connection in a text file, so I open a file connection as well.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/83b3369b22d7a573447a59a86519beee/href">https://medium.com/media/83b3369b22d7a573447a59a86519beee/href</a></iframe><p>We have done no scrapping at this moment, only opened up a connection to a URL, read all the HTML data and closed the connection. Now, it is time to parse the HTML data and scrape some meaningful information out of them.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db694413803afec47160d3130ee648e9/href">https://medium.com/media/db694413803afec47160d3130ee648e9/href</a></iframe><p>The line of code above is very important in my experience. Most of the time, BeautifulSoup can figure out a site’s character encoding correctly, but sometimes it is not the case. Sometimes it cannot get the correct encoding and that caused me a lot of headaches. So, to be perfectly safe, I tell BeautifulSoup how he need to parse the HTML data from the URL with the code above. In most of the cases, the character encoding is UTF-8 and the data is in HTML format.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/51c8aa1b276055af5e2c1baf0a833209/href">https://medium.com/media/51c8aa1b276055af5e2c1baf0a833209/href</a></iframe><p>There are a bunch of different ways to identify your target html element like element tag name, id, class name, even with styles. I used some of these ways to get the data I need. I wanted to get all the rows from a specific table and I accessed the table using its element id. After that I accessed its ‘<em>tbody’ </em>using only the element name and got all the rows utilizing their ‘<em>tr</em>’ tags.</p><p>All the rows had URLs that link to website’s subdomain addresses. My main target was to traverse all the subdomains and get the desired data from the main tables in those subdomains.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56443fee125955eda7cd9943e19c7fcc/href">https://medium.com/media/56443fee125955eda7cd9943e19c7fcc/href</a></iframe><p>It is not always viable but here I could get the desired table rows by distinguishing them by their styles. I wanted to get all the table rows (‘<em>tr’</em>)if their ‘<em>style’ </em>attributes not equals to ‘<em>height: 46px’ (which was the height of table header). </em>Then I proceeded to getting values from each cell in desired table rows. Using <em>row.findAll(‘td’)</em> I have got all the cell in an array. After that, I accessed the ‘<em>a’</em> tag and then the ‘<em>href’ </em>tag of it and store them in an array called <em>allURLs</em>.</p><p>Now, I have got all the URLs of the subdomains. It was time to iterate over all the URLs and access the desired table data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b5a31270ff5a22dfa45ac95ca452697/href">https://medium.com/media/7b5a31270ff5a22dfa45ac95ca452697/href</a></iframe><p>After accessing all the ‘<em>td</em>’s in the table, I disregarded a specific column by checking its text value. The rest is applying some operations just to extract the meaningful data from the data I scraped. Lastly I closed the file reader and printed out a basic information message.</p><p>This was a quick introduction to web scrapping using Python’s BeautifulSoup library. There is a lot more to the library itself but even these few lines of code helped me to get almost 250 thousands of lines of meaningful data in few minutes. Web scraping is a powerful method to extract data from the web and it is quite useful in a lot of fields. There are other useful libraries other than BeautifulSoup too. I encourage you to check them out.</p><p>You can get the full source code of this basic POC here: <a href="https://github.com/ismailgok33/UniversityInfo-WebScrapper">https://github.com/ismailgok33/UniversityInfo-WebScrapper</a>. I hope this has been very helpful. Stay healthy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed7db83d690" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/web-scraping-example-in-python-using-beautifulsoup-ed7db83d690">Web Scraping Example in Python using BeautifulSoup</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RDBMS & NoSQL Database Scaling]]></title>
            <link>https://ismailgok.medium.com/rdbms-nosql-database-scaling-548716c2bb03?source=rss-2c6f21657997------2</link>
            <guid isPermaLink="false">https://medium.com/p/548716c2bb03</guid>
            <category><![CDATA[rdbms]]></category>
            <category><![CDATA[horizontal-scaling]]></category>
            <category><![CDATA[database-scalability]]></category>
            <category><![CDATA[nosql]]></category>
            <category><![CDATA[vertical-scaling]]></category>
            <dc:creator><![CDATA[Ismail Gok]]></dc:creator>
            <pubDate>Wed, 09 Dec 2020 13:46:43 GMT</pubDate>
            <atom:updated>2020-12-09T13:46:43.264Z</atom:updated>
            <content:encoded><![CDATA[<p>There are a huge amount of data is being generated every day by billions of people and they are stored in systems called databases. With a lot of data, the incoming traffic to those database systems are rapidly increasing.</p><p>Because of the huge number of traffic incoming to database systems, it is getting harder and harder to maintain the availability and performance high. There is a severe need of scaling the systems to make them highly available and high performant.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*ViN8jNwAtE-RdZzXaUVdDQ.jpeg" /></figure><p>This is a brief introduction about the general database scaling concepts . It will only scratch the surface of a vast and complicated subject.</p><p>A database needs to always be available, high performant and needs to minimally latent. The big companies with huge number of data can provide that with scaling their databases. There are mainly two types of scaling concepts that can be introduce on database system. Vertical Scaling and Horizontal Scaling.</p><h3>Vertical Scaling (Scale Up)</h3><p>Let’s say that you bought 10 oranges and a small basket to put them in from the market. When you got back home, you realized your wife also got 10 oranges but has no basket. Would you buy another small basket to put other 10 in or buy a bigger basket to put all 20 in?</p><p>If you consider getting a bigger basket to put all 20 of them in, you went for scaling vertically.</p><p>Let’s examine more technical example. You have a small company and you have a database server with 25GB of RAM to store all the data in. After some time, your company got bigger and your data got bigger with it. Now you database gets overwhelmed with the traffic incoming.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*F8OC-6WsMTfhnqiVP4BOxA.png" /></figure><p>In such a scenario, in order to scale your database system vertically, all you need to do is to get a bigger and faster database server.</p><h4>Advantages</h4><ul><li>Since there is only a single node of database, it is easy to implement.</li><li>The bigger is the server, the faster it gets. (performance-wise)</li></ul><h4>Disadvantages</h4><ul><li>It gets more expensive as your data largen.</li><li>Difficult to perform parallel operations.</li><li>Creates some risky situations when database server fails.</li></ul><h3>Horizontal Scaling</h3><p>Let’s remember the orange — basket case from above. You have 20 oranges in total and a small basket that can store 10 oranges at a time. You choose not to get a bigger basket with the capacity to store 20 oranges. Instead, you go and purchase another small basket. You now have two small baskets each can store 10 oranges. This is called horizontal scaling.</p><p>Now, we can examine the “more technical” scenario from before with this approach in mind. You have your company and you have a database server with 25GB of RAM to store all the data in. Your needs changed as before. But this time you chose not to buy a bigger database server, you chose to increase the number of servers to compensate the incoming traffic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*AOeSRmy_herYSAgdRqimQQ.png" /></figure><h4>Advantages</h4><ul><li>It is always the cheaper option compared to vertical scaling.</li><li>Has a better fault tolerance. Therefore the downtime would be significantly lower.</li><li>Easy to perform parallel tasks.</li></ul><h4>Disadvantages</h4><ul><li>More difficult to implement. Keeping the consistency between nodes is hard.</li><li>Not always ideal for RDBMS since the relations between data is difficult when the data is scattered over DB nodes.</li></ul><p>It is time to examine both scaling concepts and techniques further for both SQL and NoSQL databases.</p><h3>Scaling SQL Database Systems</h3><p>The Relational Databases by their very nature strictly follow the ACID properties. (You can find further information about ACID here: <a href="https://en.wikipedia.org/wiki/ACID">https://en.wikipedia.org/wiki/ACID</a>)</p><blockquote>In <a href="https://en.wikipedia.org/wiki/Computer_science">computer science</a>, <strong>ACID</strong> (<a href="https://en.wikipedia.org/wiki/Atomicity_(database_systems)">atomicity</a>, <a href="https://en.wikipedia.org/wiki/Consistency_(database_systems)">consistency</a>, <a href="https://en.wikipedia.org/wiki/Isolation_(database_systems)">isolation</a>, <a href="https://en.wikipedia.org/wiki/Durability_(database_systems)">durability</a>) is a set of properties of <a href="https://en.wikipedia.org/wiki/Database_transaction">database transactions</a> intended to guarantee data validity despite errors, power failures, and other mishaps. In the context of <a href="https://en.wikipedia.org/wiki/Database">databases</a>, a sequence of database operations that satisfies the ACID properties (which can be perceived as a single logical operation on the data) is called a <em>transaction</em>. For example, a transfer of funds from one bank account to another, even involving multiple changes such as debiting one account and crediting another, is a single transaction.</blockquote><p>The power of RDBMS’s comes from making relations between tables and always stay consistent. Hence(keeping ACID rules in mind) RDBMS’s are mostly scaled vertically. (More traffic equals bigger server!)</p><p>That does not mean that you cannot scale RDBMS’s horizontally. In order to perform horizontal scaling RDBMS’s are replicated with a method called Master-Slave Replication. Multiple Slave replicas has one master node. The true data is kept at the master node, thus writing only occurs there. The master performs and logs the writes and then passes the updated information to the slaves(replicas). Each slave node outputs a message stating that it has received the update successfully, thus allowing the sending of subsequent updates. Slave nodes can perform read actions any time to reduce the load on the master node. When the master node is down due to a failure, one of the slave nodes become the master node.</p><p>While the SQL database servers can scale horizontally like above, the tables can be scaled across those nodes as well. This operation is called <strong>Partitioning.</strong></p><blockquote>Partitioning is the database process where very large tables are divided into multiple smaller parts. By splitting a large table into smaller, individual tables, queries that access only a fraction of the data can run faster because there is less data to scan.</blockquote><blockquote>-www.sqlhack.com</blockquote><h4>Vertical Partitioning</h4><p>Vertical partitioning is a kind of partitioning that divides a table vertically. You divide a table logically and can access that specific part at once. It can be used in such scenarios when you don’t need to access all the data of a table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NBfQKeDyYb8ZNkprdxi55g.png" /></figure><h4>Horizontal Partitioning (Sharding)</h4><p>Horizontal partitioning is a kind of partitioning that divides tables horizontally. Horizontal partitioning divides a table into multiple tables that contain the same number of columns, but fewer rows.</p><p>For example, let’s say there is a big company data ordered by timestamps and the data is used for some analytical algorithm. If the data is commonly retrieved by its year, then it can easily be partitioned into more tables by years.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4jVLfVvm7x_EtxlfHfHpiA.png" /></figure><blockquote>Tables are horizontally partitioned based on a column which will be used for partitioning and the ranges associated to each partition. Partitioning column is usually a datetime column but all data types that are valid for use as index columns can be used as a partitioning column, except a timestamp column. The ntext, text, image, xml, varchar(max), nvarchar(max), or varbinary(max), Microsoft .NET Framework common language runtime (CLR) user-defined type, and alias data type columns cannot be specified.</blockquote><blockquote>-www.sqlhack.com</blockquote><h3>Scaling NoSQL Database Systems</h3><p>We talked about vertical and horizontal scaling in general and how to apply them onto SQL database systems so far. The next thing is how they are applied onto NoSQL database systems and which one is better on which scenarios.</p><p>Vertical scaling is the same. If you want to scale up, you need to get bigger servers. There is no magic here. The real challenge is to scale database systems horizontally. Which is almost always a better option when there are big data in hand.</p><p>Although horizontal scaling is almost always better than vertical scaling in most of the cases, we know that it is harder and riskier to apply on to database system because of the CAP theorem. You can find information about CAP theorem here: <a href="https://en.wikipedia.org/wiki/CAP_theorem">https://en.wikipedia.org/wiki/CAP_theorem</a></p><blockquote>In theoretical computer science, the <strong>CAP theorem</strong>, also named <strong>Brewer’s theorem</strong> after computer scientist Eric Brewer, states that it is impossible for a distributed data store to simultaneously provide more than two out of the following three guarantees:</blockquote><blockquote><em>Consistency</em>: Every read receives the most recent write or an error</blockquote><blockquote><em>Availability</em>: Every request receives a (non-error) response, without the guarantee that it contains the most recent write</blockquote><blockquote><em>Partition tolerance</em>: The system continues to operate despite an arbitrary number of messages being dropped (or delayed) by the network between nodes</blockquote><p>We are in luck though. Because NoSQL systems in their very nature are designed to scale horizontally. They are designed to address the scalability requirements that an ordinary SQL cannot address. Since they follow the <strong>de-normalization</strong> concept, there is no necessity for a single point of truth. It can store <strong>duplicates.</strong></p><p>Due to its architectural design, NoSQL database systems relies upon a softer model known as the BASE model instead of ACID model mentioned above in SQL part. You can find more information about <a href="https://www.freecodecamp.org/news/nosql-databases-5f6639ed9574/#:~:text=%E2%80%8CNoSQL%20relies%20upon%20a%20softer,Soft%20state%2C%20Eventual%20consistency).&amp;text=Eventual%20consistency%3A%20The%20system%20will,in%20return%20they%20improve%20scalability.">BASE model here</a>.</p><blockquote><strong>Basically Available:</strong> Guarantees the availability of the data . There will be a response to any request (can be failure too).</blockquote><blockquote><strong>Soft state</strong>: The state of the system could change over time.</blockquote><blockquote><strong>Eventual consistency:</strong> The system will eventually become consistent once it stops receiving input.</blockquote><blockquote>NoSQL databases give up the A, C and/or D requirements, and in return they improve scalability.</blockquote><p>Like RDBMS, replication is also used to scale NoSQL Database Systems horizontally. Since there is no single point of truth, in order to use master — slave architecture like in SQL, NoSQL systems use variety of different replication methods.</p><p>I will not explain each NoSQL database servers and their replication methods because It would make the article too long (since the main purpose of this article to introduce basic concepts of database scaling as plain as possible) instead I will list some of the commonly used NoSQL databases and their replication methods below.</p><p>Maybe the most common NoSQL database is <strong>MongoDB</strong>. You can find how MongoDB replicates its nodes to scale the database horizontally here: <a href="https://docs.mongodb.com/manual/replication/">https://docs.mongodb.com/manual/replication/</a></p><blockquote>A <em>replica set</em> in MongoDB is a group of <strong>mongod </strong>processes that maintain the same data set. Replica sets provide redundancy and high availability, and are the basis for all production deployments. This section introduces replication in MongoDB as well as the components and architecture of replica sets. The section also provides tutorials for common tasks related to replica sets.</blockquote><p>Another widely used NoSQL database is Apache’s famous <strong>Cassandra</strong>. You can find <a href="https://docs.apigee.com/private-cloud/v4.17.09/about-cassandra-replication-factor-and-consistency-level#:~:text=Cassandra%20stores%20data%20replicas%20on,ensure%20reliability%20and%20fault%20tolerance.&amp;text=A%20replication%20factor%20of%20one,is%20on%20a%20different%20node.">its replication method here.</a></p><p><strong>Couchbase </strong>is a both a document-typed and key-value typed NoSQL database and it has some different replication methods that you can find interesting.</p><p>This article is already longer that I intended it to be so I will not go in more detail about other specific databases. I hope this has been very helpful. Stay healthy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=548716c2bb03" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let’s Git Familiar — Part 1]]></title>
            <link>https://medium.com/swlh/lets-git-familiar-part-1-5de13a6ad7b5?source=rss-2c6f21657997------2</link>
            <guid isPermaLink="false">https://medium.com/p/5de13a6ad7b5</guid>
            <category><![CDATA[git]]></category>
            <category><![CDATA[version-control]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[Ismail Gok]]></dc:creator>
            <pubDate>Mon, 16 Nov 2020 21:28:45 GMT</pubDate>
            <atom:updated>2021-11-08T11:25:29.667Z</atom:updated>
            <content:encoded><![CDATA[<h3>Let’s Git Familiar — Part 1: Git Fundamentals</h3><p>This story is the first part of a series on Git Version Control System Fundamentals. If you want to proceed, you can find <a href="https://ismailgok.medium.com/lets-git-familiar-part-2-9657a2b80090">the second part of the series here.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Jl2VDHVzFBDdXggRprziUg.png" /></figure><p>Git is a free, open-source Distributed Version Control System (DVCS) and it keeps track of projects and files as they change over time with the help of different contributors. Git keeps track of the changes made to the code. So when a bug arrises you can see what stage of the development caused the bug and you can revert the change.</p><p>The major difference between Git and any other VCS’s like SVN is the way Git stores the data parts. Git doesn’t store the data like a regular file system. With every commit, Git captures the current Snapshot of the files and stores them. To be more efficient, if files have not changed, Git doesn’t store the file again, just a link to the previous identical file it has already stored.</p><p>This part is going to be only an introductory to Git ecosystem, the details of how Git works and all of the workflows will be mentioned in later writings. So now let’s go over the Git commands and how you use them briefly. By the way you surely can use any of the Git GUI application to handle Git commands but I strongly suggest you to at least learn the commands on terminal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*OqKfKe3mqCRbaWT2Y8YDOQ.png" /></figure><p>Almost every Git operation is done on the local machine. (That is one reason why Git is super efficient. The performans details will be on the later writings.)</p><p>Let’s review the basic commands that you will need when you start to use Git.</p><p>So let’s assume that you are working on a project. You created the bare project and wrote some code. Now it is time for you to use some Git magic. Open up your terminal and go to your project’s location.</p><pre><strong>cd/users/userName/myProject</strong></pre><p>First command is the initialization command. With it, you create your local Git repository and a file with .init extension is created.</p><pre><strong>git init</strong></pre><p>After that you can add your personel information to that git repository such as your e-mail address and your user name. (These are optional of course.)</p><pre><strong>Git config —global user.name ‘your user name’</strong></pre><pre><strong>Git config —global user.email ‘your e-mail address’</strong></pre><p>Important stuff! You add your files to your local git repository using <strong>git add &lt;file name&gt; </strong>command. Ex <strong>git add index.html </strong>If you want to add all files in your directory you can use <strong>git add .</strong> For example if you only want to add your html files to your local git repository you go with <strong>git add *.html</strong></p><pre><strong>git add index.html // </strong><em>adds index.html to local git repo</em></pre><pre><strong>git add *.html // </strong><em>adds all html files to local git repo</em></pre><pre><strong>git add . // </strong><em>adds all files to local git repo</em></pre><p>Now you keep track of every change you made on your local repository using <strong>git status </strong>command. It show you which files you added and which files you did not. It also notifies you if you made some changes on any added files. This command is your best buddy. You will use it a lot to know what is going on with the local repository.</p><pre><strong>git status</strong></pre><p>You used git status and you have seen some files you did not want to add to your local Git repository in the first place. You can undo that by <strong>git rm — cached &lt;file name&gt;</strong></p><pre><strong>git rm --cached index.html </strong>// <em>deletes index.html from git repo</em></pre><p>You often have some files you don’t need to version with Git and you don’t want to manually add or delete them over and over again. All you need to do is you create “<strong>.gitignore</strong>” file.</p><p>Let’s examine this with and example. You have a log file called “<em>Log.txt</em>”. It is very common not to version log files so you don’t want to add it to your repository. All you need to do is to open your <em>.gitignore</em> file and write one line: Log.txt . After that <strong>git add . </strong>adds all of your files to your local repository but <em>“Log.txt”</em>. Git excludes every file or directory in .<em>gitignore </em>file. (You place / before your directory name.)</p><p>This is the time for taking snapshots of your files on your local repository. <strong>Git commit </strong>does that for you. Write <strong>git commit -m ‘&lt;commit description goes here&gt;’ </strong>on your terminal and you get your first snapshot of your code files. (Or any other file for that matter.) After that whenever you make any changes on your files, you first write git add . To add all of them to local repository and use git commit -m ‘&lt;description&gt;’ to commit those changes.</p><pre><strong>git commit -m &#39;initial commit&#39;</strong></pre><p>So far you commit your changes but all of your files are still in your computer. You need to send them to a remote server for obvious reasons. Let’s say you or your team is using Github for Git VCS. For one time only you need to add your remote repository to your project. With <strong>git remote add origin https://github.com/user-name/project-name </strong>you add your GitHub repository as remote repository for your project. After that all you need to do to send your files to the remote repository with <strong>git push </strong>command. It will push your local repository to Master branch of your remote repository. <em>(No worries. Branching will be on the later writings.)</em></p><pre><strong>git remote add origin https://github.com/myUser/myAwesomeApp</strong></pre><p>You also get your projects latest version by writing <strong>git pull </strong>via your terminal. If you want to get a project from Github or any other Git based VCS servers, you use <strong>git clone &lt;git url of the project or ssh link&gt;</strong></p><pre><strong>git pull </strong>// Gets the latest snapshot from remote git repo to your                  // local repo</pre><pre><strong>git clone </strong><a href="https://github.com/myUser/myAwesomeApp.git"><strong>https://github.com/myUser/myAwesomeApp.git</strong></a><strong> </strong>// Clones the // app to your directory</pre><p>This story has became very long just with these basic commands. You can find more advance commands like branching, merging, creating pull requests, rebasing etc on later writings. You can also find information about some best practices about Git version control system such as Git Workflows on later writings as well. You can find <a href="https://ismailgok.medium.com/lets-git-familiar-part-2-9657a2b80090">the second part of the series here.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5de13a6ad7b5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/lets-git-familiar-part-1-5de13a6ad7b5">Let’s Git Familiar — Part 1</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>