this skill that we are studying is not about following algorithms, for that is the job of the computer
it is to construct these steps in such a way that computers can
comprehend them
give the desired outputs for given inputs
do so in a reasonable timespan
in order to achieve these aims, we must overcome certain common hinderances
now, this is where abstraction comes in
in any real world problem, there will be excess choices for which sets of data to analyse
consider the search engine google
the abstractions that google should make to design an algorithm that decides what webpages to return a user are subjective
should google just care about the text searched for and abstract the rest away?
should google moreover care about previous searches and which ones captured your attention for longer?
what details regarding the webpages themselves are genuinely relevant?
ultimately, it will depend on their specific aims
in modern programming languages, it is not always evident what code does in memory
thus, it can read more like pure logic and more time spent coding can be allocated for algorithms
on the other hand, if a language is a more realistic representation of the true interface with hardware, its performance is better
chapter 48
--- thinking ahead ---
let f = (...inputs) => outputs
the above is a neat abstraction of a pure function and code of this form can used and reused again and again
however, for some functions, there exist inputs that would not (and often should not) yield a meaningful output
having preconditions on inputs is one solution to this
for example, in a function for the square root, it may be preferable for negative inputs to throw an error
for expensive calculations, it is easier to temporarily remember the result as opposed to repeating the calculation
it is for this reason, caching time consuming operations such as downloading media is used frequently in optimised applications
chapter 49
--- decomposition and thinking procedurally ---
finding the sum of an array of numbers
adding two numbers
adding three bits
problems are formed of sub problems
it is through decomposition that hard problems can be reduced to their simpler constituents
in the shown example, functions we may take for granted are the result of smaller and smaller tasks
top-down design is tactic of decomposing into subroutines
hierarchy charts are a visual representation of this process