<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Noaa Barki</title>
    <description>The latest articles on Forem by Noaa Barki (@noaabarki).</description>
    <link>https://forem.com/noaabarki</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F347836%2Fb1e93ac8-0eed-42c8-8a2f-cad99b199515.jpeg</url>
      <title>Forem: Noaa Barki</title>
      <link>https://forem.com/noaabarki</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/noaabarki"/>
    <language>en</language>
    <item>
      <title>Let's Go! Why Golang is the way to go :)</title>
      <dc:creator>Noaa Barki</dc:creator>
      <pubDate>Mon, 19 Dec 2022 10:08:34 +0000</pubDate>
      <link>https://forem.com/noaabarki/lets-go-why-golang-is-the-way-to-go--3a5g</link>
      <guid>https://forem.com/noaabarki/lets-go-why-golang-is-the-way-to-go--3a5g</guid>
      <description>&lt;p&gt;Not so long ago, while I was working on creating an outline for my upcoming Golang workshop one of my teammates came and asked me "Noaa, what is so special about Golang?". His question got me thinking “Why do I like this language so much?”, and I realized that I’m not really sure and maybe I don’t really understand Golang. So I decided to go on a new journey - my journey after the meaning of Golang. &lt;/p&gt;

&lt;p&gt;In this article, we are going to talk about How Golang was invented in the first place, what is so special about it, when you should use it and why for those use cases I believe that Golang language is the way to go 🙂&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Big thank you and credits to Karolina Rusinowicz, and Jacek Olszak who wrote &lt;a href="https://codilime.com/blog/why-golang-may-be-a-good-choice-for-your-project/"&gt;“Why Golang may be a good choice for your project”&lt;/a&gt;. I learned a lot and used your article as a resource.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What is Go?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Go was developed by Google in 2007.&lt;/li&gt;
&lt;li&gt;It was first released as an open source in 2009.&lt;/li&gt;
&lt;li&gt;Go was designed just for that: to run on multiple cores and it was built to support concurrency. Concurrency in Go is considered very cheap and easy.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;How Go was born?&lt;/strong&gt;
&lt;/h3&gt;




&lt;p&gt;A long time ago, in the early 2000, Google was growing exponentially. 📈 They grew so fast that they started to have a lot of scaling problems. They simply had too much of everything! Lots of software and systems, millions of lines of code being developed by hundreds of programmers, and finally lots of hardware on which all this software was launched.&lt;/p&gt;

&lt;p&gt;In addition to that, Google’s entire source code was stored in one monolithic repository and their build took &lt;strong&gt;a huge amount of time.&lt;/strong&gt; It was so long that to perform such a build, &lt;strong&gt;Google created its own build system to compile the code on many machines in parallel.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;But... despite all this and many other optimization efforts, the time needed to build certain systems reached several dozen minutes in 2007.  &lt;/p&gt;

&lt;p&gt;This became a problem for a lot of other companies besides Google... 🌍  &lt;br&gt;
At that time, multi-core processors became common and the infrastructure became much more scalable, dynamic, and had more capacity. Using cloud infrastructure with hundreds of servers with multiple processors to deploy applications became universal. However, back then code compilation (mainly in C++) lasted too long and coding with threads and memory sharing (in C++ and Java) to write concurrent code was considered too complicated. Programmers made a lot of mistakes, and the code was often not optimized. In most cases, a thread was left waiting—and gobbling up resources like RAM and CPUs.&lt;/p&gt;

&lt;p&gt;To solve this problem, &lt;strong&gt;alternative models of concurrent programming were created&lt;/strong&gt;. 💡 &lt;br&gt;
An asynchronous model used especially in Node.js is one of them. However, it wasn’t so Promising 🙃 &lt;strong&gt;it was still complex for programmers to use and even much more difficult to debug.&lt;/strong&gt; Additionally, there were many approaches to C++ and Java programming (which were the top languages for multi-threading) but none emerged as best-in-class. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This resulted in the code being difficult to manage and in needlessly long compilation times.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Fed up with these pitfalls, Googlers Robert Griesemer, Rob Pike, and Ken Thompson,  decided to create a new language. This language was supposed to increase the productivity of Google engineers and allow them to use the company’s huge hardware resources more effectively. Since the most widely used programming languages at Google were C++ (mainly for servers) and Java/Python (the rest of the code), this new language needed to be similar to them so that programmers could learn it easily.&lt;/p&gt;

