Strict Evaluation

Strict evaluation, also known as eager evaluation, is the evaluation strategy used by most functional programming languages where an expression is evaluated as soon as it is bound to a variable. Strict evaluation is in direct opposition to lazy evaluation, where the evaluation of an expression is delayed until its value is needed. Haskell is the most popular programming language that uses lazy evaluation. Most programming languages use strict evaluation for function arguments (sometimes referred to as parameters) such as Java, Scheme (a Lisp language), and JavaScript.

Using strict evaluation results in code that is easily understandable in terms of execution order, an easier debugging process compared to other evaluation strategies, and the responsibility for code performance being shifted to the programmer, meaning a careful code optimization process is required.

Evaluation strategies in programming

Evaluation strategies are used in programming languages to determine when to evaluate the arguments of a function call and what kind of value to pass to the function. There are many evaluation strategies, but most fall under one of two umbrella categories: Strict and lazy evaluation.

Strict evaluation strategies

  • Call-by-value: The most common evaluation strategy that consists of copying the content of the actual parameters into the formal parameters. If the function is able to assign values to its parameters, only its local variable is assigned, meaning anything passed into a function call is unchanged. Call-by-value is not a single evaluation strategy but rather a family in which a function’s arguments is evaluated before being passed to the function. Programming languages such as C, Eiffel, and Common Lisp use a call-by-value strategy.
  • Call-by-reference: Another common strategy. Whereas the call-by-value strategy copies the content of the actual parameter to the formal parameter, a call-by-reference strategy copies the address of the actual parameter to the formal one. A function receives an implicit reference to a variable used as an argument rather than a copy of its value. C++ uses the call-by-reference strategy.

Lazy evaluation strategies

  • Normal order: An expression is evaluated by repeatedly evaluating the left-most, outer-most reducible expression first.
  • Call-by-name: The actual parameter is only evaluated if used inside the function. If a parameter is not used in the function body, it is never evaluated. If it is used several times, it’s re-evaluated each time it appears.
  • Call-by-macro-expansion: Similar to call-by-name but avoids substitution. Provides developers with a mechanism to add new syntax to the core language grammar known as macros. Macros are expanded into code by a macro preprocessor.
  • Call-by-need: A parameter is evaluated only if it’s used. Once the first evaluation happens, the result is cached, so further uses of the parameter don’t require re-evaluation.






Abby Braden
Abby Braden
Abby Braden is an award-winning writer and editor for websites such as TechnologyAdvice.com, Webopedia.com, and Project-Management.com, where she covers technology trends and enterprise and SMB project management platforms. When she’s not writing about technology, she enjoys giving too many treats to her dog and coaching part-time at her local gym.

Related Articles

Special Character

A special character is one that is not considered a number or letter. Symbols, accent marks, and punctuation marks are considered special characters. Similarly,...

Software

Table of contents What is Software? History of Software Software vs. Hardware Software vs. Hardware Comparison Chart What Types of Software Exist? Saas vs....

Email Address

What is an Email Address? An email address is a designation for an electronic mailbox that sends and receives messages, known as email, on a...

Information Technology (IT) Architect

The information technology architect applies IT resources to meet specific business requirements. The role requires a high degree of technical expertise as well as...

Geotargeting

Geotargeting is a method of delivering data or content to users based on...

Agile Project Management

Agile project management enables business teams to approach their projects and tasks with...

Private 5G Network

A private 5G network is a private local area network (LAN) that utilizes...