← Back to list

Dealing with Golang Data Types

It’s really been a very busy week over here, work has been quite tasking; been building a couple of features at work which has got me…

Abati Babatunde Daniel · 2025-02-05 11:01 · 58 claps · 5.4 min read
#software-development #software-engineering #golang #go #go-tutorial
Open on Medium ↗

Dealing with Golang Data Types

It’s really been a very busy week over here, work has been quite tasking; been building a couple of features at work which has got me working round the clock. Last week I started the Fundamentals with Go series ; we went on a deep dive into variables, program structure & packages (here’s a link: https://medium.com/@danielabatibabatunde1/lets-talk-about-the-fundamentals-of-golang-e80d69a706ff). Today’s session would be a quick straight to the point tutorial on Data Types & Sizes (So sit back, grab a note, set up your code editor, we’d be writing couple of programs😊).

Data Types & Sizes

I view programs as simply data flowing in, gets transformed through a set of instructions and an output is produced no matter how complex a codebase can be , this is my simplest idea & approach to everything software technology.

(This basic philosophy has done a lot for me to be able to solve bugs, build features, modules & projects). But program as a whole has a composition of units to represent real-world data & information, for which they can be classified; I mean even in natural language we have numbers, special characters & words but the computer is oblivious as they only deal with 1’s and 0’s (binary, but we can’t be writing 1’s and 0’s, can we ?😩 ). And so in Golang we have a way of representing these classifications, namely;

  • Integers
  • Strings
  • Unsigned Integers
  • Float
  • Boolean
  • Complex Numbers

Integers (int) in Go are foundational data types for representing whole numbers, much like their real-world counterparts. The language offers a spectrum of integer types, akin to differently sized containers tailored for specific numerical ranges. The number following int (e.g., 8, 16, 32, 64) denotes its bit size, determining how much data it can store — larger numbers require “bigger boxes”!

Here’s a breakdown of their ranges:

  • int8: A compact container (-128 to 127)
  • int16: A modest range (-32,768 to 32,767)
  • int32: Handles mid-sized values (approximately ±2.1 billion)
  • int64: The heavyweight for colossal numbers (roughly ±9.2 quintillion)

When you declare a plain int (without a bit size), Go automatically selects the most efficient size based on your system’s architecture — 32 bits on older machines or 64 bits on modern ones. These explicit bit sizes (int8, int16, etc.) give developers fine-grained control over memory usage and performance, which is critical for low-level optimization (we’ll explore this in detail later).

Below is a code implementation of an integer:

Strings in Go are immutable sequences of bytes designed to handle text — think of them as unchangeable “text builders” that assemble characters into readable content. By default, they’re UTF-8 encoded (you should google this), which means they effortlessly support international characters (like emojis 🎉, Cyrillic script, or Mandarin) without extra configuration.

You can create strings in two primary ways:

  • Double quotes (“Hello, 世界!”) for single-line strings with escaped characters (e.g., \n for newlines).
  • Backticks (Multi-line strings!) for raw, unprocessed text spanning multiple lines — ideal for templates, JSON blobs, or preserving formatting.

Unsigned integers (uint) might sound complex, but they’re simply non-negative counterparts to regular integers. By ditching negative values, they free up space to store larger positive numbers within the same bit size — think of them as “roomier boxes” for specific use cases.

Here’s how they scale:

  • uint8: Ranges from 0 to 255 (ideal for RGB color codes! 🎨)
  • uint16: Handles 0 to 65,535 (great for smaller counts or identifiers)
  • uint32: Supports 0 to ~4.3 billion (useful for large datasets)
  • uint64: A behemoth for 0 to ~18.4 quintillion (astronomical calculations, anyone?)

Like its sibling int, a plain uint defaults to your system’s architecture (32-bit or 64-bit). Opting for explicit types like uint8 or uint32 lets you balance memory efficiency and numerical capacity — a key consideration for performance-critical applications.

Below is a code implementation of an unsigned integer:

While integers and unsigned integers handle whole numbers, they fall short when representing decimal values like 3.16 or 0.0004. Enter floating-point numbers (float) — Go’s solution for precision-driven, fractional data. Think of floats as specialized tools for measuring continuous quantities, such as distances, temperatures, or scientific constants.

Go offers two primary float types:

  • float32: Single-precision (≈7 decimal digits of accuracy) — suitable for basic measurements or graphics.
  • float64: Double-precision (≈15 decimal digits of accuracy) — the gold standard for scientific computing, financial models, or scenarios demanding ultra-fine granularity.

By default, Go prioritizes float64 for its superior precision, ensuring calculations remain robust even in complex applications. Below is a code implementation of floats:

Booleans (bool) are the binary bedrock of programming — simple yet universal. They represent the most fundamental logic in code: true or false (no in-betweens, no maybes ✅ ❌). While their purpose seems minimalistic, they’re the invisible gears powering decision-making in programs, from conditional statements (if x > 0) to control flow (for loops) and error checks.

In Go, booleans are straightforward:

  • Declare with var isReady bool = true or shorthand isActive := false
  • Use logical operators (&&, ||, !) to build compound conditions.
  • Serve as guard clauses to validate data or toggle application behavior.

Though seemingly basic, booleans enforce program safety by eliminating ambiguity. They act as gatekeepers for critical operations, ensuring code executes only when specific criteria are met. Paired with Go’s strict typing, they help prevent bugs that arise from implicit “truthy/falsy” conversions seen in other languages.

Complex numbers might sound intimidating — reserved for quantum physics or fractal geometry (😅) — but in Go, they’re simply a data type for advanced mathematical computations. They consist of two components: a real part (like everyday numbers) and an imaginary part (denoted with an i, e.g., 3 + 4i). Together, these parts model phenomena that regular numbers can’t, such as waveforms or electrical engineering problems. Complex in Go are provided in two flavors : complex64, complex128.

Now that we’ve explored Go’s data types and their quirks, it’s time for a hands-on coding challenge to solidify your skills! Below are three practical exercises designed to push your understanding of Go’s type system. A friendly warning: resist the urge to ask ChatGPT 😉 — the real growth happens when you wrestle with problems yourself. Trust me, the struggle is worth it! Leave your solution in the comment too.

  1. Fizzbuzz Program: this is a common program where we simply print “fizz” & “buzz” when we run a loop from 1–100 and it hits multiples of 3 and 5 respectively. (my favorite program I always write when learning a new language). Here’s my approach & solution:

  1. Temperature Converter: Write a program that converts Celsius to Fahrenheit, this would help you understand floats better.

  2. Password strength Checker: Create a program that checks if a password meets minimum security criteria.

Enjoy the rest of your day, Selah🎉!


메타데이터
post_id
f2a3f08b9e8b
slug
dealing-with-golang-data-types-f2a3f08b9e8b
url
https://medium.com/@danielabatibabatunde1/dealing-with-golang-data-types-f2a3f08b9e8b
canonical_url
https://medium.com/@danielabatibabatunde1/dealing-with-golang-data-types-f2a3f08b9e8b
author_url
https://medium.com/@danielabatibabatunde1
status
ok
fetched_at
2026-06-24 13:29:15