<?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>DEV Community: Mohamed Allam</title>
    <description>The latest articles on DEV Community by Mohamed Allam (@mohamedallam).</description>
    <link>https://dev.to/mohamedallam</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%2F675108%2F62b8faf9-eaa1-4117-81f3-3cb97a328aa9.png</url>
      <title>DEV Community: Mohamed Allam</title>
      <link>https://dev.to/mohamedallam</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mohamedallam"/>
    <language>en</language>
    <item>
      <title>Physical vs Logical vs Abstract Data Types (DST) and data structure (DS)</title>
      <dc:creator>Mohamed Allam</dc:creator>
      <pubDate>Sat, 17 Dec 2022 00:51:42 +0000</pubDate>
      <link>https://dev.to/mohamedallam/physical-vs-logical-vs-abstract-data-types-dst-and-data-structure-ds-57pa</link>
      <guid>https://dev.to/mohamedallam/physical-vs-logical-vs-abstract-data-types-dst-and-data-structure-ds-57pa</guid>
      <description>&lt;h2&gt;
  
  
  Physical vs Logical vs Abstract Data Types (DST) and data structure (DS)
&lt;/h2&gt;

&lt;p&gt;All computer science is about abstraction as everything is binary, and thats why its sometimes hard to learn, lets break down this terminology.&lt;/p&gt;

&lt;h2&gt;
  
  
  Abastract data types
&lt;/h2&gt;

&lt;p&gt;Also known as ADT, lets start our discussion about the primitives or scalar types.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Abstract data types is abstracting away 0 and 1 from us,&lt;/li&gt;
&lt;li&gt;Representation and operations, each data types, is represented in some specific way, and can have a set of operations to it.

&lt;ul&gt;
&lt;li&gt;16 bit intger is 15 bit of 1 and 0, and the left most bit is wether its a signed or unsigned integer.&lt;/li&gt;
&lt;li&gt;Arthmetic Operations can be done on integers addition, subtraction, multiplication division modulos

&lt;ul&gt;
&lt;li&gt;Relational operations, less than greater than, increment than decrement..ect&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;/li&gt;

&lt;li&gt;Primitives or scalar types, is the programming language provided types, like integers, strings, floats..ect&lt;/li&gt;

&lt;li&gt;We dont concern our selves too much how internally this operations are performed.&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;When we learn programming languages, we mostly learn about representation of data, mostly scalar types, or primitive types and the operations we can do to them.&lt;/p&gt;

&lt;p&gt;So the concept of representation and definition of data, and operations on the. while hiding the internal details is in essence abstract data types&lt;/p&gt;

&lt;p&gt;For example in programming languages, we define classes, which has objects, and we give those special behaviours and different details, this is how we define them and there operations. for example we can create a class of linkedlists, with different operations&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add(element, index) or inserrt(element, index)&lt;/li&gt;
&lt;li&gt;Append(element)&lt;/li&gt;
&lt;li&gt;Remove(element)&lt;/li&gt;
&lt;li&gt;Set(element)&lt;/li&gt;
&lt;li&gt;Get(index)&lt;/li&gt;
&lt;li&gt;Search(key)&lt;/li&gt;
&lt;li&gt;Sort()&lt;/li&gt;
&lt;li&gt;….&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is how we create our own abstract data types, but the thing is, there is some very known and efficient data types, we call them data structure, they allow us to efficiently utilize the resources, the main memory in the most ideal way, and we extend the programming languages to perform what we want us, us developers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Physical data structure
&lt;/h2&gt;

&lt;p&gt;Data structure is collection of data structure, so multiple data stored together.&lt;/p&gt;

&lt;p&gt;This data structure defines how memory is allocated, they define how the memory will be organized in order for them to store the data.&lt;/p&gt;

&lt;h3&gt;
  
  
  Arrays
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Most programming languages supports arrays&lt;/li&gt;
&lt;li&gt;its a collection of memory allocation, side by side, back to back.&lt;/li&gt;
&lt;li&gt;Arrays are fixed size, or arrays size is static, we cannot increase or decrease an array size after its creation, we can only assign to it, or desctruct it (deallocate the memory)&lt;/li&gt;
&lt;li&gt;Arrays can be created in the stack or the heap, we use a pointer to allocate arrays in the heap.&lt;/li&gt;
&lt;li&gt;We use arrays when we know the maximum number of elements we need&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Linedlist
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Lined lists are dynamic by nature, you can add more elements or delete them.&lt;/li&gt;
&lt;li&gt;its a collceiton of data, where each piece is called a node&lt;/li&gt;
&lt;li&gt;Each node holds data, and a pointer to the next node.&lt;/li&gt;
&lt;li&gt;Lined lists live in the heap, the head pointer can be in the stack.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Logical data structure
&lt;/h2&gt;

