- Mastering macOS Programming
- Stuart Grimshaw
- 252字
- 2021-07-02 22:54:27
Declarative programming
Let's go back to our conversation with the taxi driver. Wouldn't it be better to say "Take me to the station"? Someone has already taught the taxi driver to turn left and stop at a red traffic light (although the latter is debatable in many cities). We just need to state our destination.
In declarative programming, the emphasis is more on telling the program what to do, as opposed to how to do it. Languages that support (or use exclusively) declarative programming are in some sense at a higher level still than OOP, and they include database query languages such as SQL, and even HTML. The HTML we load into our browser doesn't tell it how to render text to a screen, or how to calculate the width of a table that should occupy half of the window width, it simply lists the page elements it wants to see and the content that goes inside those elements.
That doesn't mean, of course, that the rest happens by magic. Either a lot of code is provided (and hidden) by the environment in which the language is deployed (the browser, in the case of HTML), or the code relies on a lot of other code that has been written previously, and built up to the point where the developer is no longer explicitly writing the low-level implementation details of an app, but is instead specifying what needs to be done.
A sub-genre of declarative programming that does exactly that is functional programming.