Functional Programming Flashcards Preview

.NET / C# > Functional Programming > Flashcards

Flashcards in Functional Programming Deck (17)
Loading flashcards...
1

What is a high-order function?

Receives a function, returns a function or both.

2

What is a Pure Function?

It is a function without side effects. Always returns the same output when the same input is defined.

3

What is lazy evaluation?

Expression is not evaluated before the value is actually required.

4

What is pattern matching?

?????

5

What is a value type?

The value never changes and behaves like a value.

6

What is referential transparency?

The whole expression can be replaced by a simple value

7

What does Steve McConnel wanted to say with "Program into the language" not "in the laguange?

Means that you should express your thoughts using the language. not allowing the language shape your thoughts.

8

What are few drawback object-oriented programming has that can be tackled by functional one?

Methods know too much (too many dependencies) which is very hard to manage in large projects.
Polymorphism increases the complexity a lot.

9

What happens to state properties of an object when its functions are converted to pure functions?

The properties must become readonly. otherwise we can't ensure the same input produces the same output.

10

How to apply functional design to classes?

1 - Make public methods simple;
2 - Make them isolated;
3 - Do not expose complex functions;
4 - Let the consumer mix and match small functions;

11

What are the rules to create a pure function?

1 - Will never modify its argument;
2 - Will never call a mutator on its argument;
3 - Will not have an out argument or in/out (ref) argument;
4 - Will never throw an exception;
5 - Will only tell its result through the return value;

12

What is a tuple? By what was it superseded and when?

A tuple is a type that bundle values together. It was superseded by the ValueTuple on .net 4.7 and core 2.0.

13

What is the problem with a tuple? How was it resolved?

The problem is that it is hard to read. Solved by the the following syntax:
(double Sum, int Count) t2 = (4.5, 3);
Console.WriteLine($"Sum of {t2.Count} elements is {t2.Sum}.");

14

What is the main structual differences between tuple and value tuple? Why is not a good idea exposing a valueTuple in a public api?

Tuple are classes and ValueTuple is a struct. Not a good idea becuase valueTuple allows changing the values.

15

What is Referential Transparency?

You can replace a method with its own produced output.

16

What is Memoization?

Cache the results of a pure function to improve performance.

17

What is dynamic programming?

In terms of mathematical optimization, dynamic programming usually refers to simplifying a decision by breaking it down into a sequence of decision steps over time.