<?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: Odewole Abdul-Jemeel</title>
    <description>The latest articles on DEV Community by Odewole Abdul-Jemeel (@intellect4all).</description>
    <link>https://dev.to/intellect4all</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%2F858570%2F5720d1aa-ef88-4fb4-87f6-00825fbde22b.jpeg</url>
      <title>DEV Community: Odewole Abdul-Jemeel</title>
      <link>https://dev.to/intellect4all</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/intellect4all"/>
    <language>en</language>
    <item>
      <title>Building My Digital Playground: How I Built a Self-Sufficient Homelab That Never Sleeps</title>
      <dc:creator>Odewole Abdul-Jemeel</dc:creator>
      <pubDate>Mon, 03 Nov 2025 06:57:23 +0000</pubDate>
      <link>https://dev.to/intellect4all/building-my-digital-playground-how-i-built-a-self-sufficient-homelab-that-never-sleeps-5blk</link>
      <guid>https://dev.to/intellect4all/building-my-digital-playground-how-i-built-a-self-sufficient-homelab-that-never-sleeps-5blk</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;Introduction&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;It started with a simple motivation — I wanted a reliable and affordable way to experiment, learn, and host personal services without running them on my daily machine. I've always believed that the best way to understand systems is to build them, break them, and rebuild them better.&lt;/p&gt;

&lt;p&gt;My goals were straightforward: I needed fairly decent, cheap computing power on my network for learning purposes and hosting fun side projects. More importantly, I wanted to understand how real-world infrastructure works — from virtualization to networking to service orchestration. There's something deeply satisfying about knowing that the services you use daily are running on hardware you control, configured exactly the way you want.&lt;/p&gt;

&lt;p&gt;So, I decided to create a homelab, a dedicated environment for learning, self-hosting, and tinkering. My objectives were clear:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Learning&lt;/strong&gt;: Experiment with virtualization, orchestration, networking, and automation&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Self-hosting&lt;/strong&gt;: Run my own services—from productivity tools to media servers&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reliability&lt;/strong&gt;: Maintain 24/7 uptime and gain real-world infrastructure experience&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Over time, this small project evolved into a fully functional, solar-powered three-node cluster, running everything from media servers to automation pipelines. My setup consists of three Dell OptiPlex 7070 machines, all connected via a Ruijie RG-ES205GC-P 5-Port Gigabit Cloud Managed PoE+ Switch, with upstream connectivity through a FiberOne 50Mbps fiber connection. Not exactly enterprise-grade, but more than enough for what I needed to accomplish.&lt;/p&gt;

&lt;p&gt;In fact, my personal website &lt;a href="https://jemeel.dev/" rel="noopener noreferrer"&gt;jemeel.dev&lt;/a&gt;, a fully ClaudeCode generated portfolio website, is publicly available and running on Dokploy from this very homelab. It's incredibly satisfying to tell people, "Yeah, that's running on hardware in my room."&lt;/p&gt;

&lt;p&gt;Here's how it all came together.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Hardware &amp;amp; Power Infrastructure&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;At the heart of the lab are three Dell OptiPlex 7070 machines — compact, efficient, and affordable. I chose Dell OptiPlex machines because they're reliable, relatively power-efficient, and, most importantly, affordable on the used market.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Nodes:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;🖥️ &lt;strong&gt;Dell OptiPlex 7070 SFF&lt;/strong&gt; – Core i7, 32 GB RAM, 2 TB SSD&lt;/p&gt;

&lt;p&gt;🖥️ &lt;strong&gt;Dell OptiPlex 7070 SFF&lt;/strong&gt; – Core i7, 32 GB RAM, 1 TB SSD&lt;/p&gt;

&lt;p&gt;💻 &lt;strong&gt;Dell OptiPlex 7070 Micro&lt;/strong&gt; – Core i7, 32 GB RAM, 1 TB SSD  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fow7rjx95ewo7r26n8otv.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fow7rjx95ewo7r26n8otv.jpg" alt="Dell Optiplex Micro Motherboard" width="800" height="1066"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each node packs a Core i7 processor and 32GB of RAM, not bleeding edge, but plenty of horsepower for running multiple virtual machines and containerized services. The total storage across all nodes is 4TB, which is more than sufficient for my current needs.&lt;/p&gt;

&lt;p&gt;These nodes are connected via a &lt;strong&gt;Ruijie RG-ES205GC-P 5-Port Gigabit Cloud Managed PoE+ Switch&lt;/strong&gt;, with upstream internet provided by a &lt;strong&gt;FiberOne 50 Mbps fiber connection&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8c1p1jw9blm8mq7u3wm1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8c1p1jw9blm8mq7u3wm1.jpg" alt="Ruijie Switch" width="800" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Cost Breakdown&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's talk numbers, because one of the biggest questions people ask is: "How much does this actually cost?"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Initial Investment:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;3× Dell OptiPlex 7070 units: ₦520,000 each = ₦1,560,000&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ruijie RG-ES205GC-P Switch: ₦45,000&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;2TB SSD (replacement—more on this later): ₦220,000&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Total initial cost: ₦1,825,000&lt;/strong&gt; (~$1,200 USD at current rates)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Monthly Operating Costs:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Internet (50Mbps fiber, shared with home): ₦25,000&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Electricity (minimal due to solar): ~₦5,000&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Total monthly cost: ₦30,000&lt;/strong&gt; (~$20 USD)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, let me put this in perspective. For comparison, running equivalent infrastructure on cloud platforms would cost significantly more:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cloud Cost Comparison (Approximate Monthly Costs):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AWS EC2:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;3× t3.xlarge instances (4 vCPU, 16GB RAM each): ~$220/month&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;4TB EBS storage: ~$400/month&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Data transfer (moderate): ~$50/month&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Total: ~$670/month&lt;/strong&gt; (₦1,005,000)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;DigitalOcean:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;3× droplets (8GB RAM, 4 vCPU): ~$240/month&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;4TB block storage: ~$400/month&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Bandwidth overages: ~$30/month&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Total: ~$670/month&lt;/strong&gt; (₦1,005,000)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Google Cloud Platform:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;3× n2-standard-4 instances: ~$250/month&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;4TB persistent SSD: ~$680/month&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Network egress: ~$40/month&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Total: ~$970/month&lt;/strong&gt; (₦1,455,000)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Heroku:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Performance-M dynos (comparable): ~$500/month&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Heroku Postgres: ~$200/month&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add-ons and scaling: ~$100/month&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Total: ~$800/month&lt;/strong&gt; (₦1,200,000)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Vercel Pro + Infrastructure:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Vercel Pro: $20/month&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Backend hosting (Railway/Render): ~$100/month&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Database (PlanetScale/Supabase): ~$50/month&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Total: ~$170/month&lt;/strong&gt; (₦255,000) - &lt;em&gt;Limited to web apps only&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;My Homelab ROI:&lt;/strong&gt; After just &lt;strong&gt;3 months&lt;/strong&gt;, my homelab pays for itself compared to AWS/GCP. After 6 months, I'm saving over ₦6 million annually compared to traditional cloud hosting. The only ongoing costs are internet (which I'd have anyway) and minimal electricity due to solar power.&lt;/p&gt;

&lt;p&gt;Of course, cloud platforms offer advantages like global distribution, automatic scaling, and managed services. But for learning, experimentation, and self-hosting personal projects, the homelab is unbeatable in terms of cost-effectiveness.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Power &amp;amp; Uptime Design&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Living in Nigeria means dealing with inconsistent power supply, so I couldn't just plug everything into the wall and hope for the best. All nodes are connected to a dedicated outlet powered by both the grid and a &lt;strong&gt;3.5KVA solar inverter&lt;/strong&gt;. The setup automatically switches between power sources, keeping everything online even during extended outages—a must for 24/7 operation.&lt;/p&gt;

&lt;p&gt;There's nothing more frustrating than having your services go down because of a power outage, especially when you're hosting productivity tools you rely on daily. This dual-power configuration provides an uninterrupted 24/7 power supply essential for services that need to stay online. The solar setup has been a game-changer, reducing my electricity costs to nearly nothing while ensuring my services remain accessible even during the longest power outages.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Network Topology&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Each node communicates over Gigabit LAN, ensuring low latency and quick data replication. All three nodes are connected via the Ruijie switch, which handles local network traffic at gigabit speeds. The switch connects to my FiberOne router, which provides a stable 50Mbps upload and download connection.&lt;/p&gt;

&lt;p&gt;I know 50Mbps isn't blazing fast by modern standards, but for a homelab serving primarily personal use and a handful of external services, it's perfectly adequate. The keyword here is "stable"; consistent connectivity matters more than raw speed for most self-hosted services. The fiber line is stable enough for remote access, backups, and moderate traffic applications.&lt;/p&gt;

&lt;p&gt;That said, I'm currently in discussions with my ISP about upgrading to a higher dedicated line. With my website now publicly accessible and plans to self-host more projects, the additional bandwidth would provide headroom for growth and better performance for external users.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Virtualization Layer&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;When it came to choosing a virtualization platform, I went with &lt;a href="https://www.proxmox.com/en/" rel="noopener noreferrer"&gt;&lt;strong&gt;Proxmox VE&lt;/strong&gt;&lt;/a&gt;. Why Proxmox? It's free, stable, and incredibly flexible. It supports both KVM virtualization for full virtual machines and LXC containers for lightweight workloads. Plus, the web-based management interface makes it easy to manage everything from anywhere on the network. It allowed me to cluster all three nodes, share resources, and manage VMs and containers from a unified interface.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cluster Setup&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Each node was joined into a single Proxmox cluster, enabling live migration and centralized backups. I configured all three nodes into a Proxmox cluster, which allows them to work together as a unified system. This means I can migrate VMs between nodes, manage all three from a single interface, and set up high availability if needed. The cluster setup was straightforward - Proxmox makes it easy to add nodes to an existing cluster through the web UI.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2hm4ewx3htg70u3ud4yg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2hm4ewx3htg70u3ud4yg.png" alt="Proxmox Node Summary page" width="800" height="424"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftwfe5n4sxkv1lf3zl6yd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftwfe5n4sxkv1lf3zl6yd.png" alt="Proxmox DataCenter Summary Page" width="800" height="438"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Storage Architecture&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For storage, I maintain shared storage through &lt;strong&gt;NFS&lt;/strong&gt;, hosted on one of the larger nodes for reliability. This allows all nodes to access shared storage, making it easy to migrate VMs without worrying about moving disk images around. I also configured regular backups to ensure I don't lose everything if a disk decides to give up on life.&lt;/p&gt;

&lt;p&gt;And speaking of disks giving up — let me tell you about an expensive lesson I learned the hard way.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A Costly Mistake: The 1TB SSD Incident&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Early in my homelab journey, I ran into a Proxmox cache issue. In my attempt to resolve it, I mistakenly (yeah, the word was invented for blame shifting reasons like this) deleted some critical memory addresses that completely crashed one of my 1TB SSDs. The drive became completely undiscoverable and unrecoverable — no amount of troubleshooting, recovery tools, or desperate Googling could bring it back to life.&lt;/p&gt;

&lt;p&gt;This was a painful lesson in several ways:&lt;/p&gt;

&lt;p&gt;First, the obvious cost of ₦220,000 for a replacement 2TB SSD (I upgraded the capacity while I was at it). Second, the time lost in rebuilding and reconfiguring services. But most importantly, it taught me the absolute importance of proper backups and understanding what you're doing before you execute commands, especially when dealing with storage and memory management.&lt;/p&gt;

&lt;p&gt;Since then, I've implemented much more rigorous backup procedures and I always, &lt;em&gt;always&lt;/em&gt; double-check before running any storage-related commands. I also document every significant change I make to the infrastructure. And lastly, it thought me VM managements and deep understanding of proxmox.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Base Templates &amp;amp; Remote Access&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One of my favorite optimizations was creating a &lt;strong&gt;headless Ubuntu VM template with cloud-init&lt;/strong&gt;. To speed up provisioning, I use this template which means I can spin up new Ubuntu VMs in seconds with pre-configured networking, SSH keys, and basic packages already installed. No more spending 20 minutes setting up a new VM every time I want to experiment with something.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsjvx61pvzyjw5ofobees.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsjvx61pvzyjw5ofobees.png" alt="Ubuntu VM Template Hardware Configurations" width="800" height="357"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3ktiadqque2t8vn4k3ns.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3ktiadqque2t8vn4k3ns.png" alt="Ubuntu VM Template CloudInit config" width="800" height="357"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For remote access and interconnectivity, I configured &lt;strong&gt;Tailscale VPN&lt;/strong&gt;, which allows me to securely connect and manage the cluster from anywhere. Tailscale creates a mesh VPN that lets me connect to my homelab from anywhere without exposing services directly to the internet. It's like having a secure tunnel straight into my network, which is especially useful when I need to access my services while away from home.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Service Grouping Strategy&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;One of the most important decisions when building a homelab is figuring out how to organize your services. Do you run everything on one machine? Do you create a separate VM for every service? The answer, as usual, is somewhere in between.&lt;/p&gt;