&lt;p&gt;And this is exactly what they did. They wrote the code, published it as an open-source named &lt;strong&gt;Golang&lt;/strong&gt; and they lived happily ever after. 🌈&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Go?
&lt;/h3&gt;




&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;CONCURRENCY MADE EASY&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Go introduced an alternative model of concurrent programming, ****one based mainly on &lt;a href="https://en.wikipedia.org/wiki/Communicating_sequential_processes"&gt;CSP language&lt;/a&gt;. This new model introduced &lt;code&gt;goroutines&lt;/code&gt; which communicate with each other using &lt;code&gt;channels&lt;/code&gt;  (you can think about them as mailboxes). &lt;code&gt;goroutines&lt;/code&gt; had several advantages over threads and memory sharing, one of them was that they were easier to understand which made the code much more simple and safe.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;FAST PROGRAMS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Programs written in Go are executed fast and use little RAM. One reason why is because when Go code is compiled, it creates an executable file. This is not &lt;code&gt;bytecode&lt;/code&gt; or any other intermediary code, it’s &lt;em&gt;a machine code.&lt;/em&gt; 😎 Another reason is because of Go’s &lt;code&gt;goroutine&lt;/code&gt;. A &lt;code&gt;goroutine&lt;/code&gt; is a lightweight thread managed by Go runtime and it consumes fewer resources than threads in Operating Systems.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;FAST BUILD&lt;/strong&gt;&lt;br&gt;
Go’s compilation is very fast because Go was designed to enable its compiler to analyze dependencies quickly and avoid loading files repeatedly. Under the hood, Go, compiles the source code incrementally, creating an object file for every package. so when somebody uses a specific package, it loads the previously prepared file. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Local Setup
&lt;/h1&gt;

&lt;p&gt;In order to compile Go source code, Go requires two &lt;code&gt;.env&lt;/code&gt; variables exists, &lt;code&gt;$GOPATH&lt;/code&gt; and &lt;code&gt;$GOROOT&lt;/code&gt; →  &lt;code&gt;$GOPATH&lt;/code&gt; pointing to the directory where the Go source code exists, and &lt;code&gt;$GOROOT&lt;/code&gt; points to Go’s installation directory. &lt;/p&gt;

&lt;p&gt;💡 Go v1.11 does introduce the concept of &lt;a href="https://github.com/golang/go/wiki/Modules"&gt;modules&lt;/a&gt; that allows you to have your project code outside of your &lt;code&gt;GOPATH&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;After installing Go, you have to configure your workspace. &lt;/p&gt;

&lt;h3&gt;
  
  
  Workspaces
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;A Go workspace&lt;/strong&gt; is a directory stored on your local machine for your Go code. Go doesn’t require a special name or location for the workspace however, by default, Go expects all code to be in a single workspace. The reason why is for the compiler to operate at optimal efficiency. The path to your workspace should be stored in &lt;code&gt;$GOPATH&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Inside the workspace there must be 3 subdirectories named by convention:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;$GOPATH/src&lt;/code&gt;&lt;/strong&gt;  - for the code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;$GOPATH/pkg&lt;/code&gt;&lt;/strong&gt;  - stores archived files of packages installed in programs. This essentially helps to save compilation time based on whether the packages being used have been modified.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;bin&lt;/code&gt;&lt;/strong&gt;  - stores all the compiled binaries.&lt;/p&gt;

&lt;h2&gt;
  
  
  File structure
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;go.mod&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;package.json&lt;/code&gt; file for Go. &lt;br&gt;
Modules are the Golang support for dependency management. A module by definition is a collection of related packages with a &lt;strong&gt;&lt;code&gt;go.mod&lt;/code&gt;&lt;/strong&gt; file at its root. All the modules which are needed to be used in the project are maintained in &lt;code&gt;go.mod&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;&lt;code&gt;go.mod&lt;/code&gt;&lt;/strong&gt; file defines:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Module import path.&lt;/li&gt;
&lt;li&gt;The version of go with which the module was created&lt;/li&gt;
&lt;li&gt;Dependency requirements of the module for a successful build. It defines both projects’ dependencies requirements and also locks them to their correct version.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;go.sum&lt;/code&gt;&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;package-lock&lt;/code&gt; file for Go.&lt;/p&gt;

