Logo
Logo
6 results for
  • In the last lesson we defined a User struct. We could pass it to functions — birthday(u), sendEmail(u), formatName(u). That works, but there’s a better way: we can attach functions directly to the User type. Then instead of birthday(u) we write u.Birthday(). Those are called methods.

    Methods make code more readable, more organized, and closer to how we naturally think about objects — “a user does birthday-related things” rather than “a birthday function takes a user.”

    Go tutorial golang beginner Created Sun, 11 Feb 2024 00:00:00 +0000
  • So far we’ve been working with Go’s built-in types: strings, ints, booleans, slices, maps. Those are great, but real programs deal with real-world things — users, orders, products, messages. You need a way to group related data together and give it a meaningful name. In Go, that’s a struct.

    If you come from Python, think of a struct as a lightweight class that holds data (but with no inheritance, and methods are defined separately). If you come from JavaScript, think of it as a typed object. If you come from C, structs work almost exactly the same way.

    Go tutorial golang beginner Created Wed, 07 Feb 2024 00:00:00 +0000
  • Strings look simple. You write "hello", you print it, done. But when I first started working with non-ASCII text in Go — names with accents, emoji, Chinese characters — things started behaving oddly. len("café") returned 5, not 4. Iterating with a regular index loop gave me garbled output. It took me a while to understand why, and once I did, a lot of things clicked.

    The short version: Go strings are sequences of bytes, not characters. Once you internalize that, the rest makes sense.

    Go tutorial golang beginner Created Fri, 02 Feb 2024 00:00:00 +0000
  • Every language has some version of the dictionary or hash map. Python calls it a dict, JavaScript calls it an Object or Map, Ruby calls it a Hash. In Go, it’s just called a map. Once you understand how Go maps work, you’ll reach for them constantly — they’re one of the most useful data structures in the language.

    The Basics

    Creating a map

    The zero value of a map is nil. A nil map is readable (it returns zero values) but not writable. If you try to write to a nil map, your program panics. The safe way to create a map is with make:

    Go tutorial golang beginner Created Sat, 27 Jan 2024 00:00:00 +0000
  • Go has two sequence types: arrays and slices. I’ll tell you upfront — arrays are rarely used directly. They exist, they matter for understanding how things work under the hood, but in day-to-day Go programming you’ll almost always reach for a slice instead.

    Slices are Go’s workhorse collection type. They’re flexible, they grow when you need them to, and they’re used everywhere: in standard library APIs, in function parameters, in HTTP handlers. Understanding slices well will make you a much more effective Go programmer than memorizing syntax ever will.

    Go tutorial golang beginner Created Mon, 22 Jan 2024 00:00:00 +0000
  • If there’s one thing experienced Go programmers agree on, it’s this: write small functions. Not tiny, cryptic one-liners, but focused functions that do one thing and are easy to test. Go’s function syntax encourages this style — it’s clean, explicit, and has one feature that’s genuinely different from most languages you’ve used before: multiple return values.

    In Python you can return a tuple. In JavaScript you can return an array. But in Go, returning two or three values is a first-class language feature with its own syntax, and it fundamentally changes how error handling works. By the end of this lesson you’ll understand Go functions well enough to start writing real, useful programs.

    Go tutorial golang beginner Created Wed, 17 Jan 2024 00:00:00 +0000
  • Every program you’ll ever write needs to make decisions and repeat actions. “If this condition is true, do that. Otherwise, do something else.” “Keep doing this until we run out of items.” These are the fundamental building blocks of logic, and Go handles them with just three constructs: if, for, and switch.

    That’s it. No while. No do-while. No foreach as a separate keyword. Go’s designers made a deliberate choice to keep the language small — fewer constructs means fewer ways to do the same thing, which means code is more consistent and easier to read across different projects and teams.

    Go tutorial golang beginner Created Fri, 12 Jan 2024 00:00:00 +0000
  • If you’re coming from Python or JavaScript, Go’s type system might feel like extra work at first. Why should you have to tell the compiler that a variable holds a number? Can’t it just figure it out?

    Here’s the thing — it usually can. Go has type inference, so you rarely have to write out types explicitly. But when types are written out, every person reading your code knows exactly what kind of data they’re dealing with. There’s no guessing, no surprises at runtime because a string snuck in where you expected a number. Go catches those mistakes at compile time, before your code ever runs.

    Go tutorial golang beginner Created Mon, 08 Jan 2024 00:00:00 +0000
  • I remember the first time I ran a Go program. The compiler yelled at me for an unused import, and I thought, “Okay, this language has opinions.” That’s not a bad thing. Go’s strictness is part of what makes it so readable and maintainable. Once you understand why Go works the way it does, it starts to feel less like friction and more like clarity.

    In this lesson you’re going to write your first Go program, understand every single line of it, and learn the basic tools you’ll use every day. By the end, “Hello, World!” won’t feel like a throwaway demo — it’ll feel like a foundation.

    Go tutorial golang beginner Created Wed, 03 Jan 2024 00:00:00 +0000