&lt;p&gt;To keep things organized, I grouped services by category and performance demand.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cluster Role Division&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;🧩 &lt;strong&gt;Node 1 &amp;amp; 2&lt;/strong&gt;: Dedicated to &lt;strong&gt;Dokploy&lt;/strong&gt; (self-hosted PaaS) for deployments, configured in a Docker Swarm setup (primary and worker nodes)—combining 3TB of storage and 64GB RAM. These two nodes are connected via Docker Swarm, providing a powerful platform for deploying containerized applications without much hassle.&lt;/p&gt;

&lt;p&gt;⚙️ &lt;strong&gt;Node 3&lt;/strong&gt;: Hosts self-contained services (media, productivity, and infrastructure utilities). This node is reserved for self-hosted services and tools that I want to keep separate from the Dokploy environment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Philosophy Behind Isolation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Rather than running everything in a single container stack, I prefer isolating services into dedicated VMs or grouped Docker stacks. This separation provides a layer of isolation—if something goes wrong in my deployment environment, my core services remain unaffected. This makes it easier to scale, back up, or tear down without affecting unrelated services.&lt;/p&gt;

&lt;p&gt;I organized my services into clear categories: Infrastructure, Media, and Productivity. This makes it easier to manage resources and understand dependencies. Infrastructure services like DNS and reverse proxies get priority allocation since everything else depends on them. Media services can be more resource-hungry, so they get their own allocation. Productivity tools are somewhere in between.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Resource Allocation Philosophy&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I follow a simple principle: allocate conservatively, scale when needed. It's tempting to give every VM maximum resources, but that's wasteful. Instead, I start small and monitor performance. If a service consistently maxes out its allocated resources, I increase them. This approach ensures I'm making the most of my limited hardware.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Key Self-Hosted Services&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This is where things get interesting. Let me walk you through the major services running in my homelab and why I chose to self-host them.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1. Infrastructure &amp;amp; Networking (VM 1: 4GB RAM, 2 CPUs)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This VM handles the core network and infrastructure management stack that everything else depends on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Caddy&lt;/strong&gt;: My primary reverse proxy and web server. Caddy is lightweight and handles SSL automation beautifully. It automatically handles SSL certificates, which means I don't have to manually manage Let's Encrypt renewals. It's simple, fast, and just works.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Portainer&lt;/strong&gt;: A web-based Docker management interface that provides visual Docker management. While I'm comfortable with Docker CLI, Portainer provides a nice visual overview of all my containers, makes it easy to check logs, and simplifies management when I don't want to SSH into a server.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;AdGuard Home&lt;/strong&gt;: Network-wide ad blocking and DNS management. Every device on my network benefits from ad blocking without needing individual browser extensions. It also gives me detailed insights into DNS queries and lets me block specific domains.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Uptime Kuma&lt;/strong&gt;: A beautiful uptime monitoring and tracking tool. It pings all my services regularly and alerts me if anything goes down. The dashboard gives me a quick overview of service health.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;2. Productivity &amp;amp; Personal Management (VM 2: 4GB RAM, 2 CPUs)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;My digital workspace lives here. This VM runs services that help me stay organized and productive:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Traggo&lt;/strong&gt;: Time tracking made simple. I use it to track how much time I spend on different projects and tasks. Unlike cloud-based alternatives, my time tracking data stays on my servers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Paperless-NGX&lt;/strong&gt;: Document management system that OCRs and organizes all my documents. I scan everything—bills, receipts, important documents—and Paperless makes them searchable and accessible from anywhere.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;SureFinance&lt;/strong&gt;: Self-hosted finance tracker for personal finance tracking. I wanted to understand where my money goes without giving a third-party service access to my financial data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Vikunja&lt;/strong&gt;: Project and task management. It's like Todoist or Trello, but self-hosted. I use it to organize both personal and work projects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Mixpost&lt;/strong&gt;: Social media scheduler and management tool. Helps me schedule and manage social media posts without relying on expensive SaaS solutions.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All of these integrate into my daily workflow seamlessly, replacing SaaS tools with privacy-respecting self-hosted alternatives. The beauty of self-hosting productivity tools is that you control your data and can customize integrations exactly how you want them.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;3. Media (VM 3: 12GB RAM, 4 CPUs)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;For media and storage, media services tend to be resource-intensive, so I gave this VM more horsepower. This VM runs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Immich&lt;/strong&gt;: Self-hosted, AI-powered photo and video library. Think Google Photos, but you own your data. It's got machine learning-powered photo recognition, automatic backups from my phone, and a beautiful interface.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Nextcloud&lt;/strong&gt;: My personal cloud storage and collaboration platform for file sync. I use it for file syncing, calendar management, and sharing files with others. It's replaced Dropbox and Google Drive for me entirely.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These services make file management, streaming, and backup seamless within my network. The media VM gets more resources because photo recognition and video transcoding can be demanding. I allocated 12GB of RAM and 4 CPU cores to ensure smooth performance, especially when Immich is processing a batch of photos or Nextcloud is syncing large files.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Easier Deployment with Dokploy: My Self-Hosted PaaS&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;If there's one decision that transformed my homelab from a collection of manually-managed containers into a streamlined deployment platform, it was setting up &lt;a href="https://dokploy.com/" rel="noopener noreferrer"&gt;&lt;strong&gt;Dokploy&lt;/strong&gt;&lt;/a&gt;. This self-hosted Platform-as-a-Service has become the backbone of my entire infrastructure.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhd6lm7mfzbjkx9necflg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhd6lm7mfzbjkx9necflg.png" alt="Dokploy Usage Monitoring Dashboard" width="800" height="456"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Why Dokploy?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;When researching self-hosted PaaS solutions, I had several options: Coolify, CapRover, Dokku, and Dokploy. I chose Dokploy for three main reasons:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Modern, Intuitive UI&lt;/strong&gt;: Clean, responsive interface that's actually enjoyable to use&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Simplicity Without Sacrificing Power&lt;/strong&gt;: Easy enough for quick deployments, powerful enough for complex applications&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Active Development&lt;/strong&gt;: Recent, actively maintained, with responsive developer support&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I seriously considered Coolify, which is also excellent, but Dokploy's UI and overall user experience won me over.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;What Makes Dokploy Special?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Dokploy is essentially a self-hosted alternative to Heroku, Vercel, and Railway. Here's what makes it powerful:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitHub Integration &amp;amp; One-Click Deployments&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Dokploy connects directly to my GitHub repositories. Push code, and it automatically builds, deploys, and configures everything. My website, &lt;a href="https://jemeel.dev" rel="noopener noreferrer"&gt;jemeel.dev&lt;/a&gt;, goes from code push to production in &lt;strong&gt;less than 5 minutes&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Push code to GitHub&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dokploy receives webhook, pulls code, builds Docker image&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Deploys to Docker Swarm&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Traefik configures routing&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Let's Encrypt provisions SSL&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Site is live with HTTPS&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is Vercel-level developer experience on hardware I own.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F10dldy89454xmcoegj3g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F10dldy89454xmcoegj3g.png" alt="Dokploy Project Dashboard" width="800" height="456"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Docker Compose Support&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Native Docker Compose support means I can paste existing compose files directly into Dokploy. For complex multi-container applications (API + frontend + database + cache), one compose file orchestrates everything.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Database Provisioning&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Dokploy spins up popular databases with a few clicks: PostgreSQL, MySQL, MongoDB, Redis, MariaDB. Need a database? Click "Add Database," choose PostgreSQL, set a password—done. No manual container management or volume configuration.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fupcgdxg27f227qjrvm5c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fupcgdxg27f227qjrvm5c.png" alt="Database Provisioning in Dokploy" width="800" height="923"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Traefik Integration &amp;amp; SSL Management&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Dokploy works seamlessly with Traefik for automatic routing and Let's Encrypt for SSL certificates. Deploy a service with a domain name, and SSL just works—automatically provisioned and renewed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cloudflare Tunnel Integration&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For public-facing services, I use a three-layer architecture:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cloudflare Tunnel&lt;/strong&gt;: HTTPS, DDoS protection, WAF, bot filtering&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Traefik&lt;/strong&gt;: HTTP routing, load balancing, service discovery&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dokploy&lt;/strong&gt;: Application hosting and orchestration&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cloudflare handles external threats and SSL termination, Traefik manages internal routing, and Dokploy hosts the applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When This Works Best:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Public websites and web applications&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;REST APIs with moderate traffic&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Personal projects and portfolios&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Small to medium business applications&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Content management systems&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;When This Has Limitations:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Latency-sensitive applications (adds 20-50ms)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Very high bandwidth needs (4K streaming to multiple users)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Applications requiring static IPs for allowlisting&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Strict compliance requirements needing direct IP control&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For most use cases—personal projects, small business apps, moderate-traffic websites—this setup is excellent.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Dokploy vs. Popular PaaS Platforms&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Let's compare costs for hosting 10 moderate applications with databases:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Heroku:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;10 apps + databases: &lt;strong&gt;$160/month&lt;/strong&gt; (₦240,000) = &lt;strong&gt;₦2,880,000/year&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Vercel + Supabase:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pro plan + databases + bandwidth: &lt;strong&gt;$85/month&lt;/strong&gt; (₦127,500) = &lt;strong&gt;₦1,530,000/year&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Railway:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;10 apps with databases: &lt;strong&gt;~$115/month&lt;/strong&gt; (₦172,500) = &lt;strong&gt;₦2,070,000/year&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Dokploy on My Homelab:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Hardware (amortized over 3 years): ₦50,694/month&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Internet: ₦25,000/month&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Electricity: ₦5,000/month&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Total: ₦80,694/month&lt;/strong&gt; = &lt;strong&gt;₦968,328/year&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After the first year, when hardware is paid off, costs drop to just &lt;strong&gt;₦30,000/month&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First-year savings:&lt;/strong&gt; Over ₦1.9 million compared to Heroku. After three years: Over ₦6 million saved. Plus, I own the hardware—it's an asset with resale value.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Feature Comparison:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Dokploy matches or exceeds commercial platforms on most features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;✅ GitHub integration (same as all platforms)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;✅ Automatic SSL (same as all platforms)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;✅ Database hosting (built-in, unlike Vercel)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;✅ Docker Compose support (better than Heroku)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;✅ Unlimited deployments (Heroku charges per app)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;✅ No sleep mode (Heroku free tier sleeps)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;✅ Full backend support (better than Vercel's serverless-only)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;❌ Global CDN (Vercel wins here)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;❌ Automatic scaling (Railway/Heroku win)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For full-stack applications with traditional databases, Dokploy is far more capable and cost-effective than any commercial PaaS.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;My Primary Use Case: Self-Hosting Everything&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;My philosophy: &lt;strong&gt;if it can run in a container, it's going on Dokploy&lt;/strong&gt;. Every side project, every experiment, every tool I build gets deployed to my homelab.&lt;/p&gt;

&lt;p&gt;This approach provides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Financial Freedom&lt;/strong&gt;: Never worry about deployment costs&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Learning Opportunities&lt;/strong&gt;: Every deployment teaches DevOps skills&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data Ownership&lt;/strong&gt;: Complete control over my data&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Portfolio Advantage&lt;/strong&gt;: Demonstrates end-to-end technical capability&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Backup &amp;amp; Recovery&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;My backup strategy ensures quick recovery:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Nightly&lt;/strong&gt;: Application and database backups via Proxmox&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Weekly&lt;/strong&gt;: Docker volume snapshots&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Monthly&lt;/strong&gt;: Off-site sync to external drives&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After the SSD incident, this strategy proved its worth—I restored a complete node in under an hour. Having the Docker Swarm across two nodes provides redundancy: if one node fails, services continue on the other.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;The Developer Experience&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;What I love most is the workflow simplicity:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Write code&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Push to GitHub&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Watch it automatically deploy&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Done&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;No SSH-ing into servers, no manual Docker commands, no editing configs. Just pure development focus. It's Heroku-level simplicity on infrastructure I own.&lt;/p&gt;

&lt;p&gt;Dokploy transformed my homelab from a technical experiment into a practical platform that genuinely competes with commercial PaaS offerings. It's the difference between having servers and having infrastructure.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Networking&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Networking is often the most challenging part of a homelab, but it's also the most critical. You need secure, reliable access to your services both from inside and outside your network. My network stack is designed around both security and accessibility.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cloudflare Tunnel&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For external access, I route external traffic through &lt;strong&gt;Cloudflare Tunnel&lt;/strong&gt;. This is a brilliant solution that eliminates the need to expose my home IP address or open ports on my router. The tunnel creates a secure connection from my homelab to Cloudflare's edge network, and Cloudflare handles all the external traffic.&lt;/p&gt;

