January 2, 2023
I had two weeks off at the end of 2022. Telesign closed its operations on the last week of 2022 to give employees well-deserved time off for a year of hardwork and I took another week off in addition to that. Like many technologists, I became captivated by OpenAI’s release of ChatGPT in 2022, and I spent a lot of the last two weeks exploring what OpenAI has to offer.
January 24, 2021
My wife got me a 5 gallon fish tank last Christmas. I’ve wanted to set up a planted tank – an aquarium ecosystem balanced by plants. In a planted tank, the vegetation naturally filter water by using bio waste as fertilizer, and typically contain critters like shrimp and snails to keep algae from taking over. This idea was heavily inspired by Youtube videos from Michael Langerman and Foo the Flowerhorn.
November 13, 2020
When you are using an AWS Application Load Balancers to front your APIs or EC2 instances, you will need the right SSL certificate(s) on your ALB to encrypt traffic. For example, if your ALB handles traffic for apis.example.com and apis.example.org, you’ll need two SSL certificates.
When you request an SSL certificate, you need to prove that you are truly the owner of the domain. In many cases, this is as simple as adding a custom CNAME entry to your DNS records to show that you have control over the domain.
October 15, 2020
I briefly worked on a workflow system at $past_job, implemented using AWS Step Functions. My experience was pretty terrible. I wasn’t sure which technical requirements led the team to this system. Some people said we needed a “system that is configuration driven and not code driven” and some people said “we needed something that scales.” Whatever the reason was, making improvements to this system was a pain in the ass, with AWS Step Functions itself being somewhat responsible.
September 8, 2020
I want to love DynamoDB. I love that it just scales (disk usage and processing power). I love that it is tightly integrated with AWS’s IAM model, so I don’t have to deal with user/role/permissions management.
But DynamoDB does some weird things by design. For example, only the primary key can be unique. If you want a table with multiple unique attributes, for example, a Users table where both the user_name and email are unique, you’ll have to do weird things like this.
July 26, 2020
I spent too much time Saturday getting the Go S3 SDK to work with LocalStack.. It turns out that if you are using LocalStack, you need to explicitly configure the following properties:
sess, err := session.NewSession(aws.NewConfig(). WithEndpoint(endpoint). WithRegion(region). WithS3ForcePathStyle(true)) The requirements for Endpoint and Region are obvious. If S3ForcePathStyle is not specified, then LocalStack will fail.
data, err := svc.GetObject(&s3.GetObjectInput{ Bucket: &bucket, Key: &cfgKey, }) What is path-style? In May 2019, Amazon deprecated path-based access model for S3 objects.
August 19, 2019
I previously wrote about owning my own data. An
important part of data ownership is backing up your data. I use S3 as my long term data store. It is
pretty easy to set this up using Terraform.
S3
Provisioning a S3 bucket is simply a single Terraform resource:
resource "aws_s3_bucket" "repo_archive_log" {
acl = "log-delivery-write"
bucket = "example-bucket"
tags = {
Name = "example"
TTL = "persistent"
ManagedBy = "Terraform"
}
}
August 17, 2020
I finished Managing Humans from Michael Lopp today. I knew of Lopp through “Rands Leadership”, the Slack community he created. I enjoyed learning from the people in the community and thought I’d pick up his book. I’m not sure what I expected going into the book. I think I expected tips and rules that I can follow. After trying to summarize the book, I think what I wanted and got was a set of mental models that I am happy to add to my toolbox.
May 28, 2020
Steve Jobs, Bill Gates, and Jeff Bezos are considered great entrepreneurs of our time. But Elon Musk has to be recognized as an unique compatriot. With SpaceX, Elon has rallied folks to create a privately funded company capable of sending men to space. This is no small feat. Whereas Apple, Microsoft, and Amazon succeeded because people willingly gave money for their products and services, SpaceX has only lost money (overall). Musk’s ability to convince people to commit to his vision must be recognized.
October 30, 2020
By configuring your Docker containers to talk to a custom DNS server, you gain more control over how your container look up other services – database, other microservices, etc.,
It turns out Docker networking isn’t completely straight forward. On Linux you can:
Run a DNS server locally, either dnsmasq or devdns Run your container with --dns 172.17.0.1, the magic IP where your host machine is located Configure dnsmasq from step 1 via /etc/hosts Sadly, none of it was easy.
July 12, 2020
I still find it hard to believe how easy it is to run your own infrastructure in the cloud.
Running a Docker registry is as simple as adding a few lines of code to your Terraform configuration.
resource "aws_ecr_repository" "foo" { name = "bar" image_tag_mutability = "MUTABLE" image_scanning_configuration { scan_on_push = true } } When deployed, this create an registry where you can manage multiple Docker repositories. You can upload a Docker image to be used in your private ECS cluster:
August 13, 2019
Lately, I have been writing more code outside of full-fleged IDEs and found myself
tweaking Emacs into a lightweight IDE for Go. Having gofmt
automagically formatting the
code and refreshing it in the buffer is simply lovely. My current go-mode
cusomization
looks like this:
First, get the excellent go-playground
package.
(package-install 'go-playround)
Then, configure Emacs
;; Automatically format your code on save
(add-hook 'before-save-hook 'gofmt-before-save)
;; Automatically display gofmt processed code in buffers
(custom-set-variables
'(global-auto-revert-mode t)
'(auto-revert-interval 1))
;; Verbose output when running tests via go-test-current-*
(setq go-test-args "-v")
February 3, 2020
Algorithm interviews are the norm in software engineering. They provide a good enough approximation on whether an engineer makes good architecture and design decisions.
As example, let’s do a quick study of whether to use DynamoDB or RDBMS to store data for a project.
DynamoDB Fact(s) Implemented as a distributed hashtable. Distributed by design Pros Very little operational overhead. There’s no need to create multiple DB users; No need to study query plans; No need to think about how much disk space, RAM, or CPUs to assign to your DB; Only one option for table design (flat tables).
September 3, 2019
Code review can be an important part of a team’s culture, so it is worth thinking about. If you asked me about code review two years ago, I would’ve said its key to maintaining code quality and mentoring less experienced programmers. Now I know better. Code review is much about making the code better as it is about making the team happier. How the team runs code reviews should be based on the team’s values and culture.
October 17, 2021
In Chapter 1.3 of [Ball’s Writing an Interpreter in Go][1], we encounter one design decision of his Monkey programming language. Here, the lexer has a NextToken() method that looks like this:
func (l *Lexer) NextToken() token.Token { var tok token.Token switch l.ch { // [...] default: if isLetter(l.ch) { tok.Literal = l.readIdentifier() return tok } else { tok = newToken(token.ILLEGAL, l.ch) } } // [...] } This means the lexer itself does not do backtracking.
August 22, 2021
A lexer takes the source code, a sequence of characters, and group them into tokens. e.g., it makes the first decision on how to process the strings 100-10, -100-10, and -100--100 into groups. I’m going to call this grouping “tokenization” even though I may be misusing the term.
Tokenizing source code is hard. How should -100--100 be tokenized? Should it be a literal -100 followed by the minus token, followed by another -100?
July 29, 2021
Writing an Interpreter In Go by Thorsten Ball will be my personal introduction to writing an interpreter. I’ve never taken a comp sci class before, so I know nothing about compilers. On a lark, I decided to explore this area now, nearly 20 years after I started to learn computer programming.
If you are interested in this book as well, you might might the AST Explorer a useful companion.
I was told as some point in the past, that compilation can be broken down into four stages:
July 27, 2021
It happened. At the recommendation of https://twitter.com/dgryski, I bought Writing an Interpreter In Go. This will be my next hobby project. It’ll be interesting to see if I ever finish it.
April 18, 2021
Lots of small things today.
History “Those who cannot remember the past are condemned to repeat it”. I love reading about how software came to be the way they are today.
Before we can talk about where generics are going, we first have to talk about where they are, and how they got there.
https://cr.openjdk.java.net/~briangoetz/erasure.html
Go Errors Error handling is still jacked in Go 1.16. That is, the formatting change is still not present.
April 3, 2021
In this part of the series, we’ll write some hands-on Temporal code and run it. Let’s start with our requirements:
You need to transmit a data packet. You can choose from multiple Route Providers to do this. Transmission takes time – you will be notified on a callback URL when the packet is delivered. Delivery may fail – either because the acknowledgement was not sent or arrived late (because Internet).
April 1, 2021
I spent a couple of hours evaluating 3rd party libraries. What have I learned? For me, there’s one clear winner in a small field of candidates.
Presently, these are the top hits for “golang gauge counter timer”.
https://pkg.go.dev/github.com/go-kit/kit/metrics https://pkg.go.dev/github.com/facebookgo/metrics https://github.com/uber-go/tally The first result is go-kit. Go-kit isn’t a metrics library. Rather, it bills itself as a “framework for building microservices.” Its metrics package is simply a set of interfaces.
March 24, 2021
Go does not allow cyclic imports. A solution is to create a “shared” package to hold interfaces that related packages all reference. This, for some reason, reminds of me join tables in SQL.
Here is an example of a typical Go project. Packages toward the bottom, e.g., “common/persistence”, allow different packages to work with each other without introducing cyclic dependencies. For this project, “log” can be referenced by “config”, but cannot use “config” to conifgure itself.
March 8, 2021
Oldie but goodie. Go concurrency patterns
https://drive.google.com/file/d/1nPdvhB0PutEJzdCq5ms6UI58dp50fcAN/view
November 23, 2020
In A Tour of Go, it states “Go has pointers. A pointer holds the memory address of a value.” When you design your data structure in Go, you have to decide between using a pointer or not. There’s no clear rule of thumb for it.
I had been reading the Go source code to AWS’s client library for DynamoDB. For a while, I had been annoying with their API design, which looks like this:
August 1, 2020
As usual, LWN has a good write up on what’s going on in the Go community. This week’s discussion in on the new io/fs package. The Go team decided to use a Reddit thread to host the conversation about this draft design. LWN points out that posters raised the following concerns:
We added status logging by wrapping http.ResponseWriter, and now HTTP/2 push doesn’t work anymore, because our wrapper hides the Push method from the handlers downstream.
July 26, 2020
I spent too much time Saturday getting the Go S3 SDK to work with LocalStack.. It turns out that if you are using LocalStack, you need to explicitly configure the following properties:
sess, err := session.NewSession(aws.NewConfig(). WithEndpoint(endpoint). WithRegion(region). WithS3ForcePathStyle(true)) The requirements for Endpoint and Region are obvious. If S3ForcePathStyle is not specified, then LocalStack will fail.
data, err := svc.GetObject(&s3.GetObjectInput{ Bucket: &bucket, Key: &cfgKey, }) What is path-style? In May 2019, Amazon deprecated path-based access model for S3 objects.
June 3, 2020
Cyclical dependencies Go disallows circular dependencies between packages.
In Java this is allowed:
package b; import a.A; public class B { public static void main(String[] args) { System.out.println("A.main"); A.doA(); } public static void doB() { System.out.println("B.doB"); } } --- package a; import b.B; public class A { public static void main(String[] args) { System.out.println("A.main"); B.doB(); } public static void doA() { System.out.println("A.doA"); } } Similar code is forbidden in Go. If you want to have test utilities, you often run into circular dependencies, leading to practices like https://golang.
May 26, 2020
I’ve been using mock/Gomock to write tests in my personal project. When you’re building something in a new language, it is hard to prioritize learning every tool in your toolchain. For me, I’ve been writing custom and suboptimal code for Gomock because of a nifty but undocumented API call .Do.
In many cases, I wan to match subsets of a complex object while ignoring irrelevant parts. e.g., verify a function is invoked with a list of User objects, but only verifying the email addresses.
May 17, 2020
Here’s a rough layout of how I organize my Go project. Some parts are situational and some parts are essential. I’ll go over both in this blog.
A rough layout:
+ basedir +-- go.mod (module jcheng.org) +-- hello (empty) +-- log/ +-- utils/ +-- config/ +-- models/ +-- repositories/ +-- services/ +-- cmd/ +-- hello_app/ +--/cmd/ +-- speak/ +-- email/ +-- sms/ The basedir Situational.
I have my (personal) projects in a monorepo.
February 19, 2020
In a previous post, I talked about Gomock. I want to spend a bit more time on it.
As I’ve mentioned, setting up Gomock requires
Download mockgen go get github.com/golang/mock/mockgen@latest Edit your go.mod module jcheng.org go 1.13 require ( github.com/golang/mock v1.4.0 ) Add the go:generate incantation to your code //go:generate mockgen -source $GOFILE -destination mock_$GOFILE -package $GOPACKAGE package pastself import ( "time" ) ... Use mocks in your test case.
February 19, 2020
As promised, a few thoughts about Go that is annoying.
No Generics Code generation is tightly coupled with the tool chain. When I need to use code generation, i.e., enums and mocks, the use case can be solved with generics instead.
No lambda syntax Scala has a lambda syntax to make it easy to work with anonymous function objects
val numbers = Seq(1, 5, 2, 100) val doubled = numbers.map( n => n * 2 ) Java has a similar syntax
February 14, 2020
Today I want to talk a little about the testify and gomock packages and doing mocks in Go.
Mocking is essential when writing code that depends on external services, e.g., microservices, message brokers, and datastores. For many people, this means web applications: My system has business rules and talks to multiple services. How do I test the business rules without setting up all the services locally?
Some people argue that mocks create a false sense of test coverage and introduce blind spots.
February 8, 2020
I have a few side projects, published and unpublished. By trade, I’ve come to programming as a Java programmer. I started coding directly against the Servlet API and have coded using Enterprise Java Beans, Play Framework, Spring Framework, and even some Scala. Lately, I’ve been coding mainly in Go with some Python.
Go is a really nice programming language. Some people like it for its simplicity. I want to offer a different take on why you should learn and use Go for your own projects.
January 4, 2020
Viper is a configuration library fo Go. It has been my go to library for configs. Some of the best features of Viper are:
Ability to unmarshal subsets of a configuration file into a Go struct Ability to override contents of a configuration file using OS environment variables Here’s a brief example that demonstrates both features:
Assume you have a configuration file at $HOME/server.toml
resolve_dns = true http_keep_alive = 5 [example_com] doc_root = "/var/www/example_com" allow_files = "*.
November 29, 2019
For me, Go 1.13 arrived with anticipation of better error handling. Presently, the second Google search result for Go 1.13 error hanlding is an article that refers to the “xerrors” package. One feature of the xerrors package is that it produced errors with a stack trace showing where the error came from. The addition to Go 1.13, however, did not include this particular feature, and left me spending frustrating hours trying to debug the loss of stack trace after switching from xerrors to the standard library.
August 19, 2019
I’ve written a lot of Python. If I need to create something quickly, I tend to go to Python. I’ve written a lot of Java. But I almost never write Java code outside of work.
One thing I liked about Java over Python, however, was ease of deployment. I can package all third party dependencies into a single executable jar, making it easy to upload and distribute artifacts. I have never mastered packaging Python for distribution.
August 19, 2019
I previously wrote about owning my own data. An
important part of data ownership is backing up your data. I use S3 as my long term data store. It is
pretty easy to set this up using Terraform.
S3
Provisioning a S3 bucket is simply a single Terraform resource:
resource "aws_s3_bucket" "repo_archive_log" {
acl = "log-delivery-write"
bucket = "example-bucket"
tags = {
Name = "example"
TTL = "persistent"
ManagedBy = "Terraform"
}
}
August 13, 2019
Lately, I have been writing more code outside of full-fleged IDEs and found myself
tweaking Emacs into a lightweight IDE for Go. Having gofmt
automagically formatting the
code and refreshing it in the buffer is simply lovely. My current go-mode
cusomization
looks like this:
First, get the excellent go-playground
package.
(package-install 'go-playround)
Then, configure Emacs
;; Automatically format your code on save
(add-hook 'before-save-hook 'gofmt-before-save)
;; Automatically display gofmt processed code in buffers
(custom-set-variables
'(global-auto-revert-mode t)
'(auto-revert-interval 1))
;; Verbose output when running tests via go-test-current-*
(setq go-test-args "-v")
October 17, 2021
In Chapter 1.3 of [Ball’s Writing an Interpreter in Go][1], we encounter one design decision of his Monkey programming language. Here, the lexer has a NextToken() method that looks like this:
func (l *Lexer) NextToken() token.Token { var tok token.Token switch l.ch { // [...] default: if isLetter(l.ch) { tok.Literal = l.readIdentifier() return tok } else { tok = newToken(token.ILLEGAL, l.ch) } } // [...] } This means the lexer itself does not do backtracking.
August 22, 2021
A lexer takes the source code, a sequence of characters, and group them into tokens. e.g., it makes the first decision on how to process the strings 100-10, -100-10, and -100--100 into groups. I’m going to call this grouping “tokenization” even though I may be misusing the term.
Tokenizing source code is hard. How should -100--100 be tokenized? Should it be a literal -100 followed by the minus token, followed by another -100?
July 29, 2021
Writing an Interpreter In Go by Thorsten Ball will be my personal introduction to writing an interpreter. I’ve never taken a comp sci class before, so I know nothing about compilers. On a lark, I decided to explore this area now, nearly 20 years after I started to learn computer programming.
If you are interested in this book as well, you might might the AST Explorer a useful companion.
I was told as some point in the past, that compilation can be broken down into four stages:
July 27, 2021
It happened. At the recommendation of https://twitter.com/dgryski, I bought Writing an Interpreter In Go. This will be my next hobby project. It’ll be interesting to see if I ever finish it.
May 19, 2020
It took me way to long to learn this. Your code (and their unit tests) should inject the system clock as a dependency.
An example, let’s say you have a service that writes a record to the database with the system clock.
public void save(String userName) { long currentTimeMs = System.currentTimeMillis(); User user = User.builder() .name(userName) .updateTimeMs(currentTimeMs); database.save(user); } How would you test this? You can inject a mock database instance and use it to verify that it got a User object.
July 9, 2022
My notes from Turn the Ship Around! A True Story of Turning Followers into Leaders.
Early in the book, Marquet tells a story of having failed to empower officers under his command. The story of being unable to “empower” stuck with me. It reminded me of experiences, earlier in my career, of failing to empower people reporting into me. On empowerment, Marquet said “Empowerment is not how I want to be managed.
February 7, 2020
One thing about job hopping is that you get to experience new perspectives on how people work. It forces you to reconsider what’s obvious. Take delegation for example. I used to think anyone with a bit of experience can do it effectively. It’s just about decomposing a system and assigning components to different people, right? It turns out effective delegation is much more nuanced.
Situational Leadership Situation Leadership is a model that ascribes different delegation styles based on the competency (skill) and commitment (motivation) of each team member.
December 22, 2020
One of the things that happen to engineers is that hard-working, productive engineers are often given leeway to make faux pas because of their contributions. Today, one of the engineers wrote on a public, widely distributed emails the following (paraphrased).
We suggested the aforementioned workaround to the customers. But since they cannot do it, we will have to do an emergency release instead.
There are two parts here. One, the engineer suggested a workaround that will quickly solve the customers.
August 17, 2020
I finished Managing Humans from Michael Lopp today. I knew of Lopp through “Rands Leadership”, the Slack community he created. I enjoyed learning from the people in the community and thought I’d pick up his book. I’m not sure what I expected going into the book. I think I expected tips and rules that I can follow. After trying to summarize the book, I think what I wanted and got was a set of mental models that I am happy to add to my toolbox.
September 21, 2020
Even an old dog like me learns something new every day.
Let’s say you need a program that receives a sequence of numbers and output the current average. How do you do this efficiently? The naive solution is to to keep track of two variables:
total # add up all numbers seen so far count # a count of how many numbers seen so far This way, at any step, you can calculate the current average using total/count.
Pagesbind Sometimes a synonym for “map” conflate combine disjoint separate, e.g., odd numbers and even numbers are disjoint disjunction inclusive or – if one of the inputs is True extrinsic not intrinsic federated Top-down delegation of responsibilities; Has a single point of failure at the top. PID controller control loop feedback mechanism e.g., curise control 99%ile Abbreviation of percentile EBNF Extended Backus-Naur Form Useful for defining the syntax of a programming language EBNF terminal a token/word/chunk in EBNF Alpha Αα Beta Ββ Gamma Γγ Delta Δδ Commonly denotes ‘difference’ Epsilon Εε Used in Greedy-Epsilon algo for multi-armed bandit problems Error margin in floating point comparisons.
April 3, 2021
In this part of the series, we’ll write some hands-on Temporal code and run it. Let’s start with our requirements:
You need to transmit a data packet. You can choose from multiple Route Providers to do this. Transmission takes time – you will be notified on a callback URL when the packet is delivered. Delivery may fail – either because the acknowledgement was not sent or arrived late (because Internet).
March 7, 2021
An increasingly distributed and fragile world Workflow platforms are important because software engineers are increasingly adopting distributed systems in their architecture. There are two reasons for this change: 1) Users are demanding more frequent releases, feature teams, better peformance, and higher availability; 2) Providers are increasingly moving away from “use our library” (Spring Framework) to “use our APIs” (AWS, Azure, and GCP).
This change is undoubtedly a good thing, however, it also introduces new problems.
February 28, 2021
Introduction It is hard to describe what a Workflow Platform is. It is both familiar and exotic. There are aspects of the problem space we all know well: Retries, eventual consistency, message processing semantics, visibility, heartbeating, and distributed processing to name a few. Yet, when they’re all put together in a pretty package with a bow tied on top, it becomes something almost magical. It feels like seeing the iPhone for the first time: Of course you want a touch screen on a cellphone and mobile internet access.
August 30, 2019
The default terminal on OS X isn’t really that great. It doesn’t let me reconfigure keybindings to my liking. There are two other terminal choices for OS X: Hyper and iTerm 2. When it comes to being customizable, I think Hyper wins. However, there are some really annoying things about it:
It is an Electron app, which means it is a memory hog. You cannot drag and manipulate tabs the way you can with native apps.
February 11, 2023
Once you know a programming language well, the process for learning a new language is not very hard. It is just time consuming. You need to read the documentation for basic syntax and flow control, get familiar with its idioms, memorize core parts of the standard libraries, and learn its tool chains. What can we do to speed up the learning process? One thing we can do is provide great examples in the documentation.
January 2, 2023
I had two weeks off at the end of 2022. Telesign closed its operations on the last week of 2022 to give employees well-deserved time off for a year of hardwork and I took another week off in addition to that. Like many technologists, I became captivated by OpenAI’s release of ChatGPT in 2022, and I spent a lot of the last two weeks exploring what OpenAI has to offer.
May 3, 2021
I used to favor automated integration testing. Now, I find myself walking away from it. I no longer find it worth the cost of setting up and maintaining such tests. I now rely mostly on unit testing.
First, I need to define what I meant by those terms. In context of this post, unit tests
In Wikipedia
unit test integration test automated, not always not specified ranging from entire ‘module’ to an individual function modules tested as a group depends on execution conditions and testing procedures depends on unit test/implies modules are already unit tested From Martin Fowler
October 16, 2020
This Feburary, I ordered a Dell XPS-13 Developer Edition. The Developer Edition is a line of Dell laptops that ships with certified Linux OS. It has been my programming powerhouse for the last eight months.
My first choice for a laptop was not Linux. Windows and macOS are simply more practical. Games and MS Office just works on Windows. Software support on macOS is generally good (except games), but it beats Windows with its underlying BSD architecture.
October 9, 2020
I loathe dynamic programming languages. This week, in a system that spans 3 microservices, I needed to add two new fields to an object. I’ve spent at least two days tracking down references to said object and making notes on all the functions that may be affected by this change. I wish I had a compiler to validate type information at function boundaries. But I don’t, because the microservices are written in weakly-typed (aka dynamic) languages.
Pagesbind Sometimes a synonym for “map” conflate combine disjoint separate, e.g., odd numbers and even numbers are disjoint disjunction inclusive or – if one of the inputs is True extrinsic not intrinsic federated Top-down delegation of responsibilities; Has a single point of failure at the top. PID controller control loop feedback mechanism e.g., curise control 99%ile Abbreviation of percentile EBNF Extended Backus-Naur Form Useful for defining the syntax of a programming language EBNF terminal a token/word/chunk in EBNF Alpha Αα Beta Ββ Gamma Γγ Delta Δδ Commonly denotes ‘difference’ Epsilon Εε Used in Greedy-Epsilon algo for multi-armed bandit problems Error margin in floating point comparisons.
August 1, 2020
As usual, LWN has a good write up on what’s going on in the Go community. This week’s discussion in on the new io/fs package. The Go team decided to use a Reddit thread to host the conversation about this draft design. LWN points out that posters raised the following concerns:
We added status logging by wrapping http.ResponseWriter, and now HTTP/2 push doesn’t work anymore, because our wrapper hides the Push method from the handlers downstream.
June 8, 2020
While writing a unit test for a functionality today, I ran into a dilemma. For a given API test, T, should I choose to cover code for request parsing, routing, and preparation, or should I choose to make it orthogonal to those concerns?
Choice A) Start a server at a free port and send a HTTP request to it from a HTTP client Choice B) Call the function with manually created HTTP objects and avoid going through HTTP
June 3, 2020
Cyclical dependencies Go disallows circular dependencies between packages.
In Java this is allowed:
package b; import a.A; public class B { public static void main(String[] args) { System.out.println("A.main"); A.doA(); } public static void doB() { System.out.println("B.doB"); } } --- package a; import b.B; public class A { public static void main(String[] args) { System.out.println("A.main"); B.doB(); } public static void doA() { System.out.println("A.doA"); } } Similar code is forbidden in Go. If you want to have test utilities, you often run into circular dependencies, leading to practices like https://golang.
May 19, 2020
It took me way to long to learn this. Your code (and their unit tests) should inject the system clock as a dependency.
An example, let’s say you have a service that writes a record to the database with the system clock.
public void save(String userName) { long currentTimeMs = System.currentTimeMillis(); User user = User.builder() .name(userName) .updateTimeMs(currentTimeMs); database.save(user); } How would you test this? You can inject a mock database instance and use it to verify that it got a User object.
May 17, 2020
Here’s a rough layout of how I organize my Go project. Some parts are situational and some parts are essential. I’ll go over both in this blog.
A rough layout:
+ basedir +-- go.mod (module jcheng.org) +-- hello (empty) +-- log/ +-- utils/ +-- config/ +-- models/ +-- repositories/ +-- services/ +-- cmd/ +-- hello_app/ +--/cmd/ +-- speak/ +-- email/ +-- sms/ The basedir Situational.
I have my (personal) projects in a monorepo.
February 27, 2020
Some past self version of me is saying, every class and function should be explicit about their dependencies, so that they are easily testable. John0 would say, “If you have a service that talks to a database, the database client should be an explicit dependency specified in the constructor. This makes the code easily testable.”
There is another version of myself from 10 minutes ago arguing it’s foolish to be explicit about everything.
January 4, 2020
There are two different ways to store configurations in the environment. One can choose to store a file name in an environment variable, or one can choose to use one environment variable per configuration. Take https://github.com/spf13/viper for example, the BindEnv() and related functions are designed to work with the one env var per configuration approach. The downside is that setting environment variables in the OS is tedious and requires flat/unstructured configurations.
November 12, 2020
https://rootsofprogress.org/immunization-from-inoculation-to-rna-vaccines
When you get your covid shot (probably in 2021), take a moment to think back on the 300 years of progress that got us to this point.
https://github.com/wbolster/emacs-python-black
This is an Emacs package to make it easy to reformat Python code using black, the uncompromising Python code formatter.
May 19, 2020
It took me way to long to learn this. Your code (and their unit tests) should inject the system clock as a dependency.
An example, let’s say you have a service that writes a record to the database with the system clock.
public void save(String userName) { long currentTimeMs = System.currentTimeMillis(); User user = User.builder() .name(userName) .updateTimeMs(currentTimeMs); database.save(user); } How would you test this? You can inject a mock database instance and use it to verify that it got a User object.
April 18, 2021
Lots of small things today.
History “Those who cannot remember the past are condemned to repeat it”. I love reading about how software came to be the way they are today.
Before we can talk about where generics are going, we first have to talk about where they are, and how they got there.
https://cr.openjdk.java.net/~briangoetz/erasure.html
Go Errors Error handling is still jacked in Go 1.16. That is, the formatting change is still not present.
May 26, 2020
I’ve been using mock/Gomock to write tests in my personal project. When you’re building something in a new language, it is hard to prioritize learning every tool in your toolchain. For me, I’ve been writing custom and suboptimal code for Gomock because of a nifty but undocumented API call .Do.
In many cases, I wan to match subsets of a complex object while ignoring irrelevant parts. e.g., verify a function is invoked with a list of User objects, but only verifying the email addresses.
December 9, 2022
Since its release in Nov 2022, ChatGPT has been making waves in the tech world. Its user-friendly interface has made GPT-3 accessible to the general public, and its capabilities have captured the imagination of many. More and more, people are beginning to ponder a future where AI-generated writing is commonplace.
Some of these ideas are shallow. The Atlantic has a guest essay titled “The End of High-School English” that discusses capabilities of ChatGPT but fails to make a compelling case for why English education should be changed and how it could be improved.
June 19, 2022
Bitch is a book from zoologist Lucy Cooke on correcting misunderstandings and cultural biases in our biological science. She explains, via animal studies, how existing notions of sex, male/female roles, and “what is natural” have been incomplete, if not incorrect.
In Bitch, Lucy goes through the behaviors of lemurs, meerkats, hyenas, moles, orcas, elephants, bonobos, termites, birds and fish to challenge conventional wisdom on nature and the roles of male and females.
PagesChaos theory When the present determines the future, but the approximate present does not approximately determine the future. - Edward Lorenz Code If you can’t write it down in English, you can’t code it - Peter Halpern, via Jon Bentley Prioritize There is no such thing as two equally urgent projects, only priorities that haven’t been made clear yet. - Unknown Regular expression Some people, when confronted with a problem, think “I know, I’ll use regular expressions.
May 17, 2022
This is a story from Neil DeGrasse Tyson’s StarTalk podcast. He talked about being on Brian Cox’s show and discussing the futures of space travel. Neil was saying that chemical rocket engines are not going to cut it and we need to look into things like wormholes and warp drives. Then Brian cuts in and explains that wormholes are fundamentally unstable and they won’t work.
Brian was absolutely correct, but that was not the point.
January 3, 2022
The Earth is approximately 147 million km from the Sun. It is a tiny thing. You can fit 1,300 Earths into Jupiter. Jupiter, you think, must be huge.
The diameter of Jupiter is 140 thousand km. This means you can line up 1050 Jupiters back to back between the Earth and the Sun. As big as Jupiter is, it is still less than 1% of the distance from the Sun to the Earth.
September 14, 2021
Staff Plus Live 2021 was a virtual conference held by LeadDev.com on Sept 14, 2021. I believe this is their first conference aimed at Staff+ Engineers. Loosely defined, Staff+ are high-impacting engineers whose success is felt across the company. In other words, these are engineers who creates high leverage. I was able to attend this year’s conference and learned a lot from it. I started this post to write down what resonated with me before I forget about them.
August 29, 2021
Just the act of measuring something can change outcomes. I love the reference to Jespen.
https://danluu.com/why-benchmark/
July 25, 2021
Back from a long vacation. This week, we have folk wisdom on visual programming
https://drossbucket.com/2021/06/30/hacker-news-folk-wisdom-on-visual-programming/
June 3, 2021
Humans and incentives, and why some metrics (or objectives and key results) should not be public.
http://rachelbythebay.com/w/2021/06/01/count/
May 29, 2021
Systemd, the good parts
https://lobste.rs/s/po98o2/systemd_good_parts
May 16, 2021
My thoughts today led me to reading about nuclear wastes. It turns out that what we call “nuclear waste” is a pretty vague term.
A light-water reactor generates different kind of “waste” from a molten salt reactor. A traditional light-water reactor doesn’t consume fuel efficiently. It leaves behing partially consumed fuel that is not economically attractive to refine for further use. These partially spent rods continue to generate heat and are sometimes stored in cooling pools.
May 4, 2021
Grammar visualizer
https://dundalek.com/grammkit/
Which leads to a JS parser generator https://pegjs.org/online
And also leads to a JS parser generator with a visual debugger https://ohmlang.github.io/editor/
This also prompts my interest into a graphviz/dot parser
https://github.com/awalterschulze/gographviz
Which uses this Go parser generator
https://github.com/goccmack/gocc
This exploration also led me to this Go parser generator
https://github.com/alecthomas/participle
April 1, 2021
I spent a couple of hours evaluating 3rd party libraries. What have I learned? For me, there’s one clear winner in a small field of candidates.
Presently, these are the top hits for “golang gauge counter timer”.
https://pkg.go.dev/github.com/go-kit/kit/metrics https://pkg.go.dev/github.com/facebookgo/metrics https://github.com/uber-go/tally The first result is go-kit. Go-kit isn’t a metrics library. Rather, it bills itself as a “framework for building microservices.” Its metrics package is simply a set of interfaces.
March 24, 2021
Go does not allow cyclic imports. A solution is to create a “shared” package to hold interfaces that related packages all reference. This, for some reason, reminds of me join tables in SQL.
Here is an example of a typical Go project. Packages toward the bottom, e.g., “common/persistence”, allow different packages to work with each other without introducing cyclic dependencies. For this project, “log” can be referenced by “config”, but cannot use “config” to conifgure itself.
March 8, 2021
Oldie but goodie. Go concurrency patterns
https://drive.google.com/file/d/1nPdvhB0PutEJzdCq5ms6UI58dp50fcAN/view
March 7, 2021
Two book recommendations
https://www.oreilly.com/library/view/designing-data-intensive-applications/9781491903063/ https://www.oreilly.com/library/view/making-software/9780596808310/ Designing Data Intensive Applications: Don’t let the name fool you. The knowledge in this book applies to more than just data processing applications but to distributed systems in general. It is a great book for all software architects.
Making Software: What Really Works, and Why We Believe It: A meta-analysis of various theories on software development processes. Is TDD effective? Is Agile just a hype or is it just misused?
February 22, 2021
The Peseverance rover lands on Mars. In this month, the UAE, PRC, and US all sent scientific instruments to Mars.
https://www.nytimes.com/2021/02/18/science/nasa-peseverance-mars-landing.html
January 31, 2021
TextRank identifies connections between various entities in a text, and implements the concept of recommendation. A text unit recommends other related text units, and the strength of the recommendation is recursively computed based on the importance of the units making the recommendation. In the process of identifying important sentences in a text, a sentence recommends another sentence that addresses similar concepts as being useful for the overall understanding of the text
January 22, 2021
This blog is such a great example of why it is difficult to creat great software. So often you have to make impossible choices between security and backward-compatibility.
Today’s Go security release fixes an issue involving PATH lookups in untrusted directories that can lead to remote execution during the go get command. We expect people to have questions about what exactly this means and whether they might have issues in their own programs.
January 6, 2021
Sascha Chua is a great resource on Emacs-y things
https://sachachua.com/blog/
January 5, 2021
Maybe Emacs doesn’t need to be a fusion reactor. I only hope it continues to generate energy for many years to come.
It just needs volunteers to keep the fire going.
https://www.murilopereira.com/how-to-open-a-file-in-emacs/
December 22, 2020
Replicating a database can make our applications faster and increase our tolerance to failures, but there are a lot of different options available and each one comes with a price tag. It’s hard to make the right choice if we do not understand how the tools we are using work, and what are the guarantees they provide (or, more importantly, do not provide), and that’s what I want to explore here.
December 13, 2020
Concept: Poison pill
One strategy is a poison pill: a special message on the queue that signals the consumer of that message to end its work. To shut down the squarer, since its input messages are merely integers, we would have to choose a magic poison integer (everyone knows the square of 0 is 0 right? no one will need to ask for the square of 0…) or use null (don’t use null).
November 24, 2020
Meet GPT-3. It Has Learned to Code (and Blog and Argue).
For many artificial intelligence researchers, it is an unexpected step toward machines that can understand the vagaries of human language — and perhaps even tackle other human skills.
November 12, 2020
https://rootsofprogress.org/immunization-from-inoculation-to-rna-vaccines
When you get your covid shot (probably in 2021), take a moment to think back on the 300 years of progress that got us to this point.
https://github.com/wbolster/emacs-python-black
This is an Emacs package to make it easy to reformat Python code using black, the uncompromising Python code formatter.
October 22, 2020
What are your favorite CLI apps?
I’m looking for CLI utilities that are definitely not part of the POSIX required or optional utilities, and more coloquiallly not considered to be standard BSD or *nix fare.
The Penderwicks
My daughters couldn’t stop lauging during storytime. They actually enjoy bedtime now. Birdsall is an excellent writer.
Just write the praser
This is a whirlwind tour of writing parsers by hand.
October 20, 2020
I recently participated in 2020 Emacs User Survey. One of the questions asked is “When you were first learning Emacs, what did you find difficult to learn?” The obvious answer is keyboard shortcuts, e.g., instead of CTRL-S for save, it is CTRL-X CTRL-S. Instead, CTRL-S performs find, which is usually mapped to CTRL-F, and so on and so forth.
Why Emacs is hard for new users There were other problems too.
October 19, 2020
I recently got a Logitec Razer Kiyo for my Zoom meetings. Currently, I need to use it on on Linux Laptop, and it works rather fine. I was skeptical that it would “just work” on Linux, but it did! There is also a software package named v4l-utils that allows you to configure the zoom (crop) level of your video, which is nice for cutting out undesirable background.
apt-get install v4l-utils You can get a listing of attached cameras with
October 16, 2020
How to hire for your organization
A three-part series from 9/21/20 to 10/5/20 on how to hire for your organization.
The Tempral Workflow Framework
Let’s look at a use case. A customer signs up for an application with a trial period. After the period, if the customer has not cancelled, he should be charged once a month for the renewal. The customer has to be notified by email about the charges and should be able to cancel the subscription at any time.
October 16, 2020
This Feburary, I ordered a Dell XPS-13 Developer Edition. The Developer Edition is a line of Dell laptops that ships with certified Linux OS. It has been my programming powerhouse for the last eight months.
My first choice for a laptop was not Linux. Windows and macOS are simply more practical. Games and MS Office just works on Windows. Software support on macOS is generally good (except games), but it beats Windows with its underlying BSD architecture.
October 8, 2020
The Ultimate Guide to GPT3 from Twilio
A step-by-step walk through of what it is like to the the GUI to GPT3 from OpenAI
A Columnist Makes Sense of Wall Stree Like None Other (See Footnote)
Mr. Levine wasn’t always a darling of business media and finance Twitter. (The best measure of his audience’s devotion may not be his 112,000 Twitter followers, but rather the 3,000 that follow @MattLevineBot, a fan account describing itself as a bot that mimics his writing style.
September 21, 2020
Software engineers find it natural to talk about abstractions. We have ideas such as Decorators, Model-View-Controller, and Message Queues. These abstractions allow software engineers to talk to each other using our own rich and succint language. Abstractions, however, is not unique to engineers. In my role as a parent and an American citizen, I am constantly confronted with new abstract ideas arising out of life.
The abstractions I am referring to are new words and ideas coming out of our shared culture.
September 2, 2020
The Empathy Gap from Effectiviology.com
For example, if a person is currently feeling calm, the empathy gap can cause them to struggle to predict how they will act when they’re angry. Similarly, if a person who is on a diet is currently full, the empathy gap can cause them to struggle to assess how well they will be able to handle the temptation to eat when they’re hungry.
August 8, 2020
Something different today. I made a workbench. It took me the whole day and I made a lot of mistakes. But I also learned a lot.
I have a Dewalt tablesaw. It handles small pieces of lumber fine. But trying to rip a piece of two-by-six using the built-in guide was impossible. It was simply too wobbly for working with large pieces. I’ll probably have to build some sort of workbench to hold the tablesaw, as well as a larger guide to really make sure I can get perfect rips.