Full Width [alt+shift+f] Shortcuts [alt+shift+k]
Sign Up [alt+shift+s] Log In [alt+shift+l]
1

How to Properly Use Defer in Golang

from Boot.dev Blog [alt+shift+b] in programming

What is the “defer” keyword in Go? 🔗 In the Go programming language, defer is a keyword that allows developers to delay the execution of a function until the current function returns. What throws some people off is that the deferred function’s arguments are evaluated immediately, but the function itself doesn’t fire until the wrapping function exits.
1st Jun 2021

Stay updated

Get a weekly newsletter with the top 5 articles worth reading every week.

More from Boot.dev Blog

WannaCry: The Ransomware Attack That Shut Down Hospitals

It was 3 PM on a Friday. A doctor at an NHS hospital in the UK tries to check his email. Instead, one of the PCs in the room reboots into a scary red screen demanding $300 in Bitcoin [23].

2nd Jun 2026 • 1 votes
The AI Land Grab Looks Familiar

In May of 2013, Yahoo announced plans to buy Tumblr for 1.1 billion dollars. Yahoo’s CEO, Marissa Mayer, stood in front of the press and said, “We promise not to screw it up”.

11th May 2026 • 1 votes
Gitignore Patterns: What to Ignore and Why

Many devs adopt the git add . (yolo, just yeet it all into the commit) workflow. It is fast, simple, and usually correct. But eventually you’ll have files in your repo directory that should never be committed: secrets, generated artifacts, dependency folders, and random local junk. That’s what .gitignore is for.

1st Apr 2026 • 1 votes
Python Functions: How to Define and Call Them

Functions allow you to reuse and organize code. Instead of copying and pasting the same logic everywhere, you define it once and call it whenever you need it. They’re the most important tool for writing DRY code.

1st Mar 2026 • 1 votes
The Boot.dev Beat. February 2026

A new year and another record broken! In January a combined 4,016,641 lessons and challenges were completed by you, dear pupils! And to top it off, we’re now releasing the much anticipated Power BI Course by none other than Alex the Analyst! I hope you enjoy it.

11th Feb 2026 • 1 votes

More in programming

Notes from CoRL 2026

(Tuesday)

9 hours ago • 1 votes
The Codebase Rewrite is Back

The economics of software engineering have fundamentally changed.

12 hours ago • 1 votes
How OCaml effects simplified my JSON interpreter

How effect handlers removed control-flow plumbing from query-json

yesterday • 1 votes
Unattended reboots with encrypted disks

An introduction to ZKeys: a new service that stores encryption keys off-site and automatically locks access to them if the client machines go offline for a long period of time.

4 days ago • 1 votes
Education Shouldn't Be Held for Ransom

Google told K-12 schools they could turn off AI, but only if they gave up search too. That isn’t integration. It’s holding education for ransom.

a week ago • 1 votes
📚 BoredReading

You seem to be enjoying this.

Join free to unlock everything.

Create free account

Already have an account? Sign in