&lt;p&gt;The benefits are significant and include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;DDoS protection&lt;/strong&gt;: Cloudflare automatically protects against attacks&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Web Application Firewall (WAF)&lt;/strong&gt;: Filters malicious traffic before it reaches my network and rate limiting&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;SSL/TLS encryption&lt;/strong&gt;: End-to-end encryption without managing certificates manually&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Rate limiting&lt;/strong&gt;: Prevents abuse and resource exhaustion (configurable)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Bot protection&lt;/strong&gt;: Blocks automated attacks and filtering&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Zero Trust Access&lt;/strong&gt;: Optional additional security layer for sensitive services&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This setup is particularly important now that my website is publicly accessible. Without Cloudflare Tunnel, I'd be directly exposing my home network to the internet, which is a security nightmare. Instead, all traffic flows through Cloudflare's infrastructure first, providing multiple layers of protection.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reverse Proxies&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Internally, I run both &lt;strong&gt;Traefik&lt;/strong&gt; and &lt;strong&gt;Caddy&lt;/strong&gt; as reverse proxies, depending on the use case, handling SSL certificates and dynamic service discovery. Traefik excels at dynamic service discovery with Docker — it automatically detects new containers and configures routing. Caddy is simpler and handles static routing beautifully with automatic HTTPS.&lt;/p&gt;

&lt;p&gt;This combination gives me a clean, domain-based structure like:&lt;/p&gt;

&lt;p&gt;paperless.intellect.lab&lt;/p&gt;

&lt;p&gt;portainer.intellect.lab&lt;/p&gt;

&lt;p&gt;immich.intellect.lab&lt;/p&gt;

&lt;p&gt;jemeel.dev&lt;/p&gt;

&lt;p&gt;Between Cloudflare Tunnel, Traefik, and Caddy, I have a robust networking setup that's secure, performant, and relatively easy to manage.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Performance, Challenges &amp;amp; Lessons Learned&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Building and maintaining a homelab isn't all smooth sailing. Balancing resources across multiple VMs and containers took some trial and error. Here are some of the challenges I've faced and what I learned from them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Resource Distribution&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With three nodes and limited resources, careful resource distribution is essential. 32GB per node is adequate for most workloads, but RAM can bottleneck quickly when running multiple containers. I constantly monitor CPU, RAM, and disk usage to ensure no single VM or container is starving the others. Proxmox's built-in monitoring makes this easier, but it still requires regular attention.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Network Limitations&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The 50Mbps connection (~6.25 MB/s) is the biggest bottleneck in my setup and caps throughput, so I optimized caching and limited high-traffic services. While it's sufficient for most use cases, there are clear limitations:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Performance Envelope:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Throughput&lt;/strong&gt;: ~6.25 MB/s maximum&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Static sites&lt;/strong&gt;: ~100 concurrent users, ~12 requests per second&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;API-heavy applications&lt;/strong&gt;: ~300-500 concurrent users, ~100 requests per second&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Video streaming&lt;/strong&gt;: Best kept local or limited quality&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Capacity Examples:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Scenario: Static website serving&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Page size: 500 KB&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Concurrent users: ~100&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Requests per second: ~12&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Scenario: API-heavy application&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Response size: 50 KB average&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Concurrent users: ~300-500&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Requests per second: ~100&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Despite limitations, performance remains smooth for my use cases. My website loads quickly for visitors, and I haven't experienced any significant slowdowns even with moderate traffic. These aren't huge numbers, but for personal use and small-scale services, they're perfectly adequate. The key is understanding the limitations and designing services accordingly.&lt;/p&gt;

&lt;p&gt;However, as I scale up and plan to self-host more projects, the upgrade I'm negotiating with my ISP will provide much more breathing room. With 10x the bandwidth, I could comfortably handle:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;1,000+ concurrent users on static sites&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Significantly improved video streaming quality&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Faster backup and replication&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Multiple high-traffic services running simultaneously&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Maintenance and Troubleshooting&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Regular maintenance is crucial. I've established a routine:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Weekly&lt;/strong&gt;: Check service health, review logs for errors&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Monthly&lt;/strong&gt;: Update all services and base images, verify backups&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Quarterly&lt;/strong&gt;: Full system review, optimize resource allocation&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When things break (and they will), having good documentation and backups is essential. I maintain a simple wiki documenting every service, its configuration, and common troubleshooting steps. This saved my life during the SSD incident—I could rebuild everything relatively quickly because I had documented the entire setup.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Future Improvements&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;A homelab is never truly finished. There's always something to improve, optimize, or add. There's always room to grow. Here are my plans for the near future:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Monitoring Dashboards&lt;/strong&gt;: I plan to set up proper monitoring with &lt;strong&gt;Prometheus + Grafana&lt;/strong&gt;. While Uptime Kuma tells me if services are up or down, I want deeper insights into performance metrics, resource usage trends, and potential bottlenecks. Prometheus will collect metrics from all services, and Grafana will visualize them in beautiful dashboards.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Automating Cluster Scaling&lt;/strong&gt;: Currently, my high availability is somewhat manual. I want to implement more automated failover routines and mechanisms so that if a node goes down, services automatically migrate to healthy nodes without manual intervention. This requires more sophisticated orchestration, but it's worth the effort for critical services. I'm also exploring ways to automate scaling based on load.&lt;/p&gt;

&lt;p&gt;🌐 &lt;strong&gt;Bandwidth Upgrade&lt;/strong&gt;: I'm actively working with my ISP to secure a dedicated connection. This increase in bandwidth will enable me to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Host more public-facing projects without performance concerns&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Improve response times for external users&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Handle significantly more concurrent traffic&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Stream high-quality media without buffering&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🖥️ &lt;strong&gt;Expanding the Cluster&lt;/strong&gt;: As my workloads increase, I'm considering adding a few more Proxmox nodes to the cluster. I plan to self-host ALL my side projects moving forward — no more paying for Vercel, Heroku, or similar platforms (at least till there is a justification) when I have perfectly capable infrastructure at home. Each new project is an opportunity to learn something new while saving money on hosting costs.&lt;/p&gt;

&lt;p&gt;🎓 &lt;strong&gt;AWS Local Mimic for Certifications&lt;/strong&gt;: One of my more ambitious plans is to create a local AWS-like environment for hands-on learning. I want to build something that mimics AWS services locally—think &lt;a href="https://www.localstack.cloud/localstack-for-aws" rel="noopener noreferrer"&gt;LocalStack&lt;/a&gt; on steroids. This would allow me to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Practice for AWS certifications without incurring costs&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Understand AWS architecture at a deeper level&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Experiment with complex multi-service architectures&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Build skills that transfer directly to professional cloud environments&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The goal isn't to perfectly replicate AWS, but to create enough similarity that I can practice real-world scenarios and prepare for professional certifications. Imagine setting up S3-like object storage, EC2-like compute instances, RDS-like databases, and Lambda-like serverless functions—all running locally on my homelab. It's an ambitious project, but that's exactly why I am investing in the homelab.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Building this homelab has been one of the most rewarding technical projects I've ever undertaken. It started as a simple desire to have cheap, reliable computing power for side projects, but it evolved into a comprehensive learning experience covering virtualization, networking, containerization, and infrastructure management. It taught me more about systems architecture, resource planning, and automation than any course could.&lt;/p&gt;

&lt;p&gt;What have I learned? Quite a lot, actually.&lt;/p&gt;

&lt;p&gt;First, infrastructure work is humbling. Things will break, often at the worst possible time. Whether it's accidentally destroying an SSD or dealing with unexpected service failures, you learn to troubleshoot under pressure and develop a healthy respect for backup systems.&lt;/p&gt;

&lt;p&gt;Second, start simple and don’t despise starting from scratch. Try new things, read about the technologies, map out a plan, and tick off the checklist. Don't let the complexity intimidate you because every expert started as a beginner who kept going.&lt;/p&gt;

&lt;p&gt;Third, self-hosting is empowering. There's something deeply satisfying about using services you built and control. No surprise pricing changes, no arbitrary feature removals, no worrying about a service shutting down. You're in control. When someone visits &lt;a href="https://jemeel.dev/" rel="noopener noreferrer"&gt;jemeel.dev&lt;/a&gt;, they're connecting to hardware sitting in my room, configured and maintained by me. That's incredible.&lt;/p&gt;

&lt;p&gt;The economics make sense. For roughly ₦1.8 million upfront and ₦30,000 monthly, I have infrastructure that would cost ₦1+ million per month on AWS or GCP. The homelab paid for itself in three months and will save me millions annually. Plus, I own the hardware; it's an asset that retains value.&lt;/p&gt;

&lt;p&gt;The homelab has dramatically improved my daily productivity and experimentation workflow. I can spin up test environments in minutes, deploy new ideas without worrying about cloud costs, and learn by doing rather than just reading documentation. More importantly, this project bridged the gap between theoretical knowledge and practical implementation. Reading about the tech is one thing; actually configuring it, troubleshooting networking issues, recovering from failures, and yes, even breaking SSDs, is something else entirely.&lt;/p&gt;

&lt;p&gt;Now, every time I deploy a new app or spin up a container, I'm reminded of the beauty of learning by doing. This homelab isn't just a cluster of PCs —  it's my digital playground, my sandbox for ideas, and a daily reminder that curiosity is the best teacher.&lt;/p&gt;

&lt;p&gt;If you're considering building your own homelab, my advice is simple: just start. You don't need expensive hardware or a perfect plan. Start with what you have, run a few services, break things (hopefully not your SSDs), fix them, and keep learning. The journey is the reward.&lt;/p&gt;

&lt;p&gt;And remember, whether you're using old Dell PCs like me or something fancier, the principles remain the same. Learn, experiment, iterate, and most importantly, have fun building your digital playground. The mistakes you make will teach you more than any tutorial ever could.&lt;/p&gt;

&lt;p&gt;Keep GOing, keep building, and enjoy the journey.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>docker</category>
      <category>proxmox</category>
      <category>learning</category>
    </item>
    <item>
      <title>Advance Data Types in Go: Arrays, Slices, Maps, Functions</title>
      <dc:creator>Odewole Abdul-Jemeel</dc:creator>
      <pubDate>Sun, 26 Nov 2023 15:56:10 +0000</pubDate>
      <link>https://dev.to/intellect4all/advance-data-types-in-go-arrays-slices-maps-functions-36cb</link>
      <guid>https://dev.to/intellect4all/advance-data-types-in-go-arrays-slices-maps-functions-36cb</guid>
      <description>&lt;p&gt;This article builds upon the last entry in the “Golang Primer” series, where we delved into the intricacies of Go syntax and covered fundamental language features, specifically focusing on primary data types in Golang. In this installment, we take a step further into the realm of advanced data types in Golang. Our exploration encompasses the various tools at our disposal for modeling, storing, and accessing data in diverse forms, tailored to different use cases.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Arrays&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Arrays in Go serve as ordered collections of items, all of the same type, possessing a fixed size allocated in memory upon creation. Following the convention of many programming languages, array indices commence at zero, indicating that counting starts from 0 rather than 1. In contrast, slices in Go represent a more dynamic alternative to arrays. Slices lack a predetermined length, allowing them to expand or contract based on demand.&lt;/p&gt;

&lt;p&gt;Due to the fixed nature of arrays (for instance, if an array of length 3 is created, it can accommodate no more than 3 items), they lack the adaptability required for many applications. To illustrate, adding a fourth item necessitates creating a new array with a larger size, copying the existing items, and then appending the new item. Consequently, slices emerge as the more prevalent choice in Go, and you will seldom encounter direct dealings with arrays.&lt;/p&gt;

&lt;p&gt;The syntax for declaring arrays in Go looks as follows:&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;var&lt;/span&gt; &lt;span class="n"&gt;fiveNames&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;

&lt;span class="n"&gt;fiveNames&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;5&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;"John"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Jean"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Joe"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Jim"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Jane"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// remember that we can only use the := shorthand inside a function&lt;/span&gt;
&lt;span class="n"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;fiveNames&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="c"&gt;// to get the first item, John&lt;/span&gt;
&lt;span class="n"&gt;secondName&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;fiveNames&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="c"&gt;// to get the second item, Jean&lt;/span&gt;

&lt;span class="n"&gt;lastName&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;fiveNames&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fiveNames&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// returns Jane&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;len()&lt;/code&gt; function, a built-in function in Go, plays a crucial role in array manipulation by returning the length of the array.&lt;/p&gt;

&lt;p&gt;Some key aspects distinguish arrays in Go:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Constant Size:&lt;/strong&gt; The size of an array in Go must be a constant, meaning it must be determinable at compile time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Type Differentiation by Size:&lt;/strong&gt; The size of an array is integral to its type. For example, &lt;code&gt;[3]int&lt;/code&gt; and &lt;code&gt;[4]int&lt;/code&gt; are distinct types.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Syntactic Sugar for Size Inference:&lt;/strong&gt; Go provides syntactic sugar for inferring the size of an array based on the number of elements. For instance:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;goCopy&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt;
&lt;span class="c"&gt;// This results in the type [5]string&lt;/span&gt;
&lt;span class="n"&gt;fiveNames&lt;/span&gt; &lt;span class="o"&gt;:=&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;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"John"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Jean"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Joe"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Jim"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Jane"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Copy Behavior in Function Arguments:&lt;/strong&gt; When arrays are passed as arguments to a function, the function receives a copy of the array. Consequently, any modifications or alterations within the function do not impact the original array.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These nuances contribute to the robust and statically typed nature of arrays in Go, ensuring both predictability and type safety in array-based operations. It's essential to recognize that due to their inherent inflexibility, arrays in Go are seldom employed in everyday applications. Instead, slices, a more dynamic and versatile data structure, are the predominant choice in Go programming.&lt;/p&gt;

