惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
Google DeepMind News
Google DeepMind News
S
SegmentFault 最新的问题
Project Zero
Project Zero
D
DataBreaches.Net
I
InfoQ
L
Lohrmann on Cybersecurity
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
酷 壳 – CoolShell
酷 壳 – CoolShell
Stack Overflow Blog
Stack Overflow Blog
The Register - Security
The Register - Security
Recorded Future
Recorded Future
Vercel News
Vercel News
博客园 - 司徒正美
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
I
Intezer
The Hacker News
The Hacker News
F
Fortinet All Blogs
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
Help Net Security
Help Net Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Scott Helme
Scott Helme
T
Threatpost
爱范儿
爱范儿
N
Netflix TechBlog - Medium
D
Docker
云风的 BLOG
云风的 BLOG
C
Cisco Blogs
K
Kaspersky official blog
H
Help Net Security
S
Secure Thoughts
T
Threat Research - Cisco Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
Security @ Cisco Blogs
Cyberwarzone
Cyberwarzone
N
News and Events Feed by Topic
G
Google Developers Blog
Forbes - Security
Forbes - Security
博客园 - 三生石上(FineUI控件)
博客园 - 叶小钗
B
Blog
Google DeepMind News
Google DeepMind News
Recent Announcements
Recent Announcements
Simon Willison's Weblog
Simon Willison's Weblog
S
Securelist
P
Privacy International News Feed
Spread Privacy
Spread Privacy
The Last Watchdog
The Last Watchdog

Hacker News

