Section 1

Preview this deck

What are the two primary aspects of functional programming?

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 14, 2020

Cards (13)

Section 1

(13 cards)

What are the two primary aspects of functional programming?

Front

Higher order functions. Pure functions.

Back

What is a pure function?

Front

A function with no side-effects that is a function of just it's inputs. Also returns the same results, given the same inputs.

Back

What is memoization?

Front

Storing the output of a perfect function for future use to save on overhead of running it again, b/c you know the same input will generate the same output.

Back

The 'None' object

Front

What is returned by functions that don't explicitly return anything?

Back

Why use a tuple?

Front

When u need an immutable data structure, and when the order of elements is important (like coordinates)

Back

What do type annotations in Python 3.6 enable?

Front

...

Back

What are advantages & disadvantages of pure functions?

Front

Advantages are: - they are easy to read and test. - memoization. - easy to parallelize Disadvantage: - some functions need to perform i/o, which breaks this approach

Back

Why use 'with' when working with files?

Front

It creates a temp file object that's only live during the indented scope, and is closed automatically, even if there's an exception that kicks you out of that scope.

Back

Why use an empty tuple?

Front

You can have a function that returns a populated tuple if a condition is met, or an empty one of it isn't

Back

What does file.write() return?

Front

The length of the message written.

Back

Assertions vs. Error handling

Front

Error handling is for occurrences that may happen, while assertions are for 'impossible' scenarios that indicate a logic flaw in software. (by asserting something, one is saying, 'this must be true'). It's typically not possible to recover from an assertion.

Back

What are higher order functions?

Front

Functions that take other functions as arguments, or that return functions as results.

Back

Why should one avoid using generic 'except' statements that catch all errors?

Front

It's lazy, and can hide errors from exceptions that haven't been considered.

Back