&lt;p&gt;This data structure, are an abstraction over the physical datastructure, Physical data structure store the data in memory, physically, but the logical data strucutre is the protocol, the discipline or the set of rules and policies we use to use the physical data structures in way we want for better organiztion of our data.&lt;/p&gt;

&lt;p&gt;All operations we do to this data structure are defined also by the logic we set. the API.&lt;/p&gt;

&lt;p&gt;This data structure can be split into two types, linear data structure, and non linear data structure.&lt;/p&gt;

&lt;h3&gt;
  
  
  Linear data sturcture
&lt;/h3&gt;

&lt;p&gt;linear data structure include&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stack (LIFO)&lt;/li&gt;
&lt;li&gt;Queue (FIFO)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Non linear data structure
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Tree&lt;/li&gt;
&lt;li&gt;Graph&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Tabluar
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Hash tables&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Big O notatian
&lt;/h2&gt;

&lt;p&gt;Its how we analyse algorithms and operations on them, how efficient they are specially when we approach infinity. in respect of N input.&lt;/p&gt;

&lt;h3&gt;
  
  
  Time complexity
&lt;/h3&gt;

&lt;p&gt;To measure the performance of our data structure, our job is to find out how much work we do per N elements, means for example if to find a word in a dictionary takes you iterating through every single word, means thats Order of N, if you can find the word by just looking at a fraction of the book or a subset, there is high chances, its a log to the two of N, so time complexity is always in respect of our input, or how much element exists in the data we are working with, the job is not to find the exact time it takes, because that varies from machine to machine or from buzy processors to another..ect&lt;br&gt;
Our job is to find the least amount of time we need to process N elements, we analyse the behaviour, how much more time we need to get the task done. a behaviour not an exact time.&lt;/p&gt;

&lt;h3&gt;
  
  
  Space complexity
&lt;/h3&gt;

&lt;p&gt;Many times, when we do something, we need extra memory than what we are working with, so in that case, we would have to consider that, because we dont always have extra memory, so thats the memory complexity it can be order of N or less or more, depends on the data type or algorithm we are working with.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.bigocheatsheet.com/" rel="noopener noreferrer"&gt;https://www.bigocheatsheet.com/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www-cs-faculty.stanford.edu/~knuth/taocp.html" rel="noopener noreferrer"&gt;https://www-cs-faculty.stanford.edu/~knuth/taocp.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Big_O_notation" rel="noopener noreferrer"&gt;https://en.wikipedia.org/wiki/Big_O_notation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>watercooler</category>
    </item>
    <item>
      <title>Trees data structure with types (uses cases included)</title>
      <dc:creator>Mohamed Allam</dc:creator>
      <pubDate>Sat, 10 Dec 2022 09:40:07 +0000</pubDate>
      <link>https://dev.to/mohamedallam/trees-data-structure-with-types-uses-cases-included-p8o</link>
      <guid>https://dev.to/mohamedallam/trees-data-structure-with-types-uses-cases-included-p8o</guid>
      <description>&lt;h2&gt;
  
  
  Whats a tree
&lt;/h2&gt;

&lt;p&gt;A tree is a collection of nodes, each node holds some data, one of the nodes is the root node, and other nodes. are disjoints subsets and each subset is a tree or a sub tree.&lt;/p&gt;

&lt;p&gt;Each node has exactly one parent, and can have one or more children, no single node has more than one parent.&lt;/p&gt;