&lt;p&gt;This file contains all the project’s dependencies(a.k.a dependencies checksums) and it is managed by the go tools. &lt;/p&gt;

&lt;h3&gt;
  
  
  Packages
&lt;/h3&gt;

&lt;p&gt;A package is the entry point to access a Go code. All go code is organized into packages and it simply consists of several&lt;code&gt;.go&lt;/code&gt; files. You might be surprised to know that packages are the most powerful part of the Go language! (see “Why Go?. Fast Build” section).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Common packages structure&lt;/strong&gt; &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;/cmd&lt;/code&gt;&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;In general, this folder contains the main entry point files for the project, with the directory name matching the name for the binary. In our project, this folder contains the main commands entry points. Each directory name matches the name of the command.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;**/pkg**&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is the place to put public libraries. Usually, this may include API clients or utilities which may be handy for other projects but don’t justify their own project. The important thing to remember is that other projects might import these libraries, so we need to think twice when we make changes.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;/internal&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;internal&lt;/code&gt; directory is the place to put your private packages. If you put your code in an &lt;code&gt;internal&lt;/code&gt; directory no external project will be able to import that code. Any code that lives outside of &lt;code&gt;internal&lt;/code&gt; parent directory won’t be able to import this code. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://golang.org/doc/go1.4#internalpackages"&gt;Go 1.4&lt;/a&gt; introduces an ability to hide code using &lt;code&gt;internal&lt;/code&gt; directories. &lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Common best practices
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Go projects often keep the core types grouped at the top of a file.&lt;/li&gt;
&lt;li&gt;Organize code by responsibility, not by type.&lt;/li&gt;
&lt;li&gt;Package names are often single form, lowercase (not snake_case or camelCase).&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>How To Fine Structure Your Project</title>
      <dc:creator>Noaa Barki</dc:creator>
      <pubDate>Wed, 14 Oct 2020 23:06:10 +0000</pubDate>
      <link>https://forem.com/noaabarki/how-to-fine-structure-your-project-9ok</link>
      <guid>https://forem.com/noaabarki/how-to-fine-structure-your-project-9ok</guid>
      <description>&lt;p&gt;Before we begin I'd like to ask you a question- when you are about to go on a trip, how do you pack your suitcase? Do you separate the shirts from the pants? Do you use some sort of organizers for your clothes or you just fold everything into one big pile?&lt;/p&gt;

&lt;p&gt;The reason I'm asking you this is because a few months ago, during a code review session, my teammates and I argued about how we should separate a certain logic between the files in the project. We argued about it for some time until Guy, one of teammates, stood up and asked me: &lt;em&gt;"When you pack a suitcase for a trip, do you put your swimsuit along with your undergarments or inside a separate bag?"&lt;/em&gt; my answer was immediate - a separate bag of course - but just like in a Disney movie Guy's question took me 9 years back in time when my family and I had a family trip to Eilat and I had to share a suitcase with my older brother. Back then I wasn't as sophisticated as I am today with my dedicated organizers and I did not know how to keep the suitcase organized throughout the trip. I remember how quickly everything in the suitcase got messed up and how after two days(!!!) I found myself re-inventing new rules for the suitcase organization's sake.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fldidy7lhbuvxl7n5ys8i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fldidy7lhbuvxl7n5ys8i.png" alt="How I backpack my suitcases since Eilat"&gt;&lt;/a&gt;&lt;/p&gt;
How I backpack my suitcases since Eilat



&lt;p&gt;Recently, I got to plan the file structures of several projects  - one of them was our frontend project and the rest were our backend services. These golden opportunities gave me a chance to research and understand what is, in my opinion, the right way of organizing a project's file structure.&lt;/p&gt;

&lt;p&gt;In this article, I'd like to share with you why I think that your project files structure is one of the most important parts of your projects and my personal guidelines on how to build a files structure that I believe can improve the efficiency of the code and eventually lead to a healthier and faster development cycle. 🧘🏼‍♀️&lt;/p&gt;

