From 9cc715bd92d88ca29ed3d2cb900f424e45fa578d Mon Sep 17 00:00:00 2001 From: jeff Date: Thu, 30 Jul 2020 22:44:24 +0000 Subject: [PATCH] BlogPost_BooleanNames (#22) Blog post on boolean names. Co-authored-by: steverusso --- Dockerfile.prod | 4 +-- README.md | 11 ++++++++ assets/simplesystems.css | 8 ++++++ config.toml | 5 +++- content/blog/boolean_names.md | 40 +++++++++++++++++++++++++++ static/img/yinyang-simplesystems.png | Bin 0 -> 11035 bytes 6 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 content/blog/boolean_names.md create mode 100644 static/img/yinyang-simplesystems.png diff --git a/Dockerfile.prod b/Dockerfile.prod index 37eb3ad..3bbb2f4 100644 --- a/Dockerfile.prod +++ b/Dockerfile.prod @@ -18,7 +18,7 @@ FROM golang:alpine AS build-webserver RUN apk update && apk upgrade && \ apk add --no-cache git -RUN go get -u git.simplesystems.tech/SimpleSystems/static-web-server +RUN go get -u git.simplesystems.tech/simplesystems/static-web-server # STEP 3: Combine static files and binary on fresh alpine image FROM alpine:latest @@ -31,4 +31,4 @@ COPY --from=build-website /src/public /app/public # Copy over static-web-server COPY --from=build-webserver /go/bin/static-web-server /app/ -ENTRYPOINT ["./static-web-server", "-rootDir", "public", "-port", "80", "-redirect"] +ENTRYPOINT ["./static-web-server", "-rootDir", "public", "-port", "80"] diff --git a/README.md b/README.md index 4466ca6..2c98ee8 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,23 @@ Built using [Hugo](https://gohugo.io/getting-started/installing/) hugo server ``` +Development can also be run using Docker: +```shell script +docker build --no-cache -f Dockerfile.dev -t website-fe . && \ +docker run -it -p 1313:1313 --mount source=$(pwd),target=/src,type=bind --rm website-fe +``` + ## Production To build the production site, run the following command: ``` hugo --minify ``` +To build the Dockerfile, run this command: +```shell script +docker build --no-cache -f Dockerfile.prod -t docker.simplesystems.tech/simplesystems/website:latest . && docker push docker.simplesystems.tech/simplesystems/website +``` + The resources will be stored in the `./public` directory. ## Managing Job Posts diff --git a/assets/simplesystems.css b/assets/simplesystems.css index 44a9f49..1ab0f07 100644 --- a/assets/simplesystems.css +++ b/assets/simplesystems.css @@ -340,3 +340,11 @@ button.round, .btn.round { } .blue { --clr: #42A5F5 } + +pre { + background: #eee; + border-radius: 5px; + padding-left: 1rem; + color: black; + font-size: 0.95rem; +} diff --git a/config.toml b/config.toml index ac8095d..d49234c 100644 --- a/config.toml +++ b/config.toml @@ -3,4 +3,7 @@ disableKinds = ["taxonomy", "taxonomyTerm"] title = "SimpleSystems, LLC" [markup.goldmark.renderer] -unsafe= true + unsafe= true + +[markup.highlight] + style = "friendly" diff --git a/content/blog/boolean_names.md b/content/blog/boolean_names.md new file mode 100644 index 0000000..01ed83f --- /dev/null +++ b/content/blog/boolean_names.md @@ -0,0 +1,40 @@ +--- +img: /img/yinyang-simplesystems.png +title: "Boolean Variable Names" +author: Jeff Russo +pdate: June 30, 2020 +desc: Choosing a good boolean variable name +--- + +Choosing good names for variables is an important art for software engineers to master. Variable names are documentation and can remove [complexity](http://localhost:1313/blog/complexity/) from code. Using a bad name for a variable leads to confusion, bugs, and wasted engineer time. In this blog post I will discuss what makes a [boolean](https://en.wikipedia.org/wiki/Boolean_data_type) variable name good or bad. + +## Good Boolean Names +Boolean names should be [negatable](https://www.yourdictionary.com/negatable) and in the positive form. They should be clear and concise just as all variable names should be. As the scope of the variable increases, its level of description should increase as well. + +_The Elements of Style_ 1 is a concise guide to writing English. Some rules can be used as a guide for writing code as well. For example, rule 11, "Put statements in positive form," can be applied to naming boolean variables. In code, there is one additional requirement: the statement must be positive as well. 'enabled' is both in the positive form and a positive statement. 'disabled' is in the positive form but is a negative statement. 'notEnabled' is both in the negative form and a negative statement. + +In English, it is best to use enabled or disabled, and to avoid "not enabled"; they are more concise and stay in the positive form. The extra requirement of using a positive statement for boolean names is because the negations of boolean variables have meaning as well; in writing, "not disabled" is a double negative and is discouraged. In code '!disabled' is also a double negative, and should be avoided. + +A boolean name should give the reader more clarity as its scope expands. A boolean variable that exists for the scope of an if statement may have a short name ('ok'). If this variable was in scope throughout the function, it would become meaningless. + +## Bad Boolean Names +As with many things in software engineering, it is easier to find mistakes than to do something correctly the first time. Here are some naming conventions to avoid: +1. Names that are already a negation. 'featureTurnedOff' and 'notProd' may make sense in one use case, but they become confusing in a larger context. The following code is both hard to read and ambiguous (what if there is a third environment). + ```go + + confA.useProd := !confB.notProd + + ``` + +2. Names that are not negatable. A name such as 'sheets' has ambiguous meaning. It probably has something to do with a spreadsheet, but it is the writer's responsibility to prevent the reader from needing to do an investigation. + +3. Names that are in negative form. These typically appear when the default use is the negative form. For example, 'disabled' for a service typically disabled. Keep all the names in positive form to avoid a future headache explaining what the billing system does when it's "not disabled". Is it now enabled, or is it just not disabled? + +4. Overly general names. As discussed earlier, this depends on the scope of the name. Avoid using a name such as 'on'. It leaves questions in the reader's mind such as "_Which_ thing is on?". The exception to this is typical boolean names used across code bases; Go's 'ok' is an example of this. + +5. Negatable adjectives without context. 'bool customSize' is clear, but without the 'bool' context, the type is unclear. Ambiguity can be removed by prepending 'is' or 'has' ('isCustomSize'). + +## Conclusion +This blog post discussed a goal to aim at (good names) and several things to avoid (bad names). Combined, these will hopefully increase the readability of the software you write! + +1 https://tinyurl.com/y3uxhzxc diff --git a/static/img/yinyang-simplesystems.png b/static/img/yinyang-simplesystems.png new file mode 100644 index 0000000000000000000000000000000000000000..7bba262d76d1ee7d6ce7d8bd67535e59aade1cfc GIT binary patch literal 11035 zcmZv?c{o*H^gq7Oom^a8^UM`xEQHMNk%}f6$`Iw2LT06q;T|bzFf>VJxKv1)qBIz8 zG8Pgk8LuIfd7iF&e%_zo_j!KL_xF7EKl|*x*EwgeXRr0zueF|a!^YZ@k4K6J0Km83 zYL6WNn9WBFAYwPW&)G^1n_a2Rp`&{@`&+ke&CbqFPfy#}*i24N9zJ~7+1dH%(W3_r z99URbu(PvsaBy&Sb+xp#93LNdb8|a&>Xe_KpO24ETwL7Mt5>6=qtBf?=kD$v931TF z=@}av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