&lt;p&gt;Slices provide a flexible alternative to arrays, adapting in size based on the requirements of the application. This adaptability makes slices better suited for a wide range of use cases, offering more convenience and ease of use compared to arrays.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Slices&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Slices, in simple terms, are like arrays but without a fixed size. They're akin to the concept of a &lt;code&gt;List&lt;/code&gt; in other popular programming languages. Behind the scenes, slices are built on arrays; they function as pointers to arrays. Unlike arrays, when slices are passed as arguments to a function, the function gets a reference or alias of the slice. This means that any changes made to the passed slice within the function also impact the original copy. It makes sense because a slice is always a pointer to another data structure, so any modifications to that underlying structure should affect anything else referencing or pointing to it. We'll delve into the details of pointers and referencing later.&lt;/p&gt;

&lt;p&gt;Creating a slice is as simple as declaring an array without specifying a fixed size:&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;// note that the [] is empty, that is indicating that this is a slice&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;sliceofNames&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;

&lt;span class="n"&gt;sliceOfNumbers&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are some common operations on slices:&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;// To get an item at an index, remember that the indexing is 0 based&lt;/span&gt;

&lt;span class="n"&gt;zero&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;sliceOfNumbers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;one&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;sliceOfNumbers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c"&gt;// this will create a new slice with items 2,3,4 and 5.&lt;/span&gt;
&lt;span class="c"&gt;// The operation follows the format s[i:j], where i is the start index &lt;/span&gt;
&lt;span class="c"&gt;// and j is the end index. Note that the operator will only get up to &lt;/span&gt;
&lt;span class="c"&gt;// the j-1 element and not include the end index in the resulting slice, &lt;/span&gt;
&lt;span class="c"&gt;// which is why we use 6 in the example to get the 6-1 index, &lt;/span&gt;
&lt;span class="c"&gt;// which is the index of number 5&lt;/span&gt;
&lt;span class="n"&gt;twoTo5&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;sliceOfNumbers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="m"&gt;6&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c"&gt;// we can also achieve the same result as above, &lt;/span&gt;
&lt;span class="c"&gt;// if the end index is skipped, as in this case, it defaults to len(s)&lt;/span&gt;
&lt;span class="c"&gt;// i.e the lenght of the slice, so everything till the end is included&lt;/span&gt;
&lt;span class="n"&gt;twoTo5&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;sliceOfNumbers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c"&gt;// if the start index is ignored, then the index 0 is used by default&lt;/span&gt;
&lt;span class="c"&gt;// i.e the new slice begins at the first index&lt;/span&gt;
&lt;span class="n"&gt;zeroToFour&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;sliceOfNumbers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Slices in Golang differ from some other languages, notably in the aspect of comparison using &lt;code&gt;==&lt;/code&gt;. To compare two slices, it's necessary to manually compare each item in the array.&lt;/p&gt;

&lt;p&gt;This is where the similarities between Golang slices and lists in other languages largely end. Tasks that may be familiar, such as &lt;code&gt;add&lt;/code&gt;, &lt;code&gt;pop&lt;/code&gt;, and &lt;code&gt;insert&lt;/code&gt;, often require more manual effort in Golang.&lt;/p&gt;

&lt;p&gt;Let's start with the task of adding an item to a slice. Golang provides a built-in &lt;code&gt;append&lt;/code&gt; function precisely for this purpose. The &lt;code&gt;append&lt;/code&gt; function takes a slice and a variadic number of arguments, allowing flexibility in the number of arguments passed—whether it be one, two, or an infinite amount.&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;newSlice&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;oldSlice&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;newItem&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c"&gt;// the append function has a variadic parameter, meaning we can pass &lt;/span&gt;
&lt;span class="c"&gt;// any amount of arguments after the slice&lt;/span&gt;
&lt;span class="n"&gt;newSlice&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;oldSlice&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;newItem1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;newItem2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;newItem3&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;span class="c"&gt;// or even append a slice to another&lt;/span&gt;
&lt;span class="n"&gt;newSlice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;slice1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;slice2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Removing an item from the slice is slightly more complicated:&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;names&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;"John"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Paul"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"George"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Ringo"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// remove the first element&lt;/span&gt;
&lt;span class="n"&gt;names&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c"&gt;// remove the last element&lt;/span&gt;
&lt;span class="n"&gt;names&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c"&gt;// remove the nth element in a slice&lt;/span&gt;
&lt;span class="c"&gt;// note that we created an anonymous function and assigned it to a variable&lt;/span&gt;
&lt;span class="n"&gt;removeNth&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;func&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="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&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="c"&gt;// check if the index is not out of range &lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nb"&gt;len&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="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="c"&gt;/// note the ..., i like to call it the spread operator&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;append&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="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;i&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="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="o"&gt;:&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;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;names&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;removeNth&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To remove the first item from a list (or slice, pun intended), we simply create a new slice starting from the second index to the end of the list and assign it to the original slice. It's worth noting that if the end index is not specified after the colon, it defaults to the length of the list.&lt;/p&gt;

&lt;p&gt;For removing the last item, a similar technique is employed. We copy from the start index up to the index of the last item, as illustrated in the example. Removing an item at a specific index, say the nth index, involves creating two slices: one from the start index up to the index to be removed, and another from after the index to be removed. These slices are then stitched together using the &lt;code&gt;append&lt;/code&gt; function. The &lt;code&gt;...&lt;/code&gt; syntax serves as a spread operator, allowing all elements of the items in the slice to be spread and passed to the &lt;code&gt;append&lt;/code&gt; function. This is possible because the &lt;code&gt;append&lt;/code&gt; function also accepts variadic inputs.&lt;/p&gt;

&lt;p&gt;To iterate over a slice, Golang provides a built-in &lt;code&gt;range&lt;/code&gt; method. This method iterates over the slice, returning the next item on each iteration, starting from the first item.&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;// the range returns to result, the first is the index, the second is the value&lt;/span&gt;
&lt;span class="c"&gt;// since we don't need the index in this example, we ignore it with the _ syntax&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="n"&gt;names&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;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// or if you prefer, you can use this common way&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&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;names&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&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;
  
  
  Maps
&lt;/h2&gt;

&lt;p&gt;In Go, a &lt;code&gt;map&lt;/code&gt; is essentially a reference to a hash table. A hash table is a type of data structure used for an unordered collection of key/value pairs. Each value in the collection is associated with a unique key, and this association is made possible by a function known as a "hash" function. Importantly, all keys within the hash table are unique and are created using the hash function.&lt;/p&gt;

&lt;p&gt;Hash tables are significant and valuable data structures, and I would strongly recommend delving deeper into understanding them. They play a crucial role in efficiently organizing and retrieving data based on unique keys, making them a cornerstone in various applications and algorithms.&lt;/p&gt;

&lt;p&gt;You can think of a map in Go as an unordered slice where we get to decide the key by which we want to identify an item, with the condition that the keys must be comparable with the &lt;code&gt;==&lt;/code&gt; syntax. A map has the below syntax, where the &lt;code&gt;K&lt;/code&gt; is the type of the key, and &lt;code&gt;V&lt;/code&gt; is the type of the value. The keys must have the same type, i.e you cannot use a &lt;code&gt;string&lt;/code&gt; as key for one item and then use &lt;code&gt;int&lt;/code&gt; it for another, and the values must also be of the same type.&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;var&lt;/span&gt; &lt;span class="n"&gt;newMap&lt;/span&gt; &lt;span class="k"&gt;map&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;K&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="n"&gt;V&lt;/span&gt;

&lt;span class="c"&gt;// using the := syntax&lt;/span&gt;
&lt;span class="n"&gt;mapOfAlphabetsToLanguages&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;map&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="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s"&gt;"A"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Ada"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"B"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"BASIC"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"C"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"C++"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"D"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Dart"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"E"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Erlang"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// or using the built in make function&lt;/span&gt;
&lt;span class="n"&gt;newMap&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;map&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="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You might be wondering why we would use the &lt;code&gt;make&lt;/code&gt; function when we already have the convenient &lt;code&gt;:=&lt;/code&gt; syntax. The reason lies in situations where we know the size of the map in advance. By specifying the size of the map using the &lt;code&gt;make&lt;/code&gt; function, like this: &lt;code&gt;make(map, sizeOfMap)&lt;/code&gt;, we can optimize resource usage and allocate an appropriately sized map from the start. This can be particularly beneficial when working with large datasets or in scenarios where efficiency and resource management are critical considerations.&lt;/p&gt;

&lt;p&gt;These are some common actions we can take on a map:&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;mapOfAlphabetsToLanguages&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;map&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="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s"&gt;"A"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Ada"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"B"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"BASIC"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"C"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"C++"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"D"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Dart"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"E"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Erlang"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// we can get the value by passing the key, &lt;/span&gt;
&lt;span class="n"&gt;ada&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;mapOfAlphabetsToLanguages&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"A"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="c"&gt;// note that this is case-sensitive&lt;/span&gt;

&lt;span class="c"&gt;// if we do this, there is no "a" key in the map, so the zero based value &lt;/span&gt;
&lt;span class="c"&gt;// for the type is returned, which is an empty string "" for strings.&lt;/span&gt;
&lt;span class="n"&gt;ada2&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;mapOfAlphabetsToLanguages&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"a"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c"&gt;// we can reassign the values of a key,&lt;/span&gt;
&lt;span class="c"&gt;// the value of the key "A" is now "ActionScript"&lt;/span&gt;
&lt;span class="n"&gt;mapOfAlphabetsToLanguages&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"A"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"ActionScript"&lt;/span&gt;

&lt;span class="c"&gt;// we can use the builtin delete function to delete a key-value pair from the map&lt;/span&gt;
&lt;span class="c"&gt;// the key "A" is now deleted from the map&lt;/span&gt;
&lt;span class="nb"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mapOfAlphabetsToLanguages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"A"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c"&gt;// we can use the len function to get the length of the map&lt;/span&gt;
&lt;span class="c"&gt;// the length of the map is 4&lt;/span&gt;
&lt;span class="n"&gt;lengthOfMap&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mapOfAlphabetsToLanguages&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c"&gt;// we can use the range keyword to iterate over the map&lt;/span&gt;
&lt;span class="c"&gt;// the order of the iteration is not guaranteed&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="n"&gt;mapOfAlphabetsToLanguages&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;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&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;As demonstrated in the example code above, attempting to retrieve a key that is not defined in the map does not result in an error; instead, you receive the zero value of that type. However, there are cases where it's crucial to ascertain whether the key truly exists in the map, and Go provides a convenient way to do this:&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;goCopy&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt;
&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;theMap&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"wrongKey"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Here, the variable &lt;code&gt;ok&lt;/code&gt; is a boolean that is &lt;code&gt;true&lt;/code&gt; when the key is present and &lt;code&gt;false&lt;/code&gt; when the key is not found in the map. This mechanism proves helpful in handling scenarios where the existence of a key needs to be validated. It's worth noting that the name &lt;code&gt;ok&lt;/code&gt; is a convention, and you can choose any variable name, such as &lt;code&gt;notOk&lt;/code&gt;; however, using &lt;code&gt;ok&lt;/code&gt; is a common practice for readability and consistency.&lt;/p&gt;

&lt;p&gt;So in what cases should you use a &lt;code&gt;slice&lt;/code&gt; or a &lt;code&gt;map&lt;/code&gt;? The choice between using a slice or a map in Go depends on the specific requirements of your data structure. Here are some guidelines to help you decide:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use a Slice if:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;You need an ordered collection.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The order of elements matters, and you want to preserve it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Indexing is essential, and you care about the position of elements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You are frequently shuffling or manipulating the collection.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Use a Map if:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The collection does not need to be ordered.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You require key/value pairs, where each element has a unique and comparable key.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Absolute control over indexing is not critical, and you can use the key for retrieval.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You need to check for the existence of a particular key efficiently.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For example, you might store all student details in a slice if the order of entry is important. On the other hand, if you need to associate each student with a unique identifier (like a student ID) and their corresponding grade, a map would be a more suitable choice. This provides a key/value relationship, making it efficient to retrieve grades based on student IDs. The decision ultimately hinges on the specific characteristics and use cases of your data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Functions
&lt;/h2&gt;