&lt;h2&gt;
  
  
  Why
&lt;/h2&gt;

&lt;p&gt;The main reason I love planning files structures is that it's like putting my application under the microscope, it enforces me to know which parts of the code can be grouped and which parts can work as independent units, what is stateless, what are the data flows and last but not least, what is my domain. It is almost like running my application through an MRI scan 😅 and knowing the answers to these questions significantly affected my understanding of the project and the application.&lt;/p&gt;

&lt;p&gt;I believe that establishing a proper file structure is just like embracing code style and design patterns -  it can clarify the dependencies and responsibilities of each file and part of the code and make the code more clear and efficient. From my experience, an organized file structure enables quick entry for new developers to the project and an optimal environment for fast development and delivery speed.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Organize File structure
&lt;/h2&gt;

&lt;h3&gt;
  
  
  The 3 goals
&lt;/h3&gt;

&lt;p&gt;When I think about the ultimate file structure I imagine a structure which consists these 3 main goals: &lt;/p&gt;

&lt;h4&gt;
  
  
  Easy to maintain
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Easy to file and easy to find&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The ultimate way to test how "good" your file structure is to check how long it takes(for newbies👶🏼 and seniors👴🏼) to find a particular file in the project - the less it takes the more efficient it is. Keep in mind that file structure becomes powerful when there's no need to remember anything, ideally, it just needs to make sense so that unconsciously we know where every file is or where it belongs.&lt;/p&gt;

&lt;h4&gt;
  
  
  Reflects the application
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Correct file structure tells the story of the application&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I believe that every application has a story to tell, what its domain is, which features it holds, what layers it contains and what are the interactions between them, use the files structure like it was the index of that story's book - try to specify the logical structure of the data and the relationships between the application's components. This can help to define the data flows more clearly and especially needed when collaborating with others. 🤝&lt;/p&gt;

&lt;h4&gt;
  
  
  Make the best sense for the team
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;The one that would make the best sense for the teams is the best solution.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Whether you are working in squads or teams, guild or chapters, conformant the file structure with your organization improves the scalability of the application, especially in smaller companies. One key reason for that is that as your company grows you want to expand and grow easily while continue to move fast and deliver, for that you need to maintain the application flexible and more adapted to organizational changes. For example, a company that works with squads might separate the application's project by features, on the other hand, a company with developers working on different technologies(front-end and back-end developers) organizing the projects by type which is easier to classify, back up, and migrate might be more suitable. &lt;/p&gt;




&lt;p&gt;However, knowing what to aim for wasn't enough, I still needed some guidelines and standards so I decided to try analyzing what exactly guides me during the process of planning a file structure. &lt;/p&gt;




&lt;h2&gt;
  
  
  The 5c's - 5 key principles for a proper structure 
&lt;/h2&gt;

&lt;p&gt;For a few months, while working on the file structure of several projects, I tried to figure out what is actually the thought process I do to build the structure for a project.  I wrote down all my thoughts and concerns, the questions I asked and the answers I got until I finally came out with these 5 key principles:&lt;/p&gt;

&lt;h3&gt;
  
  
  👓 Clear
&lt;/h3&gt;

&lt;p&gt;Think about your files and folders' names, keep it short(less than 25 characters) unique and meaningful so that the next developer will intuitively understand what are the responsibilities of that file and what it contains. I recommend to think about the file's names as keywords, based on their folder names. For example, inside folder called &lt;code&gt;services&lt;/code&gt; I would expect to see &lt;code&gt;userService&lt;/code&gt; and not &lt;code&gt;user&lt;/code&gt;. Moreover, if I read a file with the name &lt;code&gt;userService&lt;/code&gt; I would ultimately guess it's inside &lt;code&gt;services&lt;/code&gt; folder.&lt;br&gt;
This will save you a lot of time when you need to modify your files or navigate in your file structure. &lt;/p&gt;

&lt;h3&gt;
  
  
  🐾 Consistent 
&lt;/h3&gt;

&lt;p&gt;Choose a naming convention and follow them consistently, this will automate your workflows and save you time by keeping your code organized and understandable. &lt;/p&gt;

