Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Stroustrup in "The C++ Programming Language 3rd Edition (online)" define the function sqrt? [closed]

Tags:

c++

Bjarne Stroustrup, in 3rd edition (online) of his book "The C++ Programming Language" chapter 2, page 23 (pdf page 34), in a snippet paradigm, defines the function sqrt. Why does he not just use the one already included in the standard library?

like image 574
George Theodosiou Avatar asked Feb 03 '17 09:02

George Theodosiou


1 Answers

Because sqrt is an example of a 'good style' procedural function. It takes an input, processes it, and returns the result.

The book is not suggesting that you should write you own, or to copy the definition from the book (which lacks the implementation entirely anyway). The book also isn't demonstrating how to calculate a square root. It is describing the purpose of functions in procedural programming (or that's my interpretation anyway).

like image 125
eerorika Avatar answered Sep 22 '22 13:09

eerorika