Introducing Claude Opus 4.7 Qwen Studio The Future of Everything is Lies, I Guess: Where Do We Go From Here? GitHub - SeanFDZ/macmind: Single-layer transformer in HyperTalk for the classic Macintosh Show HN: Agent-cache – Multi-tier LLM/tool/session caching for Valkey and Redis Moving a large-scale metrics pipeline from StatsD to OpenTelemetry / Prometheus GitHub - Nightmare-Eclipse/RedSun: The Red Sun vulnerability repository GitHub - SethPyle376/hiraeth: Local AWS emulator focused on fast integration testing, with SQS support, SQLite-backed state, and a debug-friendly web UI. GitHub - macOS26/Agent: Any AI, replaces Claude Code, Cursor, OpenClaw. Over 18 LLM providers (Claude, OpenAI, Gemini, Ollama, Zai, HF, Qwen) wired into a native Mac app that writes code, builds Xcode projects, bumps versions, manages git, automates Safari, use AppleScript, JS or Accessibility, extend Agent! w/ MCP Servers, run tasks from your iPhone via Messages. YouTube now lets you turn off Shorts I Made a Terminal Pager Burgers | マクドナルド公式 Commands — HackerNews CLI documentation ChatGPT for Excel PiCore - Raspberry Pi Port of Tiny Core Linux Live Nation illegally monopolized ticketing market, jury finds Google Broke Its Promise to Me. Now ICE Has My Data. Founding Engineer at Adaptional | Y Combinator CRISPR takes important step toward silencing Down syndrome’s extra chromosome GitHub - saffron-health/libretto: The AI toolkit for building reliable browser automations US v. Heppner (S.D.N.Y. 2026) no attorney-client privilege for AI chats [pdf] Unexpected €54k billing spike in 13 hours: Firebase browser key without API restrictions used for Gemini requests Retrofitting JIT Compilers into C Interpreters IPv6 – Google The Accursèd Alphabetical Clock Cybersecurity Looks Like Proof of Work Now Fragments: April 14 Cal.com Goes Closed Source: Why AI Security Is Forcing Our Decision | Cal.com - Scheduling Software for Online Bookings Laravel raised money and now injects ads directly into your agent When moving fast, talking is the first thing to break Too much Discussion of the XOR swap trick – Heather Cafe Introduction to Spherical Harmonics for Graphics Programmers The Grand Line Building a Z-Machine in the worst possible language High-Level Rust: Getting 80% of the Benefits with 20% of the Pain GitHub - duguyue100/midnight-captain: Inspired by Midnight Commander, tailored to my taste. How to build a `git diff` driver · Jamie Tanna | Software Engineer Center for Responsible, Decentralized Intelligence at Berkeley The Local Universe’s Expansion Rate Is Clearer Than Ever, but Still Doesn’t Add Up - A new synthesis of astronomical measurements confirms a persistent mismatch that could point to physics beyond current models The air throughout our homes is infused with microplastics. But there are things you can do to breathe less of them The disturbing white paper Red Hat is trying to erase from the internet – OSnews The Future of Everything is Lies, I Guess: Annoyances ‘Abhorrent’: the inside story of the Polymarket gamblers betting millions on war Productive procrastination — Max van IJsselmuiden maps, territory and LMs 447 Terabytes per Square Centimetre at Zero Retention Energy: Non-Volatile Memory at the Atomic Scale on Fluorographane Show HN: Pardonned.com – A searchable database of US Pardons 20 Years on AWS and Never Not My Job The Seasons are Wrong Artemis II crew splashes down near San Diego after historic moon mission We gave an AI a 3 year retail lease in SF and asked it to make a profit | Andon Labs How a dancer with ALS used brainwaves to perform live On filing the corners off my MacBooks Installing every* Firefox extension OpenClaw’s memory is unreliable, and you don’t know when it will break Steve Blank Nowhere Is Safe Chimpanzees in Uganda locked in vicious 'civil war', say researchers watgo - a WebAssembly Toolkit for Go linux/Documentation/process/coding-assistants.rst at master · torvalds/linux GitHub - callumlocke/json-formatter: Makes JSON easy to read. Founding Product Engineer at Bild AI | Y Combinator A compelling title that is cryptic enough to get you to take action on it GitHub - Keychron/Keychron-Keyboards-Hardware-Design: Industrial design files for Keychron keyboards and mice. 100+ models with CAD assets in STEP, DXF, DWG, and PDF. Source-available, with commercial use allowed for original compatible accessories within the license terms. [ANNOUNCE] WireGuardNT v0.11 and WireGuard for Windows v0.6 Released 1D-Chess Helium Is Hard to Replace Cooperative Vectors Introduction | Evolve Keeping a Postgres queue healthy — PlanetScale Our response to the Axios developer tool compromise Do Americans read print books, e-books or audiobooks more? The Zettelkasten Method in Obsidian: A Practical Setup Guide Artemis II Is Competency Porn and We Are Starving For It WeakC4 Flight Viz — Cockpit View A Mexican surveillance giant you’ve never heard of is now watching the U.S. border Surelock: Deadlock-Free Mutexes for Rust RISC-V 101 – what is it and what does it mean for Canonical? | Ubuntu The Problem That Built an Industry How Much Linear Memory Access Is Enough? | Solidean Investigating Split Locks on x86-64 Simplest hash functions Sybilproof reputation mechanisms (2005) [pdf] What is a property? How Complex is my Code? Static code analysis in Kotlin — tools overview Toffoli gates are all you need PGLite evangelism dcmake: a new CMake debugger UI Clojure on Fennel part one: Persistent Data Structures Fragments: April 2 Python Release Python install manager 26.1 The Life and Death of the Book Review - Liberties Introducing Database Traffic Control — PlanetScale Bitcoin miners are losing $19,000 on every BTC produced as difficulty drops 7.8% God sleeps in the minerals Building slogbox Apple Silicon and Virtual Machines: Beating the 2 VM Limit Who was “Not Even Wrong” first? Pokemon Evolution Vs Darwinian Evolution The APL Programming Language Source Code
Excessive nil pointer checks in Go
Konrad Reiche · 2026-06-18 · via Hacker News

Let’s talk about nil pointer checks in Go. You want to prevent panics in production, but that doesn’t start with a deferred recover. It starts with defensive programming. Check your inputs, check your bounds, and check pointers for nil before dereferencing them.