&lt;p&gt;Examples:&lt;br&gt;
• Angular: &lt;code&gt;{fileName}.{type:component|service|test…}.{format:ts|css…}&lt;/code&gt;&lt;br&gt;
• Go: files and folders names should &lt;code&gt;camleCase&lt;/code&gt; based on what they are or what they do and &lt;code&gt;{fileName_test}.go&lt;/code&gt; for test files. &lt;br&gt;
• React: UI components should be &lt;code&gt;PascalCase&lt;/code&gt; and  &lt;code&gt;{ComponentName}.test&lt;/code&gt; for test files.&lt;br&gt;
• Java/C#: each file name should consist of the case-sensitive name of the top-level class it contains, plus the &lt;code&gt;.java&lt;/code&gt; extension.&lt;/p&gt;

&lt;p&gt;🌼 This is the pattern that I use for most of the projects:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fn4ja26u85kevzgdxz65n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fn4ja26u85kevzgdxz65n.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I like to think that I took the best from every technology 😊&lt;/p&gt;

&lt;h3&gt;
  
  
  💎 Concise 
&lt;/h3&gt;

&lt;p&gt;Avoid overlapping and don't let your structure get too deep, it makes it harder to write relative imports or move files between places but mostly takes out the grouping context from a grouped files. A rule of thumb that I personally use - when your structure's nesting exceeds 3 levels you are probably gone too deep buddy 😏&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fbcirjqgf87bw3r53zgn2.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fbcirjqgf87bw3r53zgn2.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  ✔️ Correct
&lt;/h3&gt;

&lt;p&gt;Group all files and place them in your structure as they exist. &lt;/p&gt;

&lt;p&gt;Let's break this down:&lt;/p&gt;

&lt;p&gt;(i) "…group all files" - it can be by feature or by type of layer(such as service, controller, component, or stand-alone-scripts)- feel free to choose whatever works the best for you but follow it on the entire project.&lt;/p&gt;

&lt;p&gt;Personally, in most cases and especially in front-end projects, I prefer to group the files by feature so that every feature-folder is an independent unit like a lego brick. One key reason for that is that I believe that people work on features and not on types of files, when I close my eyes and imagine my application I think about its views and the features it holds. The second reason is that I was surprised to find out how to modularize the project by features encourage everyone on the team to think about modeling the entities, the layers, inverting dependencies, decoupling code, and define flows in the application. 😌 &lt;/p&gt;

&lt;p&gt;Here is an example of a React project where the items are &lt;br&gt;
grouped by feature:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F37yzcrg9irqu3c7hugog.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F37yzcrg9irqu3c7hugog.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;dashboard&lt;/code&gt; and &lt;code&gt;marketplace&lt;/code&gt; folders are both features in the application and each one contains its required internal items such as components, services, routes, etc.&lt;/p&gt;

&lt;p&gt;For further reading about folder-by-feature, I recommend reading &lt;a href="https://timgthomas.com/2013/10/feature-folders-in-asp-net-mvc/" rel="noopener noreferrer"&gt;Tim G. Thomas's article&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;(ii) "…place them in your structure as they exist " - &lt;/p&gt;

&lt;p&gt;Use your file structure to reflect the architectural relationship between the components(features, types, etc…). &lt;br&gt;
When I'm about to place items in the project I try to find which feature or layer in the architecture this component belongs to, what its scope, is there any architecture restrictions from or of that item?  &lt;/p&gt;

&lt;p&gt;Let's take for example the following snippet from a simple backend Node.js project:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fom052xyuztj0ubj9axur.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fom052xyuztj0ubj9axur.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see in this project the items are group by type and the code is separated into 3 architectural layers: services, stores, and controllers. To reflect the architecture-relationship between the layers, I placed &lt;code&gt;someEntityModel&lt;/code&gt; inside its own parent - &lt;code&gt;someEntity&lt;/code&gt;- store folder because &lt;code&gt;someEntityStore&lt;/code&gt; is the only one who deals with &lt;code&gt;someEntity&lt;/code&gt; 's logic, placing it outside of this folder might imply that another store can import it and I didn't want that. On the other hand, all the stores can import &lt;code&gt;db.ts&lt;/code&gt;, therefore it should be placed in the store's folder as a sibling to all the stores. &lt;/p&gt;

