- Let's take C and move the argument type to the back, because pointers to pointers are cumbersome to read. This makes the syntax of a defined array: var primes := [6] int {2, 3, 5, 7, 11, 13}
- While we're moving things to the back, let's also move the function's return arguments to the back too. That way, all those C programmers start to appreciate their dyslexia.
- Let's have pointers, but we're all about safety, so no pointer arithmetic.
- Since we don't have pointers to arrays, let's create slices. You update one slice and it updates all the slices of that array! But hey, no pointer arithmetic, so we're preventing programmer created bugs.
- And we want all the goodies from a Python list, so let's make slices dynamically sized. For some reason, we still need arrays.
- And we love Python so much, we'll add the ability to iterate over a range and have a dictionary type called map.
- Let's rename typedef as type, because we save 3 characters and we're all about efficiency. But let's leave struct in, we're not just changing keywords for the sake of it are we? And struct members are accessed with a dot even when the variable is a pointer to a structure. Let's add arbitrary syntax since we're just making things up a this point.
- And let's get rid of breaks in case blocks, because we're all about efficiency.
- While we're at it, let's introduce a "naked" return that magically returns all the named arguments. Readability guy took the day off when this was added.
- And let's start time 0 on the day Go went open source - acknowledging the momentous day that must take precedence over UNIX's, Python's and every other major language's well established start time.
- Let's import "import" from Python, but let's add the option to import multiple modules using a parenthesis, because ... efficiency.
- Let's take the package concept from npm, but let's add our nifty touch to it by having a "tidy" keyword to updated dependencies.
- Let's solve those pesky multiple returns in a function by adding a defer keyword, because readability is important, but not that important. And did the readability dude resign or something?
- The parenthesis around for need to be DOGE'ed too - programmers can save a whole of 3 seconds per day skipping the typing. It's OK to spend a few minutes deciphering the for intent - makes you understand the code better. And while was such a burden on C programmers - let's just get rid of it. After all, what could while do that for couldn't?
- C++ is admittedly a complex language. Let's avoid classes in Go and instead add a receiver that lets one add a method to a type. And let's make the syntax: func <pointer to receiver> <method> (<method arguments>) <return type>. See, the syntax in #1 now makes total sense.
- And breaking with the random logic that drives the rest of the syntax, let's constrain the receiver restricted to the same file as the method. The "pointer to receiver" part is important, without which the method behaves as a function that operates on a value and not the reference.
net.createServer(stream => { stream = toPull.duplex(stream) //turn into a pull-stream //connect the output of the net stream to the muxrpc stream //and then output of the muxrpc stream to the net stream pull(stream, server.stream, stream) }).listen(8080) //connect a pair of duplex streams together. const stream = toPull.duplex(net.connect(8080)) pull(stream, client.stream, stream)
Let's deconstruct:
First, the problems as seen by a C programmer
- stream is used before it's defined
- The anonymous arrow function takes one argument stream and returns a closure that uses and initializes the same argument, stream.
- The function pull has 3 arguments out of which 2 are the same. This is reasonable - if stream is input at one spot and output at another.
- The function call inside createServer is a CALLBACK. It is not immediately called.
- The listen on port 8080 starts immediately.
- Once the client connects using toPull.duplex, the server calls the function inside createServer with stream being initialized to the server side of the connected stream.