I’ve started to see more nil checks in Go code. In the right place, they are necessary for writing safe code. In the wrong place, they are a sign that the code has stopped being clear about what can and cannot be nil. I have noticed this pattern more in generated code, but this symptom is not new and is not limited to AI.

When a nil check is cheap and prevents a panic, why not add it? Your reflex may be, let’s just be safe. But the check also tells the next reader something, and often the wrong thing.

Nil Check on a Dependency

Consider a nil check on a dependency. A type RateLimiter holds a Redis client, and a nil check guards before using it in lines 10 to 12:

 1type RateLimiter struct {
 2	redis *redis.Client
 3}
 4
 5func (r *RateLimiter) Allow(ctx context.Context, req *Request) (bool, error) {
 6	userID := GetUserID(req)
 7	if userID == "" {
 8		return false, nil
 9	}
10	if r.redis != nil {
11		return r.checkLimit(ctx, userID)
12	}
13	return false, nil
14}

At a glance, it looks like the safe thing to do, but you should ask yourself: why would you construct RateLimiter with a nil dependency?

If the Redis client is nil, the error happened earlier, at construction time. Checking for it now does not handle that error. Worse, it treats operating with the failed construction as an acceptable state. In Go, you want to fail fast and fail early.

A nil check is not always defensive programming. In this example, it’s a sign that the code has lost track of the lineages of its objects. We no longer know where the pointer came from, who was responsible for initializing it, or what invariant should have made nil impossible.

Nil Check on a Dependency in the Constructor

You may attempt to address this by pushing the problem up one layer. You now check for nil and return an error to flag the nil dependency as an invalid state.

func NewRateLimiter(client *redis.Client) (*RateLimiter, error) {
	if client == nil {
		return nil, errors.New("redis client is nil")
	}
	return &RateLimiter{
		redis: client,
	}, nil
}

It’s better, but it’s still not correct. Why not? Because we still allowed the invalid state to enter our system. A nil pointer is still being passed to our function, which puts the burden of deciding whether to trust the input on code that should have received a valid value in the first place.

The constructor is not where the error happened. The error happens at the initialization site:

redisClient, err := NewRedisClient(addr)
if err != nil {
	return nil, err
}

limiter := NewRateLimiter(redisClient)

Once initialization fails, we should handle that error immediately. We should not continue with a nil pointer and force the next, deeper layer to rediscover the outcome. Doing so also removes the need for the rate limiter constructor to return an error in the first place!

If the system needs to tolerate the store being temporarily unavailable, do not propagate a nil, model it explicitly. Wrap it so the outer type is always non-nil and handles retries or degradation internally, exposing methods that are safe to call. The caller gets a type guaranteed to exist, and the messiness stays contained inside it. That is how you encapsulate complexity rather than expose your entire codebase to it.

This is the same idea as a database constraint. A NOT NULL or foreign-key constraint guarantees a bad row cannot exist in the first place, so every query can trust the data without re-checking it. You want the same guarantee for your runtime values, with one difference. The database enforces its constraint on every write. You establish yours once, so the rest of the code can rely on it without having to repeat the checks.

The Cost of Silent Failures

When I flag code like the one above, I often get a response that reveals a well-intentioned instinct about reliability, and it goes something like this:

“I don’t want to return an error here and risk taking the program down over my small change. Wrapping it in a nil check or just logging it feels safer.”

The choice feels like crash (bad) versus continue (safe), but it’s actually loud failure (safe) versus silent failure (bad). An error explicitly returned is:

  • Loud: You find out it happened.
  • Immediate: You find out near the cause.
  • Attributable: The caller can connect the failure to the operation that failed.

An error you swallow is the exact inverse. The failure becomes:

  • Silent: Nothing tells you it happened.
  • Delayed: It surfaces later, after more code has run.
  • Ambiguous: By the time you see the symptom, the original cause is harder to identify.

The gap between cause and symptom is the cost, and it grows with every call the program survives in an invalid state. That is why the fix is not to hide the failure locally. The fix is to understand where the error goes. Who calls this function? How are errors propagated? Where do they become a rejected request, a failed job, a retry, an alert, or a shutdown?