&lt;p&gt;Now, you probably think that making sure you placed a file in the right place can be sometimes very confusing. A rule of thumb that I personally use is to ask myself &lt;em&gt;"Which files can import it?"&lt;/em&gt; if my answer is either parent of the file/sibling of the file/I placed it in a dedicated well organized shared folder everything is ok, my file structure is aligned, everything is in its right place and I can keep on rocking it 🤓🤟🏻&lt;/p&gt;

&lt;h3&gt;
  
  
  💼 Conformant to the company workflows
&lt;/h3&gt;

&lt;p&gt;Develop a folder structure that makes the most sense for your project or team, the best folder structure is the one that mimics the way you think.&lt;/p&gt;

&lt;h2&gt;
  
  
  🌸 Summary
&lt;/h2&gt;

&lt;p&gt;I started my journey in the beloved arms of .NET framework and Angular, over the years I switched to React, Java, Node.js even Go. If you ask me, you can't take the framework out of a developer, you can leverage it 😌 and maybe the lack of "strict structure" is what made me so passionate about finding guidelines and standards in the first place.&lt;/p&gt;

&lt;p&gt;This research gave me a lot of knowledge about the importance of file structure, how to structure and develop applications but mainly it showed me that I shouldn't look for &lt;em&gt;"The One"&lt;/em&gt;, there isn't one structure to rule them all like there's no one way to backpack your suitcase.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fbey8jy2fhlafxoz2avbb.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fbey8jy2fhlafxoz2avbb.jpg" alt="My Daily Bag"&gt;&lt;/a&gt;&lt;/p&gt;
My current daily bag



&lt;p&gt;Finding the right file structure is like choosing and backpacking your bag, the one that would make the best sense is the best solution.&lt;/p&gt;

&lt;p&gt;I hope my experience will inspire you to explore your projects and who knows maybe to find new ways of backpacking a suitcase 🙌🏻.&lt;/p&gt;

&lt;p&gt;Special thanks to Guy Warburg and the rest of my teammates at &lt;a href="https://www.datree.io/" rel="noopener noreferrer"&gt;datreeio&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Git Bisect — And Debugging Is Easy</title>
      <dc:creator>Noaa Barki</dc:creator>
      <pubDate>Mon, 25 May 2020 23:31:22 +0000</pubDate>
      <link>https://forem.com/noaabarki/git-bisect-and-debugging-is-easy-4706</link>
      <guid>https://forem.com/noaabarki/git-bisect-and-debugging-is-easy-4706</guid>
      <description>&lt;p&gt;Once upon a time, there was a young developer who worked on a small side project, after a few hours he created a working version and started to refactor the code to make it nice, tidy, and clean. He refactored the code for a couple of hours and kept working neatly in small and meaningful commits. When he was pleased with his work he ran the code again but oh no, something terrible happened… the code didn’t work.&lt;/p&gt;

&lt;p&gt;We have all been there, for me it happened a week ago, I sat in my bed and stared at my IDE rat me out that it was I who wrote that buggy code, &lt;em&gt;“I got only myself to git blame that’s for sure”&lt;/em&gt; I grinned with myself but after a second a light bulb popped with a new idea — 💡 &lt;strong&gt;what if I can use Git to traverse through all of my commits and hunt down my bug&lt;/strong&gt;? fortunately, after a short search on Google I discovered that it is possible - using the simple git bisect command.&lt;/p&gt;

&lt;p&gt;In this tutorial, we will explore the &lt;code&gt;git bisect&lt;/code&gt; command. How it works, why, and how to use it so hopefully you will find it useful and powerful as I do!&lt;/p&gt;

&lt;h2&gt;
  
  
  🔮Debugging with Git
&lt;/h2&gt;

&lt;p&gt;As you may know for git everything is about commits, a branch for that matter is nothing but a pointer to a single commit. This allowed git to traverse through the commits and provide a couple of debugging tools to help us debug our code: File Annotation(a.k.a ‘git blame’) and Binary Search.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you’d like to learn more about how git works under the hood and stores its data check out my recent &lt;a href="https://medium.com/@noabarki76/dont-underestimate-the-push-force-5cba944a246d"&gt;article&lt;/a&gt; and &lt;a href="https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell"&gt;git documentation&lt;/a&gt; for further reading.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  File Annotation — git blame
&lt;/h4&gt;

