summaryrefslogtreecommitdiff
path: root/_posts/2019-08-02-program-structure-and-composability.md
diff options
context:
space:
mode:
authorLuke Jolly <lukejamesjolly@gmail.com>2019-09-10 12:55:16 -0400
committerLuke Jolly <lukejamesjolly@gmail.com>2019-09-10 13:51:27 -0400
commit1fa475a92c3ebb1960a23db7f622b61513fe9b1a (patch)
treeb8d5a2a29417bb4b0a64ae9423d53ba0d80a53f4 /_posts/2019-08-02-program-structure-and-composability.md
parenta6a158a8a2472356983716e8af525c72d2a27f71 (diff)
Clarified parse section of program-structure-and-composability
Diffstat (limited to '_posts/2019-08-02-program-structure-and-composability.md')
-rw-r--r--_posts/2019-08-02-program-structure-and-composability.md21
1 files changed, 12 insertions, 9 deletions
diff --git a/_posts/2019-08-02-program-structure-and-composability.md b/_posts/2019-08-02-program-structure-and-composability.md
index 41facc0..b44c534 100644
--- a/_posts/2019-08-02-program-structure-and-composability.md
+++ b/_posts/2019-08-02-program-structure-and-composability.md
@@ -376,11 +376,10 @@ Easy-peasy.
Sharp-eyed gophers will notice that there is a key piece missing: When is
`flag.Parse`, or its `mcfg` counterpart, called? When does `addrParam` actually
-get populated? You can’t use the redis connection until that happens, but that
-can’t happen inside `redis.NewConn` because there might be other components
-after `redis.NewConn` that want to set up parameters. To illustrate the
-problem, let’s look at a simple program that wants to set up two `redis`
-components:
+get populated? It can’t happen inside `redis.NewConn` because there might be
+other components after `redis.NewConn` that want to set up parameters. To
+illustrate the problem, let’s look at a simple program that wants to set up two
+`redis` components:
```go
func main() {
@@ -402,14 +401,18 @@ func main() {
// before, redis.NewConn can't parse command-line.
barRedis := redis.NewConn(cmpBar, "127.0.0.1:6379")
- // If the command-line is parsed here, then how can fooRedis and barRedis
- // have been created yet? It's only _after_ this point that `fooRedis` and
- // `barRedis` could possibly be usable.
+ // It is only after all components have been instantiated that the
+ // command-line arguments can be parsed
mcfg.Parse()
}
```
-We will solve this problem in the next section.
+While this solves our argument parsing problem, fooRedis and barRedis are not
+usable yet because the actual connections have not been made. This is a classic
+chicken and the egg problem. The func `redis.NewConn` needs to make a connection
+which it cannot do until _after_ `mcfg.Parse` is called, but `mcfg.Parse` cannot
+be called until after `redis.NewConn` has returned. We will solve this problem
+in the next section.
### Instantiation vs Initialization