November 28, 2018
Today started with the morning kata working in which we where asked to count the number of vowels in a string. The solution could be a one-liner const vowelCount = word => (word.match(/[aeiou]/g) || []).length;.
But we made it much longer and easier understand by using explicit definitions,
const vowelCount = (word) => {
const vowelRegexp = /[aeiou]/g;
const arrayOfVowelsOrNull = word.match(vowelRegexp);
if(arrayOfVowelsOrNull === null) { return 0 }
return arrayOfVowelsOrNull.length;
}
This could be refactored to
const vowelCount = (word) => {
const vowelRegexp = /[aeiou]/g;
const arrayOfVowels = word.match(vowelRegexp) || [];
return arrayOfVowelsOrNull.length;
}
There’s not much difference, aside from removing the for an if statement, there could also be some sort of method to check that a parameter has been given and that it’s a string but we never got to testing those situations.
After the we had cake, then I sat with in the datahub for a while and tried to figure out what the best way to approach project logfind from learn-c-the-hard-way, figuring out how to use or write an test framework similar to some of that JavaScript frame works I have used would take up an inordinate amount of time compared to using the debugging macros that I have been using as I progressed through the book. So I got started by writing a change log and doing the very minimal I could to progresses the program in the right direction, which was checking arguments have been given to the function, and then testing if it had opened the configuration file. During this one of the devops engineers let me use marathon marathon to delete a mesos application instance that was no longer required.
Then I took some time to install the nix package manager on my machine, which shouldn’t break anything as nix installs packages into a dedicated store, so I don’t have to worry about conflicts that can occur when using multiple package managers. Now I just have to think of something to do with nix…
Soon after installing nix I was invited to do some property based testing with my co-apprentice Lewis and Sergii, which after a short exercise in getting jsverify to work we started to discuss the uses of property tests, as an example we looked at functional JavaScript library folktale that has lots of property based testing in the source code.
Then to finish the day, I read the second chapter of the clean coder ”saying no”, which was mostly stories about when saying no to excessive work loads then negotiating more reasonable exceptions would have been a much better situation to be in… :/
Written by Marc McIntosh Find him on github