&lt;p&gt;File annotation shows the last commit to modify each line of any file and done using the &lt;code&gt;git blame&lt;/code&gt; command, this is often the most useful tool for tracking down a bug and know who is the one to blame. If you are not familiar with git’s file annotation I highly recommend you read about it form git &lt;a href="https://git-scm.com/docs/git-blame"&gt;documentation&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Binary Search — git bisect
&lt;/h4&gt;

&lt;p&gt;A way to locate which commit introduced an issue using binary search through all the commits history of a particular branch. It’s done with the &lt;code&gt;git bisect&lt;/code&gt; command which checks out each commit allowing you to run a test to see if the issue exists in this commit. When you’re hunting down a bug but you don’t know where to look for it and there were hundreds of commits since the last good commit you remember - the &lt;code&gt;git bisect&lt;/code&gt; command is your answer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--01cr37de--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lijckfem415xnp6h6eoz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--01cr37de--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lijckfem415xnp6h6eoz.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  📽 Simple Scenario
&lt;/h2&gt;

&lt;p&gt;Let’s say you worked on a new branch…&lt;/p&gt;

&lt;p&gt;🥳 You worked for some time until you finally reach a good point with a good working product.&lt;/p&gt;

&lt;p&gt;😌 You are also a responsible developer who wishes to keep his tree clean so you probably added a few commits along the way and had the following commits history:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;*-----*--*---271cb1c (current)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;💎 You decided it’s time to start refactoring the code, make it nicer and clean, eventually you ended up with the following commits history:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;*-----*--*---271cb1c-*-66e0075-*-...--*---9c07a95 (current)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;😰 Unfortunately, your code isn’t working properly at the current commit, apparently somewhere along the way a part of the code got broken.&lt;/p&gt;

&lt;p&gt;🧐 You know that it had definitely worked before the refactor — when you added commit &lt;code&gt;271cb1c&lt;/code&gt; — meaning there is a bug in the code between commit &lt;code&gt;271cb1c&lt;/code&gt; and &lt;code&gt;9c07a95&lt;/code&gt;, the only question is…. How do you find it?&lt;/p&gt;

&lt;p&gt;👑 Enter &lt;code&gt;git bisect&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  🛠 How to use it
&lt;/h2&gt;

&lt;p&gt;Inspired by Clint Eastwood I like to think about this part as the story of ‘The Good, the Bad and the Wizard’:&lt;/p&gt;

&lt;h4&gt;
  
  
  🧙🏼‍♂️ The Wizard
&lt;/h4&gt;

&lt;p&gt;Run the &lt;code&gt;git bisect start&lt;/code&gt; command to startup the &lt;code&gt;git bisect&lt;/code&gt; wizard.&lt;/p&gt;

&lt;h4&gt;
  
  
  😈 The Bad
&lt;/h4&gt;

&lt;p&gt;In &lt;code&gt;git&lt;/code&gt; the binary search works by repeatedly dividing in half the commits that could contain the bug and narrowing down the possible commits to one, this makes the scope of the search essential. The way to define the &lt;code&gt;git bisect&lt;/code&gt; wizard what is the searching scope is by running the &lt;code&gt;git bisect bad&lt;/code&gt; command which tells &lt;code&gt;git&lt;/code&gt; that the &lt;code&gt;current&lt;/code&gt; commit is broken and contains a contagious bug.&lt;/p&gt;

&lt;h4&gt;
  
  
  😇 The Good
&lt;/h4&gt;