That requires looking beyond your immediate change set, but that is part of the work. If returning the error would take down more of the system than necessary, the problem lies at the error-handling boundary.

Second-Order Cost

Once failures are silent, you do not know what happened, which can hide bugs. It forces you to build infrastructure to detect the absence of operations: metrics, dashboards, and alerts. You are now spending engineering effort to reconstruct a signal you threw away. Every time you tolerate an impossible or unhandled state, you pay for it later by having to observe it.

Outer vs Inner Layer

It may not be clear yet when each check should happen. It can help to think of these as different stages in the program’s execution flow. Earlier, I wrote that the deeper layer would have to rediscover an error that was already handled above.

That has to do with the order of operations: the outer layer is where execution starts and where data enters from the outside world, and the inner layer is the code those outer calls eventually reach. The deeper you go down the call stack, the further into the inner layer you are.

At the start of execution, nothing is guaranteed, but you have not done anything either. During initialization, you set up the things your program depends on. For each one, you decide: is this a must-have, or is it something that can be unavailable at times? Your design should gravitate toward dependencies that are always available and minimize those that can drop out.

Nil Check on Request-Scoped Data

The other kind of nil shows up later, once the program is running and handling work. A request-scoped value, the request itself, its fields, and anything derived from it, is different from a dependency. A dependency is fixed at construction. A request arrives from outside on every call: from an HTTP handler, an RPC, a queue, a test helper, another package.

It is tempting to have a nil check for the request itself in our RateLimiter:

 1func (r *RateLimiter) Allow(ctx context.Context, req *Request) (bool, error) {
 2	if req == nil {
 3		return false, nil
 4	}
 5	userID := GetUserID(req)
 6	if userID == "" {
 7		return false, nil
 8	}
 9    return r.checkLimit(ctx, userID)
10}

But that is the same mistake in a new place. The request did not arrive in Allow. It entered the program earlier, at the transport boundary, the HTTP handler, the RPC dispatch, the queue consumer, etc., and it has been traveling through our code ever since.

By the time Allow runs, the request is already inner-layer data. Checking it here means a deep function is re-validating something an outer layer should have guaranteed, which is exactly what we rejected for the dependency. It spreads uncertainty. The check belongs at the boundary, where the untrusted bytes first become a *Request:

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	req, err := DecodeRequest(r)
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	// req is now validated. Everything past this point can trust it.
	allowed, err := h.limiter.Allow(r.Context(), req)
	// ...
}

You do not control what you are handed, so checking it for nil at that boundary is reasonable. Data arrives from outside, and you treat it as untrusted, so you validate it: check for nil, check the constraints that must hold. Then it crosses into the inner layer, where you map it into your own types and business logic. Past that point, it is trusted. It has become an invariant of your system. Finally, Allow keeps no nil checks at all:

func (r *RateLimiter) Allow(ctx context.Context, req *Request) (bool, error) {
	userID := GetUserID(req)
	if userID == "" {
		return false, nil
	}
	return r.checkLimit(ctx, userID)
}

This is what lets you focus on the actual logic instead of cluttering every function with nil checks. You could move the empty userID check out to the HTTP layer too, but here we deliberately let the rate limiter own that policy.

Systems built this way are easier to reason about and easier to change. Systems that are not force the opposite: you add the checks, and then you have to decide what each one should do. What is the fallback? Does it even make sense here? Every check is a new branch, and every branch is a behavior you now have to define for a state that should not exist.

Conclusion

A nil check is good when it enforces a documented boundary or models an intentional optional state. A nil check is suspicious when it silently handles a state the program claims should be impossible.

So when nil checks show up everywhere, they are telling you one of two things. Either the code is guarding untrusted boundary input, which is normal, or the codebase never established its invariants, which is a design problem.

If you are working in a system where you cannot trust any parameters, the fix is not to add more checks. You may have to for the time being, but the real work is to start establishing the invariants those checks stand in for, and gradually replace fear-driven clutter with guarantees the rest of the system can rely on.