&lt;p&gt;Trees are everywhere:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you wrote any switch statement but didnt knew why its more efficient than a bunch of if-else statements, &lt;a href="https://en.wikipedia.org/wiki/Lookup_table"&gt;the answer is Look up tables (LUT) which may use BST&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Operating systems use trees for &lt;a href="https://en.wikipedia.org/wiki/File_system"&gt;File system&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;The syntactic representation of a programming language is Abstract syntax tree. &lt;a href="https://en.wikipedia.org/wiki/Abstract_syntax_tree"&gt;AST&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Browser Document object model (&lt;a href="https://en.wikipedia.org/wiki/Document_Object_Model"&gt;DOM&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Databases use Log structured merge tree. &lt;a href="https://en.wikipedia.org/wiki/Log-structured_merge-tree"&gt;LSM&lt;/a&gt; tree&lt;/li&gt;
&lt;li&gt;SQL index use &lt;a href="https://en.wikipedia.org/wiki/B%2B_tree"&gt;b-tree&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Dynamic memory management uses &lt;a href="https://en.wikipedia.org/wiki/Memory_management#Dynamic_memory_allocation"&gt;heap&lt;/a&gt;. which is a type of a tree.&lt;/li&gt;
&lt;li&gt;A trie for dictionaries or &lt;a href="https://www.geeksforgeeks.org/auto-complete-feature-using-trie/"&gt;auto complete algorithms.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Priority queues as well use &lt;a href="https://www.geeksforgeeks.org/priority-queue-using-binary-heap/"&gt;heap&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Garbage collectors also &lt;a href="https://en.wikipedia.org/wiki/Tracing_garbage_collection"&gt;use trees&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Tree_(graph_theory)"&gt;https://en.wikipedia.org/wiki/Tree_(graph_theory)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Tree_(data_structure)"&gt;https://en.wikipedia.org/wiki/Tree_(data_structure)&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Nodes or vertices
&lt;/h3&gt;

&lt;p&gt;Nodes is every unit of data&lt;/p&gt;

&lt;h3&gt;
  
  
  Edges or paths (links)
&lt;/h3&gt;

&lt;p&gt;Its the connection between each two nodes, if we have N nodes we would have N-1 edges, because each node as parent, except the root node.&lt;/p&gt;

&lt;h3&gt;
  
  
  Root
&lt;/h3&gt;

&lt;p&gt;Is the upmost node, who has no parent, and have only children,  for the children nodes this is their most parent node, generally in the top of the tree.&lt;/p&gt;

&lt;h3&gt;
  
  
  Parent-Children
&lt;/h3&gt;

&lt;p&gt;A node is a parent to its very next descendants. the descendants are the children to whom its connected with one single edge.&lt;/p&gt;

&lt;h3&gt;
  
  
  Siblings
&lt;/h3&gt;

&lt;p&gt;Are the children connected to the same node.&lt;/p&gt;

&lt;h3&gt;
  
  
  Descendants
&lt;/h3&gt;

&lt;p&gt;When we want to talk about children and their children, and the children of their children..etc we would say descendants.&lt;/p&gt;

&lt;p&gt;It means the set of nodes we can reach from a particular node going to its children. so all the subtree.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ansestors
&lt;/h3&gt;

&lt;p&gt;From that node to the root node, all this nodes are considered anscestors.&lt;/p&gt;

&lt;h3&gt;
  
  
  Degree of nodes
&lt;/h3&gt;

&lt;p&gt;Is the number of children a node has, so the direct children.&lt;/p&gt;

&lt;p&gt;A degree of a tree cannot be told from a tree, but its predefined, we can say its a binary tree. but if its unbalanced, we would see it in a form of a linkedlist.&lt;/p&gt;

&lt;h3&gt;
  
  
  Leaf nodes, external or terminal
&lt;/h3&gt;

&lt;p&gt;All nodes who has no children. so with nodes with degree 0&lt;/p&gt;

&lt;h3&gt;
  
  
  Levels
&lt;/h3&gt;

&lt;p&gt;Levels starting from first level 1, the root, as we categorize each level by all the nodes who take the same number of edges to get to the root node.&lt;/p&gt;

&lt;h3&gt;
  
  
  Height
&lt;/h3&gt;

&lt;p&gt;Hight of nodes, is the same as the levels but it starts from 0, its very useful for analysis.&lt;/p&gt;

&lt;h3&gt;
  
  
  Forest
&lt;/h3&gt;

&lt;p&gt;A collection of a tree is called a forest. which at least has a root node.&lt;/p&gt;

&lt;p&gt;To convert a forest to a tree, we attach the roots of the present trees, to one single root.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of trees
&lt;/h2&gt;

&lt;p&gt;There is many types of trees, and they are extremely useful and popular. for example&lt;/p&gt;

&lt;h3&gt;
  
  
  Binary tree
&lt;/h3&gt;

&lt;p&gt;One of the most popular trees, is &lt;a href="https://en.wikipedia.org/wiki/Binary_tree"&gt;the binary tree&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;Its tree of degree 2, means every node can have 0,1 or 2 children, but not more than 2.&lt;/p&gt;

&lt;p&gt;deg(T)=2&lt;/p&gt;

&lt;p&gt;$children=&lt;code&gt;{{0,1,2}}&lt;/code&gt;$&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Because the nodes can have only 2 nodes, we call them left child and right child. or left node and right node.&lt;/li&gt;
&lt;li&gt;If we come across a tree that is unbalanced, means it forms something like a linked list, but to the left side, we call it left skewed binary tree. or right skewed binary tree&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Binary search tree
&lt;/h3&gt;

&lt;p&gt;The binary search tree or &lt;a href="https://en.wikipedia.org/wiki/Binary_search_tree"&gt;BST&lt;/a&gt; , is a derivate of binary tree, but with a constraint in the data, Its a rooted binary tree, where every node (data) on the left side is grater than nodes on the right side.&lt;/p&gt;

&lt;p&gt;$deg(T)=2$&lt;/p&gt;

&lt;h3&gt;
  
  
  AVL Tree
&lt;/h3&gt;

&lt;p&gt;Another tree named after inventors &lt;strong&gt;A&lt;/strong&gt;delson-&lt;strong&gt;V&lt;/strong&gt;elsky and &lt;strong&gt;L&lt;/strong&gt;andis, is a self balancing binary search tree.&lt;/p&gt;

&lt;h3&gt;
  
  
  Decision Tree
&lt;/h3&gt;

&lt;p&gt;Its one of the popular ones for &lt;a href="https://www.geeksforgeeks.org/decision-tree/"&gt;classification and prediction&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Fenwich Tree
&lt;/h3&gt;

&lt;p&gt;A Fenwick tree or binary indexed tree is a data structure that can efficiently update elements and calculate &lt;a href="https://en.wikipedia.org/wiki/Prefix_sum"&gt;prefix sums&lt;/a&gt; in a table of numbers.&lt;/p&gt;

&lt;p&gt;Link to &lt;a href="https://en.wikipedia.org/wiki/Fenwick_tree"&gt;wiki&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Log structured Merge Tree
&lt;/h3&gt;

&lt;p&gt;Or LSM &lt;a href="https://en.wikipedia.org/wiki/Log-structured_merge-tree"&gt;tree&lt;/a&gt;  one of the trees used in databases like influxDB.&lt;/p&gt;

</description>
      <category>go</category>
      <category>algorithms</category>
      <category>database</category>
    </item>
    <item>
      <title>How to work with paths join or change directories in Golang</title>
      <dc:creator>Mohamed Allam</dc:creator>
      <pubDate>Fri, 18 Nov 2022 21:52:43 +0000</pubDate>
      <link>https://dev.to/mohamedallam/how-to-work-with-paths-join-or-change-directories-in-golang-48bn</link>
      <guid>https://dev.to/mohamedallam/how-to-work-with-paths-join-or-change-directories-in-golang-48bn</guid>
      <description>&lt;h1&gt;
  
  
  Path join in Golang
&lt;/h1&gt;

&lt;p&gt;Manipulating filename paths in a way that is compatible with the any target operating system-defined file paths.&lt;/p&gt;

&lt;h2&gt;
  
  
  Path joining
&lt;/h2&gt;

&lt;p&gt;When you start changing directories, you have to work with both forward slash and backward slash, depending on the operating system, Unix or Windows, Go takes care of that using &lt;a href="https://pkg.go.dev/path/filepath#Join"&gt;path.FilePath.Join function,&lt;/a&gt; to use Join, you have to provide the name of the folders, and Go will use the appropriate slash for you&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// https://pkg.go.dev/path/filepath#Join&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;Join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;elem&lt;/span&gt; &lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="o"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Join joins any number of path elements into a single path, separating them with an OS specific Separator. Empty elements are ignored. The result is Cleaned. However, if the argument list is empty or all its elements are empty, Join returns an empty string. On Windows, the result will only be a UNC path if the first non-empty element is a UNC path.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To use that, let's change directory using Go.&lt;/p&gt;

&lt;h2&gt;
  
  
  Change directory &lt;code&gt;cd&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;And also we generally you would need to use the &lt;code&gt;[chdir](https://pkg.go.dev/os#Chdir)&lt;/code&gt; you specify the name of the directory you want to go to, and this function would change the current directory for you&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// https://pkg.go.dev/os#Chdir&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;Chdir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dir&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="o"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Chdir changes the current working directory to the named directory. If there is an error, it will be of type *PathError.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Lets combine this two, which does allow us to work with either windows or linux who use / or \ backslash and forward slash for each system, and change directory to for now the names we pass in the &lt;code&gt;ChangeDir&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;ChangeDir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;elem&lt;/span&gt; &lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;filepath&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"./"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;filepath&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;elem&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

    &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Chdir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Cant change the workig directory"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Joining strings
&lt;/h2&gt;

&lt;p&gt;On the same note, if for whatever reason you want to join folder names, based on something different, or if is any strings joined, there is in the Go standard package, a string package that has a &lt;a href="https://pkg.go.dev/strings#Join"&gt;join&lt;/a&gt; method that is as below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;https&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="c"&gt;//pkg.go.dev/strings#Join&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;Join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;elems&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sep&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Join concatenates the elements of its first argument to create a single string. The separator string sep is placed between elements in the resulting string.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And as the official documentation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"foo"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"bar"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"baz"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strings&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;", "&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="c"&gt;//Output&lt;/span&gt;
&lt;span class="c"&gt;//foo, bar, baz&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>programming</category>
      <category>go</category>
      <category>linux</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Protocol buffer and gRPC: Beginners guide</title>
      <dc:creator>Mohamed Allam</dc:creator>
      <pubDate>Mon, 07 Nov 2022 09:23:57 +0000</pubDate>
      <link>https://dev.to/mohamedallam/protocol-buffer-and-grpc-beginners-guide-15ch</link>
      <guid>https://dev.to/mohamedallam/protocol-buffer-and-grpc-beginners-guide-15ch</guid>
      <description>&lt;h2&gt;
  
  
  Protocol buffer and gRPC: Beginners guide
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;Modern software applications rarely operate in isolation. Rather, they are connected with each other through computer networks and communicate and coordinate their actions by passing messages to one another.&lt;/p&gt;

&lt;p&gt;Wether you are looking to weather in your iPhone, or Paying a service/product in websites, inter and public communications between different code bases is always required to implement such functionalities.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem
&lt;/h2&gt;

&lt;p&gt;There is more than a thousand programming languages, and lot of different communications&lt;/p&gt;

&lt;h1&gt;
  
  
  What are protocol buffers?
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://developers.google.com/protocol-buffers"&gt;https://developers.google.com/protocol-buffers&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/protocolbuffers/protobuf"&gt;https://github.com/protocolbuffers/protobuf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Protocol_Buffers"&gt;https://en.wikipedia.org/wiki/Protocol_Buffers&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Accordring to Protocol buffer official doocumentation:&lt;/p&gt;

&lt;p&gt;Protocol buffers are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data – think XML, but smaller, faster, and simpler. You define how you want your data to be structured once, then you can use special generated source code to easily write and read your structured data to and from a variety of data streams and using a variety of languages.&lt;/p&gt;

&lt;p&gt;Accordring to Wikipedia:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Protocol Buffers&lt;/strong&gt; (&lt;strong&gt;Protobuf&lt;/strong&gt;) is a &lt;a href="https://en.wikipedia.org/wiki/Free_and_open-source_software"&gt;free and open-source&lt;/a&gt; &lt;a href="https://en.wikipedia.org/wiki/Cross-platform_software"&gt;cross-platform&lt;/a&gt; data format used to &lt;a href="https://en.wikipedia.org/wiki/Serialization"&gt;serialize&lt;/a&gt; structured data. It is useful in developing programs to communicate with each other over a network or for storing data. The method involves an &lt;a href="https://en.wikipedia.org/wiki/Interface_description_language"&gt;interface description language&lt;/a&gt; that describes the structure of some data and a program that generates source code from that description for generating or parsing a stream of bytes that represents the structured data.&lt;/p&gt;

&lt;p&gt;As for comparison:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Comparison_of_data-serialization_formats"&gt;Comparison of data-serialization formats - Wikipedia&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight protobuf"&gt;&lt;code&gt;
&lt;span class="na"&gt;syntax&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"proto3"&lt;/span&gt; &lt;span class="c1"&gt;// this defines which version of protocol buffer we use&lt;/span&gt;

&lt;span class="c1"&gt;// the messages we send is defined with "message"&lt;/span&gt;
&lt;span class="c1"&gt;// field type (int, string, boolean)&lt;/span&gt;
&lt;span class="c1"&gt;// field name&lt;/span&gt;
&lt;span class="c1"&gt;// field tag&lt;/span&gt;
&lt;span class="kd"&gt;message&lt;/span&gt; &lt;span class="nc"&gt;myMessage&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int32&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="na"&gt;first_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="na"&gt;last_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Scalar types:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://developers.google.com/protocol-buffers/docs/proto3#scalar"&gt;Language Guide (proto3) | Protocol Buffers | Google Developers&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developers.google.com/protocol-buffers/docs/proto3#scalar"&gt;https://developers.google.com/protocol-buffers/docs/proto3#scalar&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For numbers we find this types:&lt;/p&gt;

&lt;p&gt;double, float, int32, int64, uint32, uint64, sint32, sint64, fixed32, fixed64, sfixed64.&lt;/p&gt;

&lt;p&gt;We find other common ones:&lt;/p&gt;

&lt;p&gt;bool for boolean,&lt;/p&gt;

&lt;p&gt;string for strings, which are UTF-8 or 7-bit ASCII text.&lt;/p&gt;

&lt;p&gt;and bytes. or bytes array, we can use bytes for maybe a small image or something like that.&lt;/p&gt;

&lt;h3&gt;
  
  
  All types are zero valued
&lt;/h3&gt;

&lt;p&gt;When a message is parsed, if the encoded message does not contain a particular singular element, the corresponding field in the parsed object is set to the default value for that field. These defaults are type-specific:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For strings, the default value is the empty string.&lt;/li&gt;
&lt;li&gt;For bytes, the default value is empty bytes.&lt;/li&gt;
&lt;li&gt;For bools, the default value is false.&lt;/li&gt;
&lt;li&gt;For numeric types, the default value is zero.&lt;/li&gt;
&lt;li&gt;For Enum types, default value is first value.&lt;/li&gt;
&lt;li&gt;For repeated values, empty list.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight protobuf"&gt;&lt;code&gt;&lt;span class="na"&gt;syntax&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"proto3"&lt;/span&gt;

&lt;span class="kd"&gt;message&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;uint32&lt;/span&gt; &lt;span class="na"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="na"&gt;first_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="na"&gt;last_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;bytes&lt;/span&gt; &lt;span class="na"&gt;small_picture&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="na"&gt;profile_verified&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Tags
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;As you can see, each field in the message definition has a &lt;strong&gt;unique number&lt;/strong&gt;. These field numbers are used to identify your fields in the &lt;a href="https://developers.google.com/protocol-buffers/docs/encoding"&gt;message binary format&lt;/a&gt;, and should not be changed once your message type is in use. Note that field numbers in the range 1 through 15 take one byte to encode, including the field number and the field's type (you can find out more about this in &lt;a href="https://developers.google.com/protocol-buffers/docs/encoding#structure"&gt;Protocol Buffer Encoding&lt;/a&gt;). Field numbers in the range 16 through 2047 take two bytes. So you should reserve the numbers 1 through 15 for very frequently occurring message elements. Remember to leave some room for frequently occurring elements that might be added in the future.&lt;/p&gt;

&lt;p&gt;The smallest field number you can specify is 1, and the largest is 229 - 1, or 536,870,911. You also cannot use the numbers 19000 through 19999 (&lt;code&gt;FieldDescriptor::kFirstReservedNumber&lt;/code&gt; through &lt;code&gt;FieldDescriptor::kLastReservedNumber&lt;/code&gt;), as they are reserved for the Protocol Buffers implementation—the protocol buffer compiler will complain if you use one of these reserved numbers in your &lt;code&gt;.proto&lt;/code&gt;. Similarly, you cannot use any previously &lt;a href="https://developers.google.com/protocol-buffers/docs/proto3#reserved"&gt;reserved&lt;/a&gt; field numbers.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Tags in protocol buffers are a building block, they can be anywhere from&lt;/p&gt;

&lt;p&gt;Smallest tag 1&lt;/p&gt;

&lt;p&gt;Largest tag = 536 870 911 or 2 ex 29 -1&lt;/p&gt;

&lt;p&gt;There is a special range between 19000 19999&lt;/p&gt;

&lt;p&gt;Tags from 1 to 15 use 1 byte in space, so using them for frequently populated fields to maximise efficiency.&lt;/p&gt;

&lt;p&gt;Tags from 16 to 2047 use 2 bytes.&lt;/p&gt;

&lt;p&gt;Tag rules&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;singular: a well-formed message can have zero or one of this field (but not more than one). And this is the default field rule for proto3 syntax.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;repeated&lt;/code&gt;: this field can be repeated any number of times (including zero) in a well-formed message. The order of the repeated values will be preserved.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight protobuf"&gt;&lt;code&gt;&lt;span class="na"&gt;syntax&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"proto3"&lt;/span&gt;

&lt;span class="cm"&gt;/* multi
line
comment */&lt;/span&gt;
&lt;span class="kd"&gt;message&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;uint32&lt;/span&gt; &lt;span class="na"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="na"&gt;first_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="na"&gt;last_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;bytes&lt;/span&gt; &lt;span class="na"&gt;small_picture&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="na"&gt;profile_verified&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;repeated&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="na"&gt;address&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// enums of the possible eye color&lt;/span&gt;
    &lt;span class="kd"&gt;enum&lt;/span&gt; &lt;span class="n"&gt;EyeColor&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;UKNOWN_EYE_COLOR&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="na"&gt;EYE_GREEN&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="na"&gt;EYE_BROWN&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="na"&gt;EYE_BLUE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;EyeColor&lt;/span&gt; &lt;span class="na"&gt;eye_color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Given we want to add dates, we can define the date message and then just use it in the message we want&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight protobuf"&gt;&lt;code&gt;&lt;span class="na"&gt;syntax&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"proto3"&lt;/span&gt;

&lt;span class="cm"&gt;/* multi
line
comment */&lt;/span&gt;
&lt;span class="kd"&gt;message&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;uint32&lt;/span&gt; &lt;span class="na"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="na"&gt;first_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="na"&gt;last_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;bytes&lt;/span&gt; &lt;span class="na"&gt;small_picture&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="na"&gt;profile_verified&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;repeated&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="na"&gt;address&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// enums of the possible eye color&lt;/span&gt;
    &lt;span class="kd"&gt;enum&lt;/span&gt; &lt;span class="n"&gt;EyeColor&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;UKNOWN_EYE_COLOR&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="na"&gt;EYE_GREEN&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="na"&gt;EYE_BROWN&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="na"&gt;EYE_BLUE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;EyeColor&lt;/span&gt; &lt;span class="na"&gt;eye_color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;
    &lt;span class="n"&gt;Date&lt;/span&gt; &lt;span class="na"&gt;birthday&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;message&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int32&lt;/span&gt; &lt;span class="na"&gt;year&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;int32&lt;/span&gt; &lt;span class="na"&gt;month&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;int32&lt;/span&gt; &lt;span class="na"&gt;day&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Import from other proto files
&lt;/h3&gt;

&lt;p&gt;To import a type from another file, we have to use import syntax, where we start from the folder directory&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight protobuf"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"my_root_project/date.proto"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;message&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;uint32&lt;/span&gt; &lt;span class="na"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="na"&gt;first_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="na"&gt;last_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;bytes&lt;/span&gt; &lt;span class="na"&gt;small_picture&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="na"&gt;profile_verified&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;repeated&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="na"&gt;address&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// enums of the possible eye color&lt;/span&gt;
    &lt;span class="kd"&gt;enum&lt;/span&gt; &lt;span class="n"&gt;EyeColor&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;UKNOWN_EYE_COLOR&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="na"&gt;EYE_GREEN&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="na"&gt;EYE_BROWN&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="na"&gt;EYE_BLUE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;EyeColor&lt;/span&gt; &lt;span class="na"&gt;eye_color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;
    &lt;span class="n"&gt;Date&lt;/span&gt; &lt;span class="na"&gt;birthday&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;WE can add packages to have percise type naming convetino&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight protobuf"&gt;&lt;code&gt;
&lt;span class="c1"&gt;// mydate is the pacakge name&lt;/span&gt;
&lt;span class="c1"&gt;// Date is message definiton&lt;/span&gt;
&lt;span class="kd"&gt;message&lt;/span&gt; &lt;span class="nc"&gt;Address&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="na"&gt;first_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;my.date.Date&lt;/span&gt; &lt;span class="na"&gt;bithday&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Getting started with ProtoBuf
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Basics
&lt;/h3&gt;

&lt;p&gt;Protocol buffers uses .proto files, in which a &lt;code&gt;message&lt;/code&gt; is the message we send or receive, a basic message look like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight protobuf"&gt;&lt;code&gt;&lt;span class="kd"&gt;message&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="na"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="na"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Proto files has 3 versions, to indicate the version in the beginning of the file, we declare the version we want to use, the lastest one is version 3.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight protobuf"&gt;&lt;code&gt;&lt;span class="na"&gt;syntax&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"proto3"&lt;/span&gt;

&lt;span class="kd"&gt;message&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="na"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="na"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="na"&gt;available&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The scalar types&lt;/p&gt;

&lt;p&gt;double, float, int32, int64, uint32, uint64, sint32, sint64, fixed32, fixed64, sfixed64.&lt;/p&gt;

&lt;p&gt;We find other common ones:&lt;/p&gt;

&lt;p&gt;bool for boolean,&lt;/p&gt;

&lt;p&gt;string for strings, which are UTF-8 or 7-bit ASCII text.&lt;/p&gt;

&lt;p&gt;and bytes. or bytes array, we can use bytes for maybe a small image or something like that.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>migrations</category>
    </item>
    <item>
      <title>did you know what happened today?</title>
      <dc:creator>Mohamed Allam</dc:creator>
      <pubDate>Tue, 19 Jul 2022 11:12:02 +0000</pubDate>
      <link>https://dev.to/mohamedallam/did-you-know-what-happened-today-55on</link>
      <guid>https://dev.to/mohamedallam/did-you-know-what-happened-today-55on</guid>
      <description>&lt;p&gt;Liquid syntax error: Tag '{%' was not properly terminated with regexp: /\%\}/&lt;/p&gt;
</description>
      <category>discuss</category>
      <category>world</category>
    </item>
    <item>
      <title>Hello, World!</title>
      <dc:creator>Mohamed Allam</dc:creator>
      <pubDate>Tue, 19 Jul 2022 09:47:51 +0000</pubDate>
      <link>https://dev.to/mohamedallam/hello-world-5h3j</link>
      <guid>https://dev.to/mohamedallam/hello-world-5h3j</guid>
      <description>&lt;p&gt;Hello DEV, this is my first post&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Why you should learn go?</title>
      <dc:creator>Mohamed Allam</dc:creator>
      <pubDate>Fri, 29 Apr 2022 00:04:38 +0000</pubDate>
      <link>https://dev.to/mohamedallam/why-you-should-learn-go-bkd</link>
      <guid>https://dev.to/mohamedallam/why-you-should-learn-go-bkd</guid>
      <description>&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;Its 2022, 5 years since I started my first Laravel application, and I never wanted to look to anything else, to embrace the framework and learn it intimately.&lt;/p&gt;

&lt;p&gt;The beginning of this year, I made a little research in the programming languages and tried to figure out another programming language to learn.&lt;/p&gt;

&lt;p&gt;Right of the bad, I did see some comparisons and saw a difference in old vs new programming languages, and my heart instantly fell in love with new programming languages.&lt;/p&gt;

&lt;h2&gt;
  
  
  The newer programming languages
&lt;/h2&gt;

&lt;p&gt;So in the landscape of more than a thousands choice, I have limited my choices to:&lt;/p&gt;

&lt;p&gt;Dart (Flutters' language)&lt;br&gt;
Swift (Apple snob?)&lt;br&gt;
Elixir (Atom model)&lt;br&gt;
Golang (yeah)&lt;/p&gt;

&lt;p&gt;Most hardwares that existed when C or PHP was created, are not only obsolete but also different, particularly multi threaded processors.&lt;br&gt;
Therefor the languages too had to make some changes, through updates, patches, new versions.&lt;br&gt;
But when it comes to this new language, they are built from the ground up to consume and embrace the hardware of today.&lt;/p&gt;

&lt;h2&gt;
  
  
  In my research I come across
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;StackOverFlow surveys &lt;/li&gt;
&lt;li&gt;JetBrains surveys&lt;/li&gt;
&lt;li&gt;Tiobe index&lt;/li&gt;
&lt;li&gt;PYPL&lt;/li&gt;
&lt;li&gt;HackerRank report&lt;/li&gt;
&lt;li&gt;Hired reportd&lt;/li&gt;
&lt;li&gt;Github Octoverse&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Extra
&lt;/h2&gt;

&lt;p&gt;As an extra, I did scroll through some benchmarking frameworks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Buttom line
&lt;/h2&gt;

&lt;p&gt;Golang is among best programming languages to learn in 2022&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/ny-1SPBrPBY"&gt;
&lt;/iframe&gt;
.&lt;/p&gt;

</description>
      <category>go</category>
      <category>programming</category>
      <category>beginners</category>
      <category>laravel</category>
    </item>
    <item>
      <title>Test driven development</title>
      <dc:creator>Mohamed Allam</dc:creator>
      <pubDate>Tue, 27 Jul 2021 22:32:16 +0000</pubDate>
      <link>https://dev.to/mohamedallam/test-driven-development-29ai</link>
      <guid>https://dev.to/mohamedallam/test-driven-development-29ai</guid>
      <description>&lt;p&gt;My first post&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>tdd</category>
      <category>php</category>
      <category>tailwindcss</category>
    </item>
  </channel>
</rss>
