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

推荐订阅源

N
News and Events Feed by Topic
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Hugging Face - Blog
Hugging Face - Blog
S
SegmentFault 最新的问题
IT之家
IT之家
M
MIT News - Artificial intelligence
博客园_首页
aimingoo的专栏
aimingoo的专栏
C
Check Point Blog
B
Blog
人人都是产品经理
人人都是产品经理
爱范儿
爱范儿
宝玉的分享
宝玉的分享
Martin Fowler
Martin Fowler
L
LangChain Blog
Last Week in AI
Last Week in AI
Engineering at Meta
Engineering at Meta
Microsoft Security Blog
Microsoft Security Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
F
Fortinet All Blogs
罗磊的独立博客
博客园 - 叶小钗
H
Help Net Security
Google Online Security Blog
Google Online Security Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
The Last Watchdog
The Last Watchdog
S
Security @ Cisco Blogs
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
月光博客
月光博客
C
Cybersecurity and Infrastructure Security Agency CISA
博客园 - 司徒正美
S
Schneier on Security
V
Vulnerabilities – Threatpost
T
Troy Hunt's Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
博客园 - 【当耐特】
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Forbes - Security
Forbes - Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
雷峰网
雷峰网
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Secure Thoughts
V
Visual Studio Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG
T
Tailwind CSS Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
Hacker News: Ask HN
Hacker News: Ask HN
The GitHub Blog
The GitHub Blog

Lobsters

CIFSwitch: a non-universal Linux local root vulnerability RIPE NCC session fixation: poaching logins with an Atlas probe GNOME 2.20 but its Web Components Agentic Search for Context Engineering – Leonie Monigatti Garnix is shutting down [not OC] akashina.tngl.sh/jjc Concerning Emacs (and Jazz) Nitpicking the shell history scene in ‘Tron: Legacy’ What's cooking on SourceHut? Q2 2026 The tenth OpenPGP email summit Package managers that package package managers Clojure on Fennel part three: parsing WordPress at 23 Finding Miscompiles for Fun, Not Profit GitHub - creusot-rs/creusot: Creusot helps you prove your Rust code is correct. Announcing Rust 1.96.0 | Rust Blog A Love Letter to Neovim sqlite AGENTS.md Am I a Bad Friend? CSS vs. JavaScript • Josh W. Comeau Erlang Ecosystem Foundation - Supporting the BEAM community A brief note about slot access cost in Common Lisp Keyboard latency probe Rethinking the GNOME clipboard issues Back to the Building Blocks’ Building Blocks Tech Notes: Theseus: translating win32 to wasm Fast is better than slow Content-addressed Rust builds (or, what kache actually caches) Intent to Prototype: Embedding API Canada’s Bill C-22 and the security cost of collecting more data 5 PostgreSQL locking behaviors that trip people up okmij.org Stop advertising in your commits! | AksDev GitHub - mplsllc/macsurf: A modern web browser for Classic Mac OS 9 PowerPC. Real CSS3, ES5 JavaScript, native HTTPS — built with CodeWarrior on the Carbon API. Introducing DoomBench - Can Your Data Stack Run DOOM? What are some of your favourite developer tools? Building a Scalable Ingestion Pipeline with Temporal (Part 1) Converting shallow Git bundles into normal repositories Are you a member of any professional associations? What is a harmonic? An interactive comic about additive synthesis How Virtual Tables Work in the Itanium C++ ABI Using SwiftUI to Build a Mac-assed App in 2026 Rust (and Slint) on a jailbroken Kindle. ~jack/lambda-on-lambda - Serverless Haskell on AWS - sourcehut git Human proof for FOSS contributions Extremely simple internet radio controlled via IRC Announcing BABLR Splitting Konsole views from Helix to run tools | AksDev GitHub - yugr/rust-slides Serving files over HTTP three ways: synchronous, epoll, and io_uring update docs with information about building with build.py (#979) · astral-sh/python-build-standalone@c9c40c5 A Simple Makefile Tutorial On C extensions, portability, and alternative compilers Switching to Colemak | Pedro Alves Just How Bad Was The Intel IAPX432? Nix's Substituter List Is Not a Routing Table Accelerating copy_if using SIMD Lambda on Lambda: Serverless Haskell on AWS | Blog Announcing feed-repeat v1.0 Scaling Akvorado BMP RIB with sharding EYG news: A host of CLI improvements, new guides and new effects The social contract of writing JS Crossword C array types are weird; and related topics Flatpak will depend on systemd – OSnews Migrating from Go to Rust | corrode Rust Consulting A portentous reunion Vivado Licensing Options How my minimal, memory-safe Go rsync steers clear of vulnerabilities the entropy layer of a wavelet codec, on its own GitHub - nferhat/fht-compositor: A dynamic tiling Wayland compositor. Debian SE Linux and PinTheft Does bulk memmove speed up std::remove_if? (No.) 声明式部分更新 | Blog | Chrome for Developers Fully in-browser container builds Dianne Skoll's Web Site - Remind The Architecture of Open Source Applications (Volume 1)Berkeley DB Pardon MIE? - ironPeak Blog “Long-Term Support” doesn’t mean what you think Jira IS Turing-Complete May I recommend thinking of Emacs as your Fortress of Solitude hershey Floodgap Gopher-HTTP gateway gopher://thelambdalab.xyz/1cuneiforth/ HP QuickWeb, Singular And Pointless That one time I used Go panics for flow control A new suite of modern tools coming for editing and publishing RFCs From the Tabletop… The Digital Antiquarian Building a Host-Tuned GCC to Make GCC Compile Faster Are we self-sovereign PKI yet? Claw Patrol: an open-source security firewall for agents | Deno Revised^7 Report on Scheme, Large: Procedural Fascicle Draft is now public A Network Allow-List Won't Stop Exfiltration — André Graf From AFSK to Goertzel – µArt.cz Software For My New Home Server Introducing Neptune: Direct3D virtualization for QEMU AI Agent Bankrupted Their Operator While Trying to Scan DN42 - Lan Tian @ Blog mimalloc: A new, high-performance, scalable memory allocator for the modern era Making wl_shm fast The Soul of Maintaining a New Machine - Third Draft | Books in Progress What is Git made of?
Stop Naming Your Variables "Flag": The Art of Boolean Prefixes | Christopher Johnson
Christopher Johnson · 2026-06-19 · via Lobsters

Shallow Focus Flags

The Problem

You inherit a codebase and find this:

public class OrderProcessor
{
    private bool open;
    private bool flag;
    private bool done;
    private bool status;
    
    public void Process(bool check)
    {
        if (open && flag)
        {
            flag = false;
            status = true;
        }
        
        if (done)
        {
            // what happens here?
        }
    }
}

Readable? No.

What is open? Is the store open? Should the file open? What is flag? That’s a variable screaming “I’ll fix this later.” And is done a question (“is it done?”) or a command (“mark it done”)?

Boolean names are ambiguous land mines. They look innocent until you have to figure out what they mean during a 3 AM outage.

Ambiguity breeds bugs. A reviewer looks at if (done) and guesses the intent. A maintainer rewrites flag = false and accidentally inverts logic they didn’t understand. if (!flag)… does that mean turn it on? Turn it off?

Boolean names matter because they aren’t abstract labels; they are questions. Your code asks the question, and the boolean value answers “yes” or “no.” If the variable name isn’t a clear question, the answer is meaningless.

The Solution: The 4 Prefixes

You can cover 99% of boolean naming scenarios with just four prefixes. If you stick to these, every boolean becomes a clear, grammatical question.

1. IS: Identity and State Use is when describing what something is right now. It usually pairs with an adjective.

  • Good: isActive, isDeleted, isEmpty.
  • Bad: isAccess (Grammar mismatch. Use hasAccess).

2. HAS: Containment and Features Use has when describing ownership or inclusion. It pairs with a noun.

  • Good: hasAccess, hasChildren, hasValidationErrors.
  • Bad: hasActive (Grammar mismatch. Use isActive).

3. CAN: Capability Use can to check permissions or potential actions.

  • Good: canEdit, canDelete, canRetry.
  • Bad: canAdmin (Vague. Use isAdmin or canAdminister).

4. SHOULD: Intent Use should for business rules or decisions the system needs to make. This separates “what we can do” from “what we want to do.”

  • Good: shouldRetry, shouldCacheResponse.
  • Bad: shouldUser (Incomplete. shouldCreateUser?).

Stick to this list. When you mix them up—like writing isAccess or hasActive—you force the reader to stop and re-parse the sentence in their head. That friction is where bugs get introduced.

PrefixDomainFunctionExample
ISIdentity / StateDescribes what an object is currently.isActive, isEmpty
HASContainmentDescribes ownership or feature presence.hasChildren, hasAccess
CANCapabilityDescribes permission or potential action.canEdit, canRetry
SHOULDIntent / LogicDescribes a business rule recommendation.shouldCache, shouldRetry

The “No Negatives” Rule

Here is the most important rule: Never use negation in the variable name.

Avoid names like isNotEnabled, hasNoAccess, or isDisabled.

Why? Because eventually, you will need to check for the opposite state. if (!isDisabled) forces your brain to calculate a double negative: “If not is disabled…”

Compare that to: if (isEnabled)

Immediate clarity.

Negative names feel natural when you write them (“I need to check if this is disabled”), but they are a tax on every person who reads the code later. Refactoring tools make this worse; if you invert an if statement, your IDE might helpfully rename isDisabled to isNotDisabled. Now you have code that is actively hostile to human readers.

The Exception: The only time a negative name is acceptable is when you are mirroring an external API or HTML attribute that is negative by default, like noValidate. Even then, isolate it at the boundary. In your domain logic, always map it to a positive: bool shouldValidate = !request.noValidate.

Context Matters (The “Boolean Trap”)

The rules above work perfectly for properties (state). They fall apart for parameters (function arguments).

This is the “Boolean Trap”:

// Real code from NHibernate
schemaExport.Execute(false, true, false);

Quick: What does the second true do? You have no idea. You have to open the library source code to find out.

If you see a method signature like Execute(bool, bool, bool), you are looking at a design bug.

How to fix it:

1. Split the method If the boolean changes the method’s behavior entirely, make two methods.

// Bad
email.Send(message, true); // is true "immediate"? "high priority"?

// Good
email.SendImmediately(message);
email.SendQueued(message);

2. Use an Enum If there are modes, name them.

// Bad
file.Write(data, true);

// Good
file.Write(data, WriteMode.Append);

3. Use a Config Object If you have multiple flags, pass an object.

// Bad
export.Execute(false, true, false);

// Good
export.Execute(new ExportOptions { 
    Script = false, 
    Export = true, 
    JustDrop = false 
});

The Antipatterns

If you want to clean up your code, watch out for these specific smells in code reviews.

1. The “Shrug” Variable Names like flag, done, or check tell you nothing about what is being tracked.

  • Bad: if (check)
  • Fix: if (isPaymentVerified)

2. Mismatched Grammar Breaking the prefix rules confuses the mental model.

  • Bad: if (user.hasActive)
  • Fix: if (user.isActive)

3. The Double Negative Any time you see a ! next to a Not or No.

  • Bad: if (!isNotEnabled)
  • Fix: if (isEnabled)

4. The Multi-Purpose Boolean A single variable that secretly tracks three different things.

  • Bad: isValid (Actually checks if user exists, has email, AND is active).
  • Fix: Be explicit.
    bool isReadyForBilling = user.Exists && user.HasEmail && user.IsActive;

5. The Drifting Flag A local boolean that gets reused for different logic steps.

  • Bad:
    bool error = false;
    if (!Save()) error = true;
    if (!error && !SendEmail()) error = true;
    return error;
  • Fix: Use a Result object or return early. Don’t recycle a boolean bucket.

Conclusion

Naming isn’t about style. It’s about empathy.

When you name a boolean flag, you’re writing for yourself in the moment. When you name it isProcessed, you’re writing for the poor soul who has to fix a bug in this file six months from now. That person is probably you. Be kind to your future self.