From the course: Advanced C#: Functional Programming Patterns
Unlock this course with a free trial
Join today to access over 24,800 courses taught by industry experts.
Why expressions are better for functional programs - C# Tutorial
From the course: Advanced C#: Functional Programming Patterns
Why expressions are better for functional programs
One fundamental difference between functional and imperative styles is that imperative code relies on statements, functional code relies on expressions. Since C# supports both styles, we should minimize the use of statements when possible. Focus on writing your code to favor expressions over statements. Languages like C# use statements such as the if statement and the for statement to perform logic tests and execute actions. With statements, the focus is on describing how tasks should be done, using statements to change the program state through loops, conditionals, and variable assignments. This approach emphasizes the steps involved with each statement, altering the state as the program progresses. While this is effective, it contrasts with functional programming, where the focus shifts to expressions. In contrast, functional programming emphasizes what to compute using expressions that produce values. In many cases, this value is the result of a calculation, but that is only a…
Contents
-
-
-
-
-
-
-
-
(Locked)
Why expressions are better for functional programs2m 20s
-
(Locked)
Some examples of C# expressions2m 16s
-
(Locked)
Rewrite IF statement with expression4m 41s
-
(Locked)
Rewrite SWITCH statement with expression3m 4s
-
(Locked)
Rewrite FOREACH with expression1m 45s
-
(Locked)
IsPrime function as an expression1m 58s
-
(Locked)
-
-
-
-
-