- March 23rd, 2021
var totalSalesTax = orderTotal * percentSalesTax
is better than var tST = oT * pST
XYZControllerForEfficientHandlingOfStrings
and XYZControllerForEfficientStorageOfStrings
These are both very descriptive names, but if they are used in conjunction with one another, it could be very easy to confuse the two. Human-readable doesn’t just mean a long name.- March 2nd, 2021
This past week I have been developing a command-line todo app. This app is one of my first forays in using Test Driven Development in a “production” environment. Before any commands go into the command line, I set out to write a decent suite of tests that will dictate where my application would go and what it would ultimately be capable of. This new way of developing is a difficult change of pace, but I am learning to love it. In my previous jobs, there has always been a multi-step process for how to accomplish a task, with little deviation. Since getting into programming, I have felt like there is rarely an exact step-by-step process for anything and it has felt overwhelming at times. The TDD approach brings back a bit of that feeling of step-by-step processes. Instead of feeling like I need to develop this huge, nebulous project, I am only having to deal with bite-sized functions that have 1 purpose. A much less anxiety-inducing task.
While this has been a great revelation, it hasn’t all been rainbows and butterflies. I tried to get creative with my tests and decided to test whether the returning message in the console had color. Adding color to the node console doesn’t come built-in, so I added the chalk package to my project. The test started as follows:
test(“should return a colorful message”, () => {})
function colorTodo(todo) { return chalk.green(todo) }
const chalk = require('chalk')
test('should return a colorful message', () => { chalk.green = jest.fn() })
const chalk = require('chalk') test('should return a colorful message', () => { chalk.green = jest.fn() const todo = 'This message looks cool!' colorTodo(todo) expect(chalk.green).toHaveBeenCalledTimes(1) })const chalk = require(‘chalk’) function colorTodo(todo) { return chalk.green(todo) }
- February 11th, 2021
Testing. That word brings up 2 very different feelings for me. On one hand, when I open up a project with a nicely fleshed out test suite, I am very excited. I don't have to wonder what works and what doesn't! Fully green tests gives me a greater level of confidence that my fix isn't going to bring the app crashing down when I push to production. What a great feeling!
On the other hand, the thought of writing quality tests, fills me with absolute dread. I feel like I can barely write quality production code! What makes me think that I can write quality tests that checks my code?! Deep Breath ...Let's talk about tests and what I'm learning.
I am currently apprenticing with Enok Collective and I love it. The company as a whole is a quality organization. My mentor and I identified some of the areas of my work that could use the most work and would give the most return. I chose testing as a skill that would give me the most benefits starting out. I've been in software for 2 years at this point, and testing has been a part of every job I've worked at. But 2 years in, I still get queasy about the idea of writing a test for my flimsy code (notice, I always write my tests after my code...[more on that later]). Enok strives for Test Driven Development (TDD) in all of the work that they do. TDD is just what it says it is: software development that starts with and is driven by testing. This means starting with testing. Starting with testing is a huge mind shift for me. Testing has always been a secondary priority. If I have time, I will throw in a single test and call it a day. With this being my mindset, my code has suffered and I am constantly concerned about the next feature that might break my fragile code and force me to rewrite it.
This past week I have started a deep dive into best practices of testing and I am attempting to elevate my tests to be "first-class citizens". Here are the resources that I have taken advantage of:
- May 3rd, 2019
slack.rb
. I used the following gems:slack-ruby-bot
--This gem is crucial to the success of the app as it is what connects the app and Slackxbox-api
--Xbox Doesn't have a Ruby specific API implementation. They do have a C++ implementation for all you C++ folk out there. I used the Unofficial Xbox API provided by Alan Wynn. The docs are great and he provides different implementations for Python and Ruby.
json
--JSON is pretty critical when hitting most API's and this gem allows Ruby and JSON to play nice together.dotenv
--Last but not least, I used dotenv to hide my Slack and Xbox Api keys.bundle install
in your terminal to populate your Gemfile.lock
file. External set up will require you to get an API key from both Slack and Xbox API. Both keys are fairly straight forward processes.slack.rb
file. It's important to require all of your gems at the top of your file so that Ruby knows what to import. I then make my class an instance of the Slack Ruby Bot. After that, I put my api key into a variable named 'client', and I use 'client' as I set up variables for all of my friends. Once those are setup, it's time for the Slack implementation. Slack uses a function called 'command' to provide functionality. This can all be explained much more thoroughly in the Slack Ruby Bot README. I used the word 'pong' as my Slack keyword for my bot. This keyword will put the bot in motion to go fetch the data and you can change it to whatever keyword you want.JSON.generate
on each of those new variables and set this to another variable. I then call JSON.parse
and now I'm in JSON land and I can pull out the data of what they are doing right now. An if
statement determines what will be printed to Slack, dependent on the player data. After this, save everything, and move over to your terminal and cd
into the project. Once you're there, run the following script: SLACK_API_TOKEN={SLACK API KEY} bundle exec ruby slack.rb