JavaScript:
Go is a programming language developed at Google. Two of the developers came from Bell Labs and were involved in developing UNIX and the C Programming Language. Not surprisingly, Go looks a lot like C on steriods:
- It is a package-based language with a type system a lot like C.
- It has neither classes nor generics.
- It has value types, reference types, and garbage collection, but compiles to native code.
- Go functions are similar to JavaScript functions: they are lambdas, e.g., are first class functions that can be passed to and returned from other functions, they can be constructed as anonymous functions, and they have closures. That is, they capture local data they need from the scope where they are defined and, if passed out of that scope carry their data or references to be used later.
- Any references to local data remain valid when passed out of their local scope. The garbage collector does not dispose them until all references go out of scope.
- It has a library with some quite powerful components. You can build a web server in a few lines of code, using the available library constructs.
- Go has built-in concurrency in the form of Go routines which run asynchronously.
- Go has a channel construct intended for interprocess communication, something like pipes.
In these demos, we look at Go basics. We don't yet have example use of Go routines or channels.
Code Demos:
Note: The college server will not download files with extension .go, so I've changed the extensions to .go.txt. To run these
examples in the Go environment you will need to remove the .txt part.