&lt;p&gt;A function in Golang serves as a reusable unit of code designed to accomplish a specific task. It enables us to break down a large task into more manageable components that can be abstracted away from users, facilitating repetitive actions without the need to rewrite the implementation every time. The basic syntax of a function in Golang is as follows:&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;functionName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;parameters&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="o"&gt;...&lt;/span&gt;
    &lt;span class="c"&gt;// body&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;p&gt;A function is named, which can be anything descriptive except for reserved keywords. It is followed by a pair of brackets &lt;code&gt;(&lt;/code&gt; and &lt;code&gt;)&lt;/code&gt; that contain the parameters the function can accept and work with. After that comes the result types, defining the types of outcomes returned to the function invoker. The function body is enclosed in a pair of curly brackets &lt;code&gt;{&lt;/code&gt; &lt;code&gt;}&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let us write a function that gives us the sum of a list of integers:&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;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;sum&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This &lt;code&gt;sum&lt;/code&gt; function takes a slice of integers (&lt;code&gt;[]int&lt;/code&gt;) as a parameter and returns an integer.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Inside the function, we initialize a variable &lt;code&gt;sum&lt;/code&gt; to 0. Note that the variable name (&lt;code&gt;sum&lt;/code&gt;) is arbitrary, but it's good practice to choose a name that reflects the variable's purpose.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Utilizing the &lt;code&gt;range&lt;/code&gt; method, we iterate over the slice to access individual numbers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For each &lt;code&gt;number&lt;/code&gt; in the slice, we add it to the &lt;code&gt;sum&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After the loop completes, we use the &lt;code&gt;return&lt;/code&gt; keyword to send the result back to the invoker of the function. The invoker is essentially the entity that is called the function.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can then use the function in our code like this:&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;listOfNumbers&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;sum1&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;listOfNumbers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;listOfNumbers2&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="m"&gt;584&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;392&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2834&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;83&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;4839&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;sum2&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;listOfNumbers2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Consider another example function:&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;sumAndCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt; &lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;
    &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt;
        &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This function, named &lt;code&gt;sumAndCount&lt;/code&gt;, is similar to the previous one but with an added feature. Instead of only calculating the sum, it also returns the count of elements in the provided slice.&lt;/p&gt;

&lt;p&gt;Take note of a couple of key features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The function employs a variadic parameter denoted by &lt;code&gt;...&lt;/code&gt; before the type (&lt;code&gt;...int&lt;/code&gt;), indicating that the function can accept any number of &lt;code&gt;int&lt;/code&gt; parameters.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The result syntax is now &lt;code&gt;(int, int)&lt;/code&gt;, indicating that the function returns two values, both of type &lt;code&gt;int&lt;/code&gt;: the sum and the count.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;sum1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;count1&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;sumAndCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;listOfNumbers2&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="m"&gt;584&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;392&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2834&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;83&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;4839&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// we use the spread operator to `spread` the content of the slice to the function&lt;/span&gt;
&lt;span class="n"&gt;sum2&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;sumAndCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;listOfNumbers2&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;p&gt;Here's another example demonstrating an alternative function syntax:&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;// divideAndRemainder divides two numbers and &lt;/span&gt;
&lt;span class="c"&gt;// returns the quotient and remainder.&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;divideAndRemainder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dividend&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;divisor&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;quotient&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;remainder&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;quotient&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dividend&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;divisor&lt;/span&gt;
    &lt;span class="n"&gt;remainder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dividend&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;divisor&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="c"&gt;// This return statement implicitly returns the named values (quotient, remainder)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;This function takes two parameters, &lt;code&gt;dividend&lt;/code&gt;, and &lt;code&gt;divisor&lt;/code&gt;, both of type &lt;code&gt;int&lt;/code&gt;. As they share the same type, Go allows us to omit the types for all but the last one.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The primary focus of this function is on the results. Yes, these are named results. Golang permits us to name the results, which can be advantageous in various scenarios. Named results act like variables; they are initialized with their zero values and are assignable within the function, hence the use of &lt;code&gt;=&lt;/code&gt; in assignments like &lt;code&gt;quotient = dividend / divisor&lt;/code&gt;, instead of the &lt;code&gt;:=&lt;/code&gt; syntax.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Notice the absence of an explicit return statement? That's because the results are named, and Go automatically returns them from the function. The &lt;code&gt;return&lt;/code&gt; statement at the end of the function implicitly returns the named values (quotient, remainder).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Named Arguments and Default Values in Golang&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you observe, when invoking functions in Go, we don't use named arguments. In some languages, invoking the &lt;code&gt;divideAndRemainder&lt;/code&gt; function might look like this:&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;// Name arguments in some languages&lt;/span&gt;
&lt;span class="n"&gt;divideAndRemainder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dividend&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;17&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;divisor&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, in Go, there is no concept of named arguments. All arguments must be passed in the same order as the parameters are declared in the function:&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;// Go has no concept of named arguments&lt;/span&gt;
&lt;span class="n"&gt;divideAndRemainder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;17&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Additionally, it's crucial to note that Golang lacks the concept of default values. In Go, all parameters declared in a function must be explicitly passed as arguments when invoking the function. This simplicity and explicitness contribute to the clarity and predictability of Go code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Anonymous Functions in Go&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Anonymous functions, as showcased in the example, are functions in Go that don't have a name. In Go, it's not allowed to create a named function within another function. However, there are scenarios, like the one presented here, where a function is only useful in the current context, and in such cases, we can resort to using anonymous functions.&lt;/p&gt;

&lt;p&gt;Here's an example:&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;names&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;"John"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Paul"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"George"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Ringo"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// Remove the first element&lt;/span&gt;
&lt;span class="n"&gt;names&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c"&gt;// Remove the last element&lt;/span&gt;
&lt;span class="n"&gt;names&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c"&gt;// Remove the nth element in a slice&lt;/span&gt;
&lt;span class="c"&gt;// Note that we created an anonymous function and assigned it to a variable&lt;/span&gt;
&lt;span class="n"&gt;removeNth&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;func&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="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&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="c"&gt;// Check if the index is not out of range&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nb"&gt;len&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="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="c"&gt;// Use the "spread" operator (...) to remove the element at index i&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;append&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="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;i&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="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="o"&gt;:&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;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;names&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;removeNth&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Anonymous functions are declared using the &lt;code&gt;func&lt;/code&gt; keyword, similar to named functions, but without including a name. They prove useful when you need to group a block of code together, especially in cases where the function is only intended to be executed once or when defining a function within another function is necessary, as seen in callbacks.&lt;/p&gt;