&lt;p&gt;The bad commit is only one end of the scope now we need to tell &lt;code&gt;git&lt;/code&gt; when the last known good commit was, we do that by running git bisect &lt;code&gt;&amp;lt;good_commit&amp;gt;&lt;/code&gt; command, for example in our case, the good commit was commit &lt;code&gt;271cb1c&lt;/code&gt; so we’ll run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git bisect 271cb1c
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;After running this command &lt;code&gt;git&lt;/code&gt; will start checkout commits using binary search and allow at each commit to build the app and check whether or not the bug exists, all left for you to do is to make sure you tell &lt;code&gt;git&lt;/code&gt; the status of the last &lt;code&gt;git bisect&lt;/code&gt; command with either &lt;code&gt;git bisect bad&lt;/code&gt; or &lt;code&gt;git bisect good&lt;/code&gt; so it will continue to narrow down the possible commits, repeat until it finds the commit where the bug was introduced.&lt;br&gt;
Let’s assume we checked out on commit &lt;code&gt;66e0075&lt;/code&gt; and that we found out that the bug occurred before it so we run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git bisect bad
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  🙌🏻 Git is kind
&lt;/h4&gt;

&lt;p&gt;Now &lt;code&gt;git&lt;/code&gt; has all it needs to determine that the commit between commit &lt;code&gt;66e0075&lt;/code&gt; and commit &lt;code&gt;271cb1cis&lt;/code&gt; the commit where the bug introduced. When &lt;code&gt;git&lt;/code&gt; finally finds the commit with the bug it prints all the information it has about it to help you figure out what happened that may have introduced this bug, for instance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git bisect bad
66e00756e887030abcbde19ac3e10a7c2942036a is the first bad commit
commit 66e00756e887030abcbde19ac3e10a7c2942036a
Author: Noaa Barki &amp;lt;noaa@datree.io&amp;gt;
Date:   Sun Apr 26 12:10:56 2020 +0300
fix: added client
base/client.go                              
base/client_test.go                          
1 files changed, ......
 create mode 100644 base/client_test.go
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  🧙🏼‍♂️The Wizard
&lt;/h4&gt;

&lt;p&gt;Like every time-travel journey its important to go back to where it all began otherwise we might be checked out on a commit from the past and end up in a weird branch state. We go back to the present by running the simple &lt;code&gt;git bisect reset&lt;/code&gt; command which shuts down the &lt;code&gt;git bisect&lt;/code&gt; wizard and reset the &lt;code&gt;HEAD&lt;/code&gt; to where we were before we started.&lt;/p&gt;

&lt;h2&gt;
  
  
  🤖 Automation
&lt;/h2&gt;

&lt;p&gt;This is the part when &lt;code&gt;git bisect&lt;/code&gt; really shines - one of &lt;code&gt;git bisect&lt;/code&gt; subcommand is the &lt;code&gt;git bisect run&lt;/code&gt; which accepts a command as an argument and allows to fully automate &lt;code&gt;git bisect&lt;/code&gt;!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git bisect run &amp;lt;cmd&amp;gt;...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;After running this command &lt;code&gt;git&lt;/code&gt; automatically runs &lt;code&gt;cmd&lt;/code&gt; on each checked-out commit and uses the return value of that call to decide if the commit is good or bad until it will find the first broken commit.&lt;/p&gt;

&lt;h4&gt;
  
  
  How to use it
&lt;/h4&gt;

&lt;p&gt;First, you tell &lt;code&gt;git&lt;/code&gt; the scope of the bisect by providing the bad and good commits:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git bisect start &amp;lt;bad_commit&amp;gt; &amp;lt;good_commit&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then you &lt;code&gt;git bisect run&lt;/code&gt; with your command and let &lt;code&gt;git&lt;/code&gt; do all the work for you, for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git bisect start HEAD 991debbc8b9e05ddc217023a898109822a70dd60
$ git bisect run npm run test
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The command can be any script that will exit 0 for “good commit” or non-0 “bad-commit”.&lt;/p&gt;

&lt;h2&gt;
  
  
  🌸 Summary
&lt;/h2&gt;

&lt;p&gt;In this tutorial, you learned how to track down a bug using the &lt;code&gt;git bisect&lt;/code&gt; command. Moreover, you learned how to automate it and by that reduce debugging time significantly. I hope you’ll try &lt;code&gt;git bisect&lt;/code&gt; in the future when you’ll look for a nice solution for hunting down a bug.&lt;/p&gt;

&lt;p&gt;Special thanks for my teammates at &lt;a href="https://datree.io/"&gt;datreeio&lt;/a&gt; 🙏🏻&lt;/p&gt;

</description>
      <category>github</category>
      <category>git</category>
    </item>
  </channel>
</rss>
