Notes for Week 29 of 2020

Saturday, July 25, 2020, 9:29:44PM

TIL that https://cypress.io is a thing for testing JavaScript. Looks promising. Need to take a look at it.

Saturday, July 25, 2020, 3:51:38PM

Recently I was reminded how easy it can be to accidentally defeat the entire point of using sustainable interfaces instead of structs — especially if you are creating an internal struct that implements the interface as the same time that you are designing the interface.

Here’s a method I had initially created correctly, but didn’t catch the very obvious mistake until later.

func (n *node) AppendChild(c Node) {
    if n.c1 == nil {
    c.(*node).mum = n  // DOH!
        n.c1 = c
        n.cN = c
        return
    }
    n.cN.AppendAfterSelf(c)
}

Casting the incoming Node c into a *node is a whopping error because it forces all Nodes past to it to also be *node* pointers. But that goes against the entire point of interfaces. I should be able to pass anything that fulfills the Node interface and obviously something else might be different.

Here’s how I corrected it to work with any Node, not just my own specific implementation:

func (n *node) AppendChild(c Node) {
    if n.c1 == nil {
        c.SetParent(n)
        n.SetFirstChild(c)
        n.SetLastChild(c)
        return
    }
    n.cN.AppendAfterSelf(c)
}

Friday, July 24, 2020, 8:18:26PM

Turns out it is way too verbose. To me the tests are the best way for someone to get acquainted with your code base. If you mess that up with something like following boilerplate created with gotests you lose the value of communicating what your package is about and how it works. In fact, this just makes me want to use Example* more than Test* even more. Everything becomes a part of the documentation and you are writing it from the perspective of someone using it.

Friday, July 24, 2020, 7:30:01PM

Looks like exists already! I am so seriously blown away by this and it has been around for a very long time. It even has test template support with testify templates as an option.

go get -u github.com/cweill/gotests/...
go --all -w node.go

Friday, July 24, 2020, 7:24:21PM

It occurred to me that creating a tool to stub test cases would be relatively easy just by walking the Go AST and matching the lowercase file name with the specific interface or struct (assuming you use that convention and they match).

Friday, July 24, 2020, 6:41:57PM

Realized there is real value in having two scripts directories in your path, one for the good stuff in dotfiles that you can show off publicly to others and another for all the quick and dirty shit that needs to me made into something better eventually. Here’s what they look like in mine:

export PATH=\
SCRIPTS:\
SCRIPT_PRIV:\
...

(Of course there is a lot more in that path after that.)

Friday, July 24, 2020, 6:27:50PM

I really need to find or make a tool that creates test case boilerplate code for everything in a matching _test.go file.

After make a note command for like the 10th time I am realizing how much I really need to fucking finish kn. I would use it ever five minutes. It must be made!

Thursday, July 23, 2020, 4:58:59PM

I’m having a really hard time with the overwhelming level of laziness in the mainstream population — particularly among the highly gifted who could be doing so much more for the world. Don’t know why it’s hitting me so hard today. People constantly complain about now having enough time for this or that when in fact that have gobs of time that they are choosing to waste on absolutely stupid shit. At least I will be able to eventually die with a clean conscious that I worked my fucking ass off to make the world — and everyone’s lives in it — just a little bit better.

Tuesday, July 21, 2020, 3:47:47PM

TIL that Golang used reflection to implement the “built in” unmarshalling. That means no one should ever use it of they actually care about the performance of their JSON parsing. Instead, I will always implement UnmarshalJSON myself to ensure stuff gets where it needs to be as fast as possible without reflection. Seriously, reflection is pretty damn close to the devil.

Monday, July 20, 2020, 8:37:16AM

As I wrap up the PEGn.pegn spec I realized how much incredible value this has for helping people learn different language syntaxes. The power comes from a drop-dead simple representation of a language syntax that most people can understand simply by looking at it with no further explanation. By having people learn language syntax by studying a PEGn grammar they can immediately apply their own internal syntax checkers when writing one.

This doesn’t even touch how easy it is to excite someone into writing their own language once they see how easy PEG grammars are to write. The processing of logic in PEG makes for good logical (“computational”) thinking as well.

One of my new goals for the community is to have people write PEGn grammars for all the major languages. Having a database of PEGn files for all languages is such a huge win in terms of understanding different languages and being able to create your own.