Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Short-circuit evaluation
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Untested second condition leads to unperformed side effect === Despite these benefits, minimal evaluation may cause problems for programmers who do not realize (or forget) it is happening. For example, in the code <syntaxhighlight lang="c"> if (expressionA && myfunc(b)) { do_something(); } </syntaxhighlight> if <code>myfunc(b)</code> is supposed to perform some required operation regardless of whether <code>do_something()</code> is executed, such as allocating system resources, and <code>expressionA</code> evaluates as false, then <code>myfunc(b)</code> will not execute, which could cause problems. Some programming languages, such as [[Java (programming language)|Java]], have two operators, one that employs minimal evaluation and one that does not, to avoid this problem. Problems with unperformed side effect statements can be easily solved with proper programming style, i.e., not using side effects in boolean statements, as using values with side effects in evaluations tends to generally make the code opaque and error-prone.<ref>{{cite web |url=http://www.itu.dk/people/sestoft/papers/SondergaardSestoft1990.pdf |title=Referential Transparency, Definiteness and Unfoldability |publisher=Itu.dk |access-date=2013-08-24}}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)