&lt;p&gt;Here are additional examples to deepen our understanding:&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;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// Example 1: Anonymous function assigned to a variable&lt;/span&gt;
    &lt;span class="n"&gt;add&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;result1&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;5&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;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Result 1: %d&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s"&gt;n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c"&gt;// Example 2: Immediately invoked anonymous function&lt;/span&gt;
    &lt;span class="n"&gt;result2&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;
    &lt;span class="p"&gt;}(&lt;/span&gt;&lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// Note that this function is called immediately with ()&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;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Result 2: %d&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s"&gt;n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c"&gt;// Example 3: Passing an anonymous function as an argument&lt;/span&gt;
    &lt;span class="n"&gt;calculate&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;operation&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;operation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;result3&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;calculate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="m"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;3&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;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Result 3: %d&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s"&gt;n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result3&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;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Example 1&lt;/strong&gt; demonstrates an anonymous function assigned to the variable &lt;code&gt;add&lt;/code&gt;. This function adds two integers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Example 2&lt;/strong&gt; shows an immediately invoked anonymous function. The function is defined and called in a single line to calculate the product of two numbers. Notice the function invocation &lt;code&gt;()&lt;/code&gt; immediately following the function block &lt;code&gt;{}&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Example 3&lt;/strong&gt; showcases passing an anonymous function as an argument to another function (&lt;code&gt;calculate&lt;/code&gt;). The &lt;code&gt;calculate&lt;/code&gt; function takes an operation and two integers, applying the operation to the integers. This example demonstrates how to parameterize the &lt;code&gt;calculate&lt;/code&gt; function, allowing the invoker to supply a function fitting the specified interface.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Congratulations! You have made it to the end of this session As we conclude this session, we've delved into the fundamental aspects of Golang, exploring syntax intricacies, understanding data types, and delving into the world of functions, including the intriguing concept of anonymous functions.&lt;/p&gt;

&lt;p&gt;However, our journey into Golang is far from over. In the forthcoming segments of the "Golang Primer," we are poised to explore advanced data types, delving into the nuances of structs, interfaces, pointers, and the critical domain of error handling in Golang.&lt;/p&gt;

&lt;p&gt;Please feel free to drop any questions you have and I will be happy to answer them. You can connect with me via my email &lt;a href="mailto:intellectualjemeel@gmail.com"&gt;intellectualjemeel@gmail.com&lt;/a&gt;, I am &lt;a href="https://www.linkedin.com/in/abduljemeel-odewole-393a0b105/" rel="noopener noreferrer"&gt;here&lt;/a&gt; on LinkedIn and &lt;a href="https://twitter.com/intellect4all" rel="noopener noreferrer"&gt;here&lt;/a&gt; on Twitter, let’s connect.&lt;/p&gt;

</description>
      <category>go</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Understanding Go Syntax and Language Features</title>
      <dc:creator>Odewole Abdul-Jemeel</dc:creator>
      <pubDate>Sun, 05 Nov 2023 07:45:06 +0000</pubDate>
      <link>https://dev.to/intellect4all/understanding-go-syntax-and-language-features-3nci</link>
      <guid>https://dev.to/intellect4all/understanding-go-syntax-and-language-features-3nci</guid>
      <description>&lt;p&gt;In this article, I will be introducing you to the basic foundation of reading and writing GoLang. Go is one of the simplest programming languages, which is one of the many reasons many developers love the language so much (find out other reasons why Go is so popular &lt;a href="https://dev.to/intellect4all/a-comprehensive-introduction-to-golang-5ab5"&gt;here&lt;/a&gt;). Go programs are stored in a text file with a &lt;code&gt;.go&lt;/code&gt; extension, e.g &lt;code&gt;main.go&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Programming is just a sequence of written instructions for a computer, and large applications are built by the composition of tiny and simple other instructions. Understanding how to create and combine these tiny instructions is the foundation of programming. Let us start from the basics and build our way up.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Variables&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;A variable serves as a storage location on the computer, identified by a name for easy reference. and since it is a storage, it can hold a quantity of data or object of a particular type. For example, if we need to store the age of a person in memory, we can do so like this,&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;var&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;20&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, &lt;code&gt;age&lt;/code&gt; is the name of the variable, the type (we are coming to this) of data that the variable contains is &lt;code&gt;int&lt;/code&gt; (which means integer) and &lt;code&gt;20&lt;/code&gt; is the value that will be stored in the variable.&lt;/p&gt;

&lt;p&gt;Or to store the value of a complex calculation (not really), we can do this, for example&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;var&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Declaring a value in GoLang often follows the following format,&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;var&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;expression&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;var&lt;/code&gt; is a keyword in Golang to tell the compiler that we are creating a variable, the &lt;code&gt;name&lt;/code&gt; is the reference to which we want our variable to be known and accessed, the &lt;code&gt;type&lt;/code&gt; is the type of data the variable can hold, the &lt;code&gt;=&lt;/code&gt; is the assignment operator, and the &lt;code&gt;expression&lt;/code&gt; is the value to be stored in the variable. If the expression is not provided, the variable is created and initialized with the zero value of the type. A zero value simply means a default value.&lt;/p&gt;

&lt;p&gt;For instance, if we declare our variable like so,&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;var&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we did not specify any value to be stored in the variable, so Go creates the variable and sets its value to 0, which is the default value for number types.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Zero values for different types&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;0 for numbers&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;false for booleans&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“” for strings (note, “” is an empty string)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;nil&lt;/code&gt; for interfaces and reference types (we are coming to this)&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When creating multiple variables of the same type, you can efficiently do so on a single line, as demonstrated 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="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;mean&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;median&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As always, the &lt;code&gt;var&lt;/code&gt; is the keyword for declaration, &lt;code&gt;mean, median, mode, total, count&lt;/code&gt; are the variables to be created, and they are all of the same type as the type declared at the end of the line, which is &lt;code&gt;int&lt;/code&gt; in this case. And remember, since we did not include any expression, they are all created with their zero values, so they all have the value of 0.&lt;/p&gt;

&lt;p&gt;If perhaps we know the data ahead, we can create them in one line by providing the values separated by commas in the exact order in which the variables are created, like 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="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;mean&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;median&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;120&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;

&lt;span class="c"&gt;// 20 is assigned to mean, 15 to median, and so on, in that order&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to create many variables of different types in one line, you can do so like this,&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;var&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sex&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;isPresent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"John"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Male"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;

&lt;span class="c"&gt;// "John" is assigned to name, 12 to age, "Male" to sex, and true to isPresent&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Multiple variables can also be created in the format 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="k"&gt;var&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;name&lt;/span&gt;      &lt;span class="kt"&gt;string&lt;/span&gt;
        &lt;span class="n"&gt;age&lt;/span&gt;       &lt;span class="kt"&gt;int&lt;/span&gt;
        &lt;span class="n"&gt;sex&lt;/span&gt;       &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Male"&lt;/span&gt;
        &lt;span class="n"&gt;isPresent&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;false&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And just like we have established, remember that if we don’t define an expression for the variable, it is created with the zero value. So in this case, &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;age&lt;/code&gt; are created with zero values while &lt;code&gt;sex&lt;/code&gt; and &lt;code&gt;isPresent&lt;/code&gt; have the values “Male” and &lt;code&gt;false&lt;/code&gt; respectfully.&lt;/p&gt;

&lt;p&gt;Please note that expression can also be the output of a function (think of a function as a group of common code executing a particular task). Let’s say we have a function that computes the square of a number, we can store the result of this function when we calculate the square of 5 in a variable,&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;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;squareOfFive&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Square&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;5&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;squareOfFive&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// this is a function, we will discuss it in details in the next article&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;Square&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In some cases, especially if you want the variable to automatically be the type of the expression, you don’t need to explicitly specify the type, you can omit it, and Go will automatically infer the type of the variable from the type of value of the expression. So in this case of,&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;var&lt;/span&gt; &lt;span class="n"&gt;squareOfFive&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Square&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we can simply omit the &lt;code&gt;int&lt;/code&gt; and the variable will automatically assume the type of the returned data, like so:&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;// squareOfFive will automatically assume the type &lt;/span&gt;
&lt;span class="c"&gt;// of the data retured by the Square method, which is int in this case&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;squareOfFive&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Square&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This may be useful in some cases, but most times, you always want to declare the type of the variable, so your code can be simple, and readable.&lt;/p&gt;

&lt;p&gt;There is an alternate way of creating a variable in GoLang, also known as a short variable declaration. This form of declaration is only permissible within a function and only used to declare local variables within the scope of the function. It takes the form:&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;// take not of the symbol&lt;/span&gt;
&lt;span class="n"&gt;variableName&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;expression&lt;/span&gt; 

&lt;span class="c"&gt;// the syntax is a semicolon followed by equals, :=&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This method of variable declaration is prevalent and the syntax &lt;code&gt;:=&lt;/code&gt; is often confusing for people who are not familiar with Golang syntax. Let’s see it in an example, suppose we want to write a function that returns the average of 5 numbers, we can decide that we will compute the total of the 5 numbers and put it in a variable, then return the division of that variable by the count:&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;AverageofFiveNumbers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// you cannot do this outside of a function, it will throw an error&lt;/span&gt;
&lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;20&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This function is purely for demonstration and you will probably never be writing simple code like this in production. As you can see, we omitted the &lt;code&gt;var&lt;/code&gt; keyword when we declared the &lt;code&gt;total&lt;/code&gt; variable, other rules of variables apply to this too, as it is simply a variable too, but just created with another syntax (and remember that you can only use this &lt;code&gt;:=&lt;/code&gt; syntax in a function).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Variables are mutable and reassignable!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After we create a variable, we can overwrite the data later in the code to hold new information, as long as the new information is of the same type as the old value. For instance, after calculating the &lt;code&gt;squareOfFive&lt;/code&gt; in the code below, we can overwrite it later in the code, to hold the wrong data.&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;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;squareOfFive&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Square&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;5&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;squareOfFive&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// 25 is printed&lt;/span&gt;

    &lt;span class="n"&gt;squareOfFive&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;10&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;squareOfFive&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// 10 is printed&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;Square&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you run the code, you will see that the value &lt;code&gt;squareOfFive&lt;/code&gt; is overwritten with the wrong data. For this reason, variables are used to hold data that can be manipulated in the program (hence the name, it is not fixed).&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Constants&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;We have already established that variables can be overwritten and changed in the code, whether intentionally or even by mistake, which is a very good thing, because most times, we make things work by manipulating the variables and changing their values at runtime. However, there are times when we need data storage to be fixed and immutable, i.e. it should be constant.&lt;/p&gt;

&lt;p&gt;For example, if we are running a mathematical calculation that involves &lt;code&gt;Pi&lt;/code&gt; , and some other mathematical constants, we do not want our code to be able to change their values, whether willingly or by mistake. In that case, we use, well, CONSTANTS.&lt;/p&gt;

&lt;p&gt;Constants are data storage marked as immutable and are created at the program compile time. They can only be numbers, characters, strings, or booleans. And because they are constants, the expressions that define them must also be constant and can be evaluated by the compiler.&lt;/p&gt;

&lt;p&gt;To create a constant, use the keyword &lt;code&gt;const&lt;/code&gt; , e,g:&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;const&lt;/span&gt; &lt;span class="n"&gt;speedOfLight&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;299792458&lt;/span&gt; &lt;span class="c"&gt;// m/s&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It follows the same format as when creating a variable, just replace the &lt;code&gt;var&lt;/code&gt; keyword with &lt;code&gt;const&lt;/code&gt;. If we try to mutate the value of the constant &lt;code&gt;speedOfLight&lt;/code&gt; later in our code, we will get an error and our code will not compile.&lt;/p&gt;

&lt;p&gt;If we need to create multiple constants, we can do this:&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;const&lt;/span&gt; &lt;span class="n"&gt;speedOfLight&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;speedOfSound&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;299792458&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;343&lt;/span&gt;

&lt;span class="c"&gt;// or &lt;/span&gt;

&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;speedOfLight&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;299792458&lt;/span&gt;
    &lt;span class="n"&gt;speedOfSound&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;343&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But remember that constants cannot be mutated, so we cannot have zero values or use any expression that implies that. Every value of the constant must be known at compile time.&lt;/p&gt;

&lt;p&gt;There is also an &lt;code&gt;iota&lt;/code&gt; keyword that is used to enumerate constants. For example, if we need to declare the days of the week with an index, starting with Sunday at index 0, we can use iota to make things easier like so:&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;const&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;SUNDAY&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;iota&lt;/span&gt;
        &lt;span class="n"&gt;MONDAY&lt;/span&gt;
        &lt;span class="n"&gt;TUESDAY&lt;/span&gt;
        &lt;span class="n"&gt;WEDNESDAY&lt;/span&gt;
        &lt;span class="n"&gt;THURSDAY&lt;/span&gt;
        &lt;span class="n"&gt;FRIDAY&lt;/span&gt;
        &lt;span class="n"&gt;SATURDAY&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code, the &lt;code&gt;iota&lt;/code&gt; assigned the value 0 to Sunday, then increments to 1 for Monday, 2 for Tuesday, and so on. This can be very useful if we just need to quickly enumerate and increment some constants by a value.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Data Types&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;We have established that data type is the type of value that is stored in a variable. It is how we know about the data we have and how we can interact with the data.&lt;/p&gt;

&lt;p&gt;In Golang, there are four categories of data types:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Primary types:&lt;/strong&gt; Primary types are the data types that are pre-defined and built into the language and are the fundamental building blocks of the language. Examples are integers, strings, and booleans.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Aggregate types:&lt;/strong&gt; Aggregate types, as the name implies, are data types that combine simple primary data types to form complex ones. Examples are arrays and structs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reference types:&lt;/strong&gt; Reference types are data types that are used for dynamic management and accessibility of data locations and addresses in memory. Examples include pointers, slices, maps, and channels.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Interface types:&lt;/strong&gt; Interface types are used to express generalization or abstraction about the behaviors of other types.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let us dive into the primary data types in Golang, we will look at the other advanced types later in future articles.&lt;/p&gt;

&lt;h3&gt;
  
  
  Integers
&lt;/h3&gt;

&lt;p&gt;Numbers are very important in programming and all languages provide ways to work with different types of numbers for different use cases. In Go, there are several sizes of integers, floating point numbers, and complex numbers to work with.&lt;/p&gt;

&lt;p&gt;Go provides both signed and unsigned integer arithmetic. Signed integers simply mean the type can represent both positive and negative numbers, while unsigned integers mean that the type can only represent non-negative numbers. Signed integers are represented by &lt;code&gt;int&lt;/code&gt; in Go while unsigned integers are represented by &lt;code&gt;uint&lt;/code&gt;. &lt;code&gt;int&lt;/code&gt; is the most used integer type and so it is often the recommended choice for integers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sizes of integers&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;int8 - 8 bits&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;int16 - 16 bits&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;int32 - 32 bits&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;int64 - 64 bits&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;uint8 - 8 bits&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;uint16 - 16 bits&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;uint32 - 32 bits&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;uint64 - 64 bits&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The bits specify the range of the storage capacity of each type, the higher the size of the bit, the more number the type can hold. There is also a type &lt;code&gt;rune&lt;/code&gt; which is often used in place of &lt;code&gt;int32&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Many operations can be performed on integers, some of them are addition &lt;code&gt;+&lt;/code&gt;, subtraction &lt;code&gt;-&lt;/code&gt;, multiplication &lt;code&gt;*&lt;/code&gt; , division &lt;code&gt;/&lt;/code&gt; , remainder &lt;code&gt;%&lt;/code&gt;, and comparison operations (compares the values of left and right and returns a boolean) e.g equals &lt;code&gt;==&lt;/code&gt;, not equal &lt;code&gt;!=&lt;/code&gt;, less than &lt;code&gt;&amp;lt;&lt;/code&gt;, greater than &lt;code&gt;&amp;gt;&lt;/code&gt; and so on. There are also operations like &lt;code&gt;+=&lt;/code&gt;, &lt;code&gt;-=&lt;/code&gt;, &lt;code&gt;*=&lt;/code&gt; which means performing this operation with the expression, and then assigning the result as the new data. For instance:&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;var&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;

&lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;

&lt;span class="c"&gt;// which is same as&lt;/span&gt;
&lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;

&lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;

&lt;span class="c"&gt;// which is same as&lt;/span&gt;
&lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;

&lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;*=&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;

&lt;span class="c"&gt;// which is samea s&lt;/span&gt;
&lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Floating-Point Numbers
&lt;/h3&gt;

&lt;p&gt;Floating points numbers are simply decimal numbers, and Go provides two data types to work with them - &lt;code&gt;float32&lt;/code&gt; and &lt;code&gt;float64&lt;/code&gt;. The difference between these two types is also the data capacity. While the &lt;code&gt;float32&lt;/code&gt; provides approximately six decimal digits of precision, the &lt;code&gt;float64&lt;/code&gt; provides 15 digits, so it is often used for most floating number applications.&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;const&lt;/span&gt; &lt;span class="n"&gt;pi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;3.141592653589793&lt;/span&gt;
&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;discount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;.3&lt;/span&gt; &lt;span class="c"&gt;// notice that the 0 is omitted, this is permissible in Go.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also write floating point numbers with scientific notation,&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;const&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;3.456e11&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Strings
&lt;/h3&gt;

&lt;p&gt;A string is an immutable sequence of bytes, and is often human-readable text.&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;var&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"John"&lt;/span&gt; &lt;span class="c"&gt;// John is a string&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The length of a string can be determined by the &lt;code&gt;len(string)&lt;/code&gt; function. Strings are just a list of individual characters and are indexed from left to right, and the count starts from zero. E.g&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;var&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"John"&lt;/span&gt;

&lt;span class="n"&gt;John&lt;/span&gt;
&lt;span class="m"&gt;0123&lt;/span&gt;

&lt;span class="c"&gt;// we can get the first character by passing the index in a square bracket&lt;/span&gt;

&lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;h&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, when indexing a string, take note not to let the index go out of the bound of the string length as that can cause an indexing error.&lt;/p&gt;

&lt;h3&gt;
  
  
  Booleans
&lt;/h3&gt;

&lt;p&gt;Booleans, represented as &lt;code&gt;bool&lt;/code&gt; in Go can only be &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;. They are often used to represent possibilities of two logical states, e.g light is on or off (&lt;code&gt;true&lt;/code&gt; for on, and &lt;code&gt;false&lt;/code&gt;, for off.)&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;var&lt;/span&gt; &lt;span class="n"&gt;isLightOn&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;false&lt;/span&gt;

&lt;span class="n"&gt;isLightOn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;They are used in conditions for control flows and are the outputs of comparison operations such as &lt;code&gt;==&lt;/code&gt;, &lt;code&gt;&amp;lt;=&lt;/code&gt;, &lt;code&gt;&amp;gt;=&lt;/code&gt;, &lt;code&gt;!=&lt;/code&gt;. The &lt;code&gt;!&lt;/code&gt; syntax is used to negate the values of Booleans, it often reads as &lt;code&gt;not&lt;/code&gt;. For instance,&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;var&lt;/span&gt; &lt;span class="n"&gt;isLightOn&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;false&lt;/span&gt;

&lt;span class="n"&gt;isLightOn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;isLightOn&lt;/span&gt; &lt;span class="c"&gt;// note exclamation&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code means that the value of &lt;code&gt;isLightOn&lt;/code&gt; should be the opposite of whatever the current value is, so if it is false, it becomes true, and if it is true, it becomes false.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Control Structures: Loops and Conditional Statements.&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Control structures are used to analyze the state of the program and decide the direction of execution based on the given state. They are the basic decision-making process in programming.&lt;/p&gt;

&lt;p&gt;Control statements mostly allow you to do two things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Execute some statements while skipping others&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Repeat one or more statements while some conditions are met.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Loops
&lt;/h3&gt;

&lt;p&gt;There is only one way to loop in Go, and that is with the &lt;code&gt;for&lt;/code&gt; loop. A loop is an iteration/rerun of a block of code until a certain condition is met. The condition is specified by the programmer and the program will not proceed until the condition of the loop becomes false, and if the condition is never met (i.e never false), the loop will run till infinity and eventually crash the computer (don’t worry, most computers can handle this elegantly). A &lt;code&gt;for&lt;/code&gt; loop usually has this format, notice how the components are separated by semicolons, it is very important.&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;for&lt;/span&gt; &lt;span class="n"&gt;initialization&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;condition&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// do this&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;there are three basic parts of the for loop:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The initialization: this is called before the first iteration, so it is often used to do some pre-calculations, run a short code, or for variable declaration before the loop runs. Often used for short variable declarations, and any variable declared there is only available in the scope of the loop i.e in the block of code contained between the &lt;code&gt;{&lt;/code&gt; and &lt;code&gt;}&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;the condition: this is run before every iteration, so it is where the comparison needed to check if the loop should run is done. If the value of this condition is false, then the loop stops running, and the program proceeds to the code following the for loop,&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;the post: this part of the loop is executed at the end of every iteration, so it is where the necessary variables are incremented and updated ahead of the next iteration.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let us write a simple for loop that counts from 0 to 9;&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;// remember to import the fmt package&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&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;i&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;This code will run 10 times. It declares &lt;code&gt;i&lt;/code&gt; to be zero at the initialization (which is run only once and before the for loop begins), then it checks the condition &lt;code&gt;i &amp;lt; 10&lt;/code&gt; , and since &lt;code&gt;i&lt;/code&gt; is 0 at this point, the condition is true, so the code runs, and 0 is printed to the console. Immediately after that, the post is run and &lt;code&gt;i++&lt;/code&gt; executed. &lt;code&gt;++&lt;/code&gt; is a syntax meaning increment the current value by one,&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;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;

&lt;span class="c"&gt;// is the same as &lt;/span&gt;

&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and since &lt;code&gt;i&lt;/code&gt; is zero, &lt;code&gt;++&lt;/code&gt; increments &lt;code&gt;i&lt;/code&gt; to &lt;code&gt;1&lt;/code&gt;. This completes the cycle for the first iteration. On the second iteration, the initialization is skipped, and the condition is checked again, this time, we know &lt;code&gt;i&lt;/code&gt; is 1, so the condition is true again since 1 is &lt;code&gt;&amp;lt;&lt;/code&gt; 10. The loop is run and &lt;code&gt;1&lt;/code&gt; printed to the console, after which the post part is run to increment &lt;code&gt;i&lt;/code&gt; to 2 and complete the cycle of the second iteration. This is repeated until &lt;code&gt;i&lt;/code&gt; is incremented up to 10 the condition fails and the loop is closed and the program continues to the next line after the loop, which is why you don’t see the 10 printed in the console.&lt;/p&gt;

&lt;p&gt;There is no &lt;code&gt;while&lt;/code&gt; or &lt;code&gt;do while&lt;/code&gt; that you may be familiar with in other languages in Go. You only have the &lt;code&gt;for&lt;/code&gt;. To achieve a while loop, you can simply drop the initialization and post part of the for loop, as those are optional, and only declare a condition:&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;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;1000&lt;/span&gt;
    &lt;span class="n"&gt;noOfTimesDivisibleBy14&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="m"&gt;14&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c"&gt;// this works like a while loop&lt;/span&gt;
        &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="m"&gt;14&lt;/span&gt;
        &lt;span class="n"&gt;noOfTimesDivisibleBy14&lt;/span&gt;&lt;span class="o"&gt;++&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;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"No of times divisible is %v, remainder is %v"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;noOfTimesDivisibleBy14&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;number&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;If you omit the condition, you can create an infinite loop that runs forever;&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;for&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// this is an infinite loop. &lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To break out of a loop, you can use the &lt;code&gt;break&lt;/code&gt; keyword to stop the iteration and break away from the loop irrespective of the condition, then the program continues to the next line after the loop body.&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;count&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; 

&lt;span class="k"&gt;for&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;count&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;count&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="m"&gt;1000&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt; &lt;span class="c"&gt;// stop the loop and continue&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c"&gt;// the program continues running here&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that you can also use a &lt;code&gt;return&lt;/code&gt; keyword to close the loop irrespective of the conditions, but instead of continuing to the next line after the loop like in the case of &lt;code&gt;break&lt;/code&gt; above, the program returns completely from that scope.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conditional Statements
&lt;/h2&gt;

&lt;h3&gt;
  
  
  if
&lt;/h3&gt;

&lt;p&gt;The if statement is used to check if a block of code should be executed or not. it usually follows the following expression:&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;if&lt;/span&gt; &lt;span class="n"&gt;initialization&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;condtion&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// do something conditionally&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;initialization&lt;/code&gt;, as we saw in the &lt;code&gt;for&lt;/code&gt; loop is where we can make some variable declarations before the &lt;code&gt;condition&lt;/code&gt; is checked, and if the condition is &lt;code&gt;true&lt;/code&gt; the code in the block &lt;code&gt;{}&lt;/code&gt; will run and any variable created in the &lt;code&gt;initialization&lt;/code&gt; will be available in the scope of that block. If the condition is &lt;code&gt;false&lt;/code&gt;, the block is skipped and the program proceeds to the next line after the if condition.&lt;/p&gt;

&lt;p&gt;There is also an &lt;code&gt;else&lt;/code&gt; part of the if, though it is optional. The &lt;code&gt;else&lt;/code&gt; block will run if the condition of the if statement is false.&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;if&lt;/span&gt; &lt;span class="n"&gt;condtion&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// do this, only if the condition is true&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;second&lt;/span&gt; &lt;span class="n"&gt;condition&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// or do this, if first condition is false and second condition is true&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// if any of the previous conditions are not true, then do this&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can chain as many &lt;code&gt;else if&lt;/code&gt; as you want (although it is probably not advisable to do so) or you can use the next conditional statement, the &lt;code&gt;switch&lt;/code&gt;. Not that if you use a &lt;code&gt;return&lt;/code&gt; inside the if statement, the program returns from the current scope.&lt;/p&gt;

&lt;h3&gt;
  
  
  Switch
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;switch&lt;/code&gt; is simply a more compact and easier way to write a chain of &lt;code&gt;if and else&lt;/code&gt; statements. It runs a condition against preconditions called cases and executes the first case it encounters that satisfies the condition of the execution.&lt;/p&gt;

&lt;p&gt;Switch statements follow the following format:&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;switch&lt;/span&gt; &lt;span class="n"&gt;initialization&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;comparator&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;condition1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; 
            &lt;span class="c"&gt;// run this if comparator == condition1&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;condition2&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="c"&gt;// run this if comparator != condition1 and comparator == condition2&lt;/span&gt;
    &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="c"&gt;// run this if the comparator matches none of the cases&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// note that you can have as many cases as required&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As always, the &lt;code&gt;initialization&lt;/code&gt; is the part that allows us to create variables or run short codes before the switch is executed, and it is also optional. The &lt;code&gt;comporator&lt;/code&gt; is the thing we want to check with cases from top to bottom to find a match. if no match is found with any of the cases, the &lt;code&gt;default&lt;/code&gt; block is executed.&lt;/p&gt;

&lt;p&gt;For example, let us write a code that switches between the color of a car:&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;switch&lt;/span&gt; &lt;span class="n"&gt;carColor&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s"&gt;"red"&lt;/span&gt;&lt;span class="o"&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;"The car is red"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s"&gt;"blue"&lt;/span&gt;&lt;span class="o"&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;"The car is blue"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s"&gt;"green"&lt;/span&gt;&lt;span class="o"&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;"The car is green"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="o"&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;"I don't know the color of the car"&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 &lt;code&gt;comparator&lt;/code&gt; is also optional, if it is not provided, it defaults to &lt;code&gt;true&lt;/code&gt; and the program goes through the cases from top to bottom until it finds the first case whose condition is true. For example:&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;switch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="no"&gt;false&lt;/span&gt;&lt;span class="o"&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;"The is false"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="no"&gt;false&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;&lt;span class="o"&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;"The is false"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="no"&gt;false&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;&lt;span class="o"&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;"The is true"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="o"&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;"the default"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;// in this case, since the comparator is not provided, it defaults to true and&lt;/span&gt;
&lt;span class="c"&gt;// the program goes through the cases until it executes the third case whose &lt;/span&gt;
&lt;span class="c"&gt;// condition is true. &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Congratulations! You made it here. That is just the basic syntax of Golang. In the next article, we will dive deeply into advanced data types such as arrays, maps, functions, pointers, and structs.&lt;/p&gt;

&lt;p&gt;You can connect with me on &lt;a href="https://www.linkedin.com/in/abduljemeel-odewole-393a0b105/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; here, on &lt;a href="https://twitter.com/intellect4all" rel="noopener noreferrer"&gt;X&lt;/a&gt;, and my email is &lt;a href="http://mailto:odetechit@gmail.com" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Keep GOing&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;References:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Effective Go: &lt;a href="https://go.dev/doc/effective_go" rel="noopener noreferrer"&gt;https://go.dev/doc/effective_go&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Go Programming Language: Alan A.A Donovan, Brian W. Kernighan&lt;/p&gt;

</description>
      <category>go</category>
      <category>google</category>
      <category>programming</category>
    </item>
    <item>
      <title>A Comprehensive Introduction to Golang</title>
      <dc:creator>Odewole Abdul-Jemeel</dc:creator>
      <pubDate>Sat, 28 Oct 2023 00:02:24 +0000</pubDate>
      <link>https://dev.to/intellect4all/a-comprehensive-introduction-to-golang-5ab5</link>
      <guid>https://dev.to/intellect4all/a-comprehensive-introduction-to-golang-5ab5</guid>
      <description>&lt;p&gt;The genesis of the Go programming language can be traced back to a pivotal moment at Google, where engineers Robert Griesemer, Rob Pike, and Ken Thompson grappled with the intricate nature of C++. Their dissatisfaction with the complexity and the absence of a straightforward, efficiently compiled, and executed language spurred them to embark on a quest to design a novel language. On September 21, 2007, their endeavors culminated in the birth of version 1.0 of the Go language.&lt;/p&gt;

&lt;p&gt;The primary mission of the Go creators was to amalgamate the ease of programming found in interpreted, dynamically-typed languages with the efficiency and safety characteristics of statically-typed, compiled languages. Beyond this, the Go language was envisioned to facilitate network and multicore computing, striving to expedite the coding process. To achieve these objectives, Go drew inspiration from various languages, amalgamating their most favorable features into a cohesive, simplified language that resonates with a broad spectrum of developers.&lt;/p&gt;

&lt;p&gt;This article takes an in-depth look at the key features of Go, its installation, and an introductory guide to writing programs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Go
&lt;/h2&gt;

&lt;p&gt;Go is a compiled, concurrent, garbage-collected, statically-typed language. Now, let's break down each of these features to better understand their significance in Go.&lt;/p&gt;

&lt;h3&gt;
  
  
  Compiled
&lt;/h3&gt;

&lt;p&gt;In the context of programming, a compiled language relies on a compiler system to translate the written code into machine-readable instructions. These compilers facilitate the transformation of human-readable code into the binary language that a computer understands. This process grants compiled languages an inherent speed advantage during runtime, as they operate directly in machine code. However, a drawback arises: whenever alterations are made to the code, the entire program must undergo a recompilation process, demanding additional time and effort.&lt;/p&gt;

&lt;p&gt;One of the significant advantages of compiled languages lies in the early detection of errors. Before the program is executed, the compiler thoroughly scrutinizes the code, identifying and flagging any potential issues through compilation errors. This results in swift bug detection and resolution, saving time in the development cycle.&lt;/p&gt;

&lt;p&gt;Yet, a notable limitation stems from system dependence. Compiled code is tailored for a specific machine, making it bound to the underlying system's architecture. Consequently, the compiled program might not function properly on systems for which it was not specifically compiled.&lt;/p&gt;

&lt;p&gt;Considering GoLang's nature as a compiled language, it inherently inherits these advantages and trade-offs. The speed, early bug detection, and overall efficiency are key strengths of Go due to its compiled structure. However, developers working with Go need to consider the necessity for recompilation after code changes and be mindful of system dependencies while deploying their programs across different environments.&lt;/p&gt;

&lt;h3&gt;
  
  
  Concurrent
&lt;/h3&gt;

&lt;p&gt;Concurrency involves the execution of multiple tasks or instruction sequences simultaneously, distinct from parallelism, although the distinction can be quite nuanced. Concurrency is about dealing with lots of things at once but parallelism is about doing lots of things at once.&lt;/p&gt;

&lt;p&gt;Go, known as a concurrent language, is equipped with tools like Goroutines, simplifying the execution of concurrent programs. Goroutines are basic functions running independently in their threads, allowing for easy handling of concurrency.&lt;/p&gt;

&lt;p&gt;However, managing shared memory, facilitating communication across different threads, and avoiding race conditions present challenges in concurrent programming. To address these issues, Golang offers elegant native tools such as channels, wait groups, and mutex. These features empower programmers to resolve common problems associated with concurrent programs efficiently. Delving deeper into these tools will be covered in subsequent sections of this series.&lt;/p&gt;

&lt;h3&gt;
  
  
  Garbage-collected
&lt;/h3&gt;

&lt;p&gt;Garbage collection in programming serves as an automatic memory management process wherein a garbage collector scans and reclaims memory spaces that were initially allocated but are no longer referenced. This mechanism absolves programmers from the intricacies of low-level memory management and cleanups. However, while this feature does save time and effort for developers, it also utilizes system resources to decide which memory to reclaim and perform the cleanup, which could potentially impact a program's performance.&lt;/p&gt;

&lt;p&gt;The primary benefit of garbage collection is its capacity to prevent memory leaks within a program. A memory leak occurs when memory space is lost due to the absence of proper cleanup by the developer, and the program remains unaware of this loss. By implementing garbage collection, Go ensures that memory management becomes a lesser concern for developers, although maintaining vigilance regarding code quality remains essential.&lt;/p&gt;

&lt;p&gt;Nevertheless, there are instances in more advanced scenarios where adjusting or fine-tuning the garbage collection process becomes necessary. This could involve optimizing the garbage collection settings to extract maximum efficiency from a program or even temporarily disabling it to apply alternative memory management techniques. These cases necessitate a more nuanced approach to leverage the full potential of the program.&lt;/p&gt;

&lt;h3&gt;
  
  
  Statically-typed language
&lt;/h3&gt;

&lt;p&gt;A statically typed language conducts type checking during the compile time, requiring that the type associated with each variable be determined before the code is compiled. This design necessitates a deliberate and precise approach when defining variables. However, the advantage is that once the variable type is established, it need not be continuously checked during runtime.&lt;/p&gt;

&lt;p&gt;Furthermore, in a statically typed language, once a variable is defined with a certain type, it cannot be altered or assigned data that is inconsistent with that type. This characteristic offers a degree of safety and consistency within the code.&lt;/p&gt;

&lt;p&gt;The perception of static typing varies among developers, as it can be regarded as both a positive and a negative aspect in programming. Some appreciate the rigor and safety it offers by catching potential errors during compilation, while others find it restrictive or overly formal for certain types of coding tasks.&lt;/p&gt;

&lt;p&gt;These features collectively position Go as a modern and efficient language, offering speed, concurrency support, automatic memory management, and type safety. Developers can leverage these aspects for different project needs while being aware of associated trade-offs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Golang?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1 . Simplicity
&lt;/h3&gt;

&lt;p&gt;Golang's appeal lies in its simplicity and straightforward syntax, evident through its concise structure built upon a mere 25 defined keywords. The language fosters a paradigm of singular ways to execute tasks, significantly enhancing code readability while curbing the complexity that often results from over-engineering.&lt;/p&gt;

&lt;p&gt;This dedication to an encouraged singular, effective approach not only streamlines code but also amplifies its reliability. Developers find assurance in the consistent functionality of their code, allowing for a clearer and more predictable development process. What's more, Golang's design philosophy emphasizes simplicity, equipping developers with fundamental tools readily available in its standard library. This emphasis on simplicity reduces the reliance on external or third-party libraries, empowering developers to craft robust applications without unnecessary dependencies.&lt;/p&gt;

&lt;h3&gt;
  
  
  2 . Golang is fast
&lt;/h3&gt;

&lt;p&gt;Golang, as a compiled language, offers superior performance compared to dynamically typed languages such as Python and JavaScript. While it may not outperform the fastest languages like C++, the amalgamation of Golang's ease of use and inherent speed renders it significantly rapid and sufficiently swift for a wide array of use cases. This balance between speed and development ease positions Golang as an attractive language for most scenarios, catering to a broad spectrum of practical applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  3 . Easy Concurrency
&lt;/h3&gt;

&lt;p&gt;This is a pivotal strength of Golang. Concurrency is deeply ingrained in the language's core, making it an inherent part of its structure. While other languages may achieve concurrent tasks, Golang streamlines this process, requiring significantly less effort and often surpassing the effectiveness of other languages. Golang's innate design offers effortless and native solutions for handling concurrent operations, providing developers with convenient and efficient tools to manage and execute parallel tasks.&lt;/p&gt;

&lt;h3&gt;
  
  
  4 . Less Memory Footprint
&lt;/h3&gt;

&lt;p&gt;The benchmark available at &lt;a href="https://programming-language-benchmarks.vercel.app/" rel="noopener noreferrer"&gt;https://programming-language-benchmarks.vercel.app/&lt;/a&gt; demonstrates that Golang stands out as one of the most memory-efficient languages presently available. This achievement is attributable to several inherent features of Golang, such as its static typing, robust garbage collection system, and the inherent structuring of data within the language. These traits collectively contribute to Golang's exceptional efficiency in terms of minimal memory consumption compared to other languages.&lt;/p&gt;

&lt;h2&gt;
  
  
  Companies using Golang
&lt;/h2&gt;

&lt;p&gt;Google, Uber, Paypal, Alibaba, Cloudflare, Docker, Youtube, Linkedin, X (formerlly Twitter), IBM, FireFlies etc&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up Go development environment
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1 . On Mac&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To install Golang on a Mac, visit &lt;a href="https://go.dev/doc/install" rel="noopener noreferrer"&gt;here&lt;/a&gt; to obtain the Go installation package. After downloading the package file, proceed to open it, which will effectively install Go on your system. To verify the successful installation of Go, open a terminal and execute the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ go version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Upon successful installation, you should receive a response similar to the following, which may vary depending on the installed version of Go:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;go version go1.21.3 darwin/arm64
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you get a command not found error even after installing Go, then you need to add Go to your &lt;code&gt;$PATH&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;run the following commands to do that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ echo "export PATH=$PATH:/usr/local/go/bin" &amp;gt;&amp;gt; ~/.zshrc
$ echo "export PATH=$PATH:$GOPATH/bin" &amp;gt;&amp;gt; ~/.zshrc
$ source ~/.zshrc
$ go version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Following these steps, you should see the version of Golang that is currently installed in the console. If you continue to encounter issues, I recommend visiting StackOverflow at &lt;a href="https://stackoverflow.com/questions/34708207/command-not-found-go-on-mac-after-installing-go" rel="noopener noreferrer"&gt;here&lt;/a&gt; for potential solutions. It's normal to seek help in such situations, and online communities like StackOverflow often provide valuable assistance for resolving technical issues.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2 . On Linux&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To begin using Golang on Linux, head to &lt;a href="https://go.dev/doc/install" rel="noopener noreferrer"&gt;https://go.dev/doc/install&lt;/a&gt; to download the go archive. Then, execute the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ rm -rf /usr/local/go
$ tar -C /usr/local -xzf go1.21.3.linux-amd64.tar.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The initial command removes any existing Golang installation before proceeding with a new installation. The subsequent command untars the recently downloaded archive.&lt;/p&gt;

&lt;p&gt;Please note, execute these commands within the directory where the archive was downloaded. To verify your current working directory, enter the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ pwd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After the tar operation has been completed, you need to add the Go directory to your PATH.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ echo "export PATH=$PATH:/usr/local/go/bin" &amp;gt;&amp;gt; $HOME/.profile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then you can run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ go version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to verify that the installation was successful. If you don’t see the current version of Go printed in the console, then play around on Google to fix the issue.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3 . On Windows&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Visit &lt;a href="https://go.dev/doc/install" rel="noopener noreferrer"&gt;here&lt;/a&gt; to download the GO MSI file, open the file and follow the prompts.&lt;/p&gt;

&lt;p&gt;Then open the Command Prompt and run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ go version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should be greeted with the version of the Go installed.&lt;/p&gt;

&lt;p&gt;It is this simple to install Golang.&lt;/p&gt;

&lt;h2&gt;
  
  
  Coding Tools: Recommended IDE
&lt;/h2&gt;

&lt;p&gt;GoLand by JetBrains is an exceptional IDE designed specifically to facilitate an enjoyable and straightforward Golang coding experience. While this IDE isn't free, its subscription is worthwhile if within your budget. For students, there's an advantageous offer providing a free student license for all JetBrains tools, including GoLand, for a year or more.&lt;/p&gt;

&lt;p&gt;If GoLand isn't accessible, Visual Studio Code (VSCode) is an excellent alternative. To obtain VSCode, go to &lt;a href="https://code.visualstudio.com/download" rel="noopener noreferrer"&gt;https://code.visualstudio.com/download&lt;/a&gt; for setting it up on your machine. Additionally, refer to &lt;a href="https://code.visualstudio.com/docs/languages/go" rel="noopener noreferrer"&gt;this link&lt;/a&gt; for configuring VSCode for Golang development.&lt;/p&gt;

&lt;h2&gt;
  
  
  Writing and running your first Go program
&lt;/h2&gt;

&lt;p&gt;Our first Golang program is going to be a simple Hello World, to show you the feel of Golang. In addition, we will code a GPA Calculator to give you a more robust introduction to coding in Go.&lt;/p&gt;

&lt;p&gt;Let’s start with the HelloWorld program:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1 . Create a folder for our program.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;open your terminal, and run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mkdir golang_projects &amp;amp;&amp;amp; cd golang_projects
$ mkdir hello_world &amp;amp;&amp;amp; cd hello_world
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;mkdir&lt;/code&gt; is a command to create a directory with the name of the directory following it, because as software engineers, we should be comfortable with using the terminal to get things done (and it is usually faster than GUI). The &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;, the logical &lt;code&gt;AND&lt;/code&gt;, is a syntax to concatenate two commands in the terminal, meaning we are telling the terminal to create a directory AND &lt;code&gt;cd&lt;/code&gt; into the directory. As you may have figured, &lt;code&gt;cd&lt;/code&gt; is a command to go into the directory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. then run&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ go mod init github.com/hello_world

## response
go: creating new go.mod: module github.com/hello_world
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command tells Go to treat the folder we just created as a module, and to do the initialization of the dependency management for our project, so that when we import packages in other modules, go can know how to manage them for us. We will look into Go’s dependency management in detail later in this series.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. create a file hello.go in the directory&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ touch hello.go
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;touch&lt;/code&gt; is a command to create a file from the terminal. Open the directory in your favorite IDE and open the &lt;code&gt;hello.go&lt;/code&gt; file we just created.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Write the following code in the file&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The line &lt;code&gt;package main&lt;/code&gt; serves as a directive to Go, signifying that this file belongs to the main module. A package acts as a means to collect functions and essentially represents files located within the same directory in Go.&lt;/p&gt;

&lt;p&gt;The statement &lt;code&gt;import "fmt"&lt;/code&gt; functions by importing the "fmt" package into our code. This is how we use other codes written by other people in our program. import enables us to incorporate functionalities written by others into our program. "fmt" is part of the standard library inherent to Go, encompassing various formatting functions, notably the &lt;code&gt;Println&lt;/code&gt; function, which outputs content to the console.&lt;/p&gt;

&lt;p&gt;For those transitioning from other programming languages, the use of a capital letter to initiate a method might be surprising. In Go, the casing of the initial letter of a type determines the scope at the file level. Types beginning with a capital letter are accessible and exposed beyond their original declaration, while types starting with a lowercase letter remain unexposed and cannot be accessed outside of their specific scope. This mechanism mirrors the idea of public and private (or &lt;code&gt;_&lt;/code&gt;) in languages like Java and others.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;func&lt;/code&gt; keyword is used to formally declare a function. Each time you intend to create a function, you must use this keyword for declaration. In our code, we declare the &lt;code&gt;main&lt;/code&gt; function, which commonly serves as the entry point in a Golang program. By default, it gets executed whenever you run the main package.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;fmt.Println("Hello, World!")&lt;/code&gt; too is self-explanatory, we are calling the Println method of the fmt package to print the string “Hello, World!” to the console.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. To run the program,&lt;/strong&gt; open a terminal in the main module (the directory where the &lt;code&gt;go.mod&lt;/code&gt; exists), run the command below and you should see a beautiful “Hello, World!” printed in the console.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ go run .

## resp
Hello, World!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The command run compiles and runs the go module declared in the current working directory, specified by the dot (&lt;code&gt;.&lt;/code&gt;)&lt;/p&gt;

&lt;p&gt;And that is your first Golang program. Despite the simplicity of this program, it is a good entry point to the world of Golang.&lt;/p&gt;

&lt;p&gt;Check the next episode for the simple but explanatory GPA calculator that will make you fall in love with Go. Keep GOing.&lt;/p&gt;

&lt;h2&gt;
  
  
  References:
&lt;/h2&gt;

&lt;p&gt;The Go programming language—everything you should know (&lt;a href="https://codilime.com/blog/what-is-go-language/" rel="noopener noreferrer"&gt;https://codilime.com/blog/what-is-go-language/&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Go (programming language) &lt;a href="https://en.wikipedia.org/wiki/Go_(programming_language)" rel="noopener noreferrer"&gt;https://en.wikipedia.org/wiki/Go_(programming_language)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Concurrency (computer science) &lt;a href="https://en.wikipedia.org/wiki/Concurrency_(computer_science)" rel="noopener noreferrer"&gt;https://en.wikipedia.org/wiki/Concurrency_(computer_science)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Concurrency in Operating System &lt;a href="https://eng.libretexts.org/Courses/Delta_College/Operating_System%3A_The_Basics/05%3A_Process_Synchronization/5.1%3A_Introduction_to_Concurrency" rel="noopener noreferrer"&gt;https://eng.libretexts.org/Courses/Delta_College/Operating_System%3A_The_Basics/05%3A_Process_Synchronization/5.1%3A_Introduction_to_Concurrency&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Dynamic typing vs. static typing &lt;a href="https://courses.cs.washington.edu/courses/cse341/04wi/lectures/13-dynamic-vs-static-types.html" rel="noopener noreferrer"&gt;https://courses.cs.washington.edu/courses/cse341/04wi/lectures/13-dynamic-vs-static-types.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Tutorial: Get started with Go &lt;a href="https://go.dev/doc/tutorial/getting-started" rel="noopener noreferrer"&gt;https://go.dev/doc/tutorial/getting-started&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>softwareengineering</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
