Programming

Wait a minute, you might say to yourself. What do I mean by the meaning of the program? This is a surprisingly deep topic that involves a whole branch of mathematics known as homotopy. But for all practical intents and purposes of this chapter, let's define the meaning of a program to be the extensional definition of the program. If two programs compile and run, take the exact same inputs, and return the same exact output every time, we say two programs are equal.

These two programs would be equal:

Program A

Program B

fmt.Println("Hello World")

fmt.Printf("Hello " + "World ")

 

Intentionally, if we visualize the programs as an Abstract Syntax Tree (AST), they look slightly different:

The syntax for both programs are different, but they are semantically the same. We can refactor program B into program A, by eliminating the +.

But note what we did here: we took a program and represented it as an AST. Through syntax, we manipulated the AST. This is the essence of programming.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.111.208