encyclopegia.org

Gotcha (programming)

In programming, a gotcha is a valid construct in a system, program or programming language that works as documented but is counter-intuitive and almost invites mistakes because it is both easy to invoke and unexpected or unreasonable in its outcome.

In programming, a gotcha is a valid construct in a system, program or programming language that works as documented but is counter-intuitive and almost invites mistakes because it is both easy to invoke and unexpected or unreasonable in its outcome. if (a = b) code; It is syntactically valid: it puts the value of b into a and then executes code if a is non-zero. Sometimes this is even intended. However most commonly it is a typo: the programmer probably meant if (a == b) code; which executes code if a and b are equal. Modern compilers will usually generate a warning when encountering the former construct (conditional branch on assignment, not comparison), depending on compiler options (e.g., the -Wall option for gcc). To avoid this gotcha, some programming languages such include specific syntax for when this is desired behavior, such as Python's "walrus" operator ( := ). In languages where this specific syntax does not exist, there is a recommendation to keep the constants in the left side of the comparison, e.g. 42 == x rather than x == 42 . This way, using = instead of == will cause a compiler error (see Yoda conditions). Many kinds of gotchas are not detected by compilers, however. ==See also== Usability ==References== ==Further reading== ==External links== C Traps and Pitfalls by Andrew Koenig C++ Gotchas A programmer's guide to avoiding and correcting ninety-nine of the most common, destructive, and interesting C++ design and programming errors, by Stephen C. Dewhurst

References

No reference rows published for this article.

Cite this article

MLA

"Gotcha (programming)." encyclopegia.org, 2024, https://encyclopegia.org/wiki/gotcha-programming. Accessed 24 November 2026.

Chicago

"Gotcha (programming)." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/gotcha-programming.

APA

encyclopegia.org. (2024). Gotcha (programming). Retrieved November 24, 2026, from https://encyclopegia.org/wiki/gotcha-programming

Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

Ellis–Van Creveld syndrome

enwiki · references available

Sandhills (Nebraska)

enwiki · references available

Thomas Ford (politician)

enwiki · references available

Slipstream 5000

enwiki · references available

Mortiser

enwiki · references available

Mar Saba

enwiki · references available

San Pablo Villa de Mitla

enwiki · references available

Itea, Phocis

enwiki · references available

Lixnaw

enwiki · references available

Richard Edward Wilson

enwiki · references available

Finuge

enwiki · references available

Complex conjugate of a vector space

enwiki · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1252378300 · 0.5 · snapshot enwiki-001252378300

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.