TDD with JavaScript

Do you love books? I LOVE BOOKS. I just got this one in the mail and I can’t wait to spend my evenings with it for the next few months!

A book written by Christian Johansen
Time for some fun!

Do I sound nerdy to you? (It’s because I am.) I can never get enough of learning. This has been a really difficult part of being a developer for me, because I’m interested in so many things, plus I have zero patience, so I try to study multiple things at once. You can imagine how this works out for someone with unmedicated ADD. After months of trying to balance learning a new language at work with studying other things in my ‘spare’ time (hardee har har), I decided to take a couple of weeks off and see if there was one thing that would rise to the top – one thing I wanted to learn more than the others.

Now, take note of that word, ‘wanted.’ This is another difficult thing for me, because I like to make the practical decision, the responsible decision, the decision that will lead to better employment/more money/good stability for my family. Often this does not correlate with what I actually want to do. All you adults out there feel me. But over the last few months I’ve realized that if I’m going to find the motivation or energy for extra learning after a full day of work, it’s got to be something I actually want to know more about. Enter this book.

Here’s what I know about TDD:

1) TDD is something that needs to be done, should be done, and often isn’t done.

2) Every time I’ve paired with someone on it, I’ve felt so clueless I wanted to cry.

3) Every time I’ve paired with someone on it, I’ve thought, “This stuff makes me a better developer.”

That’s about it. So TDD it is. I’d like to commit myself to a post a week about what I learn, but I’m already overextended so nah. (But maybe.)

I’ve been a developer for six weeks. Here are the code school skills I actually use.

In December 2016 I finished the Front-End Engineering program at The Iron Yard in Salt Lake City. In January I was offered a job and in February I started that job. So what did I learn in bootcamp that’s helped me daily?

How to read code

I used to beat myself up constantly for being able to read code and understand what it’s doing, but not being able to write it myself. And then I got a job at a place with multiple giant codebases and it turns out that reading code and understanding it is the more important thing (at least right now – I was here four weeks before I needed to write anything from scratch). Every week I’m introduced to a new thing at work, and lo and behold, all that practice I got reading code during school comes in handy again.

How to focus among a gazillion distractions

Write/read/test code while groups chat and laugh five feet away and there are Nerf gun torpedoes being shot at my head and some delicious smell is coming from the nearby kitchen? Yes, yes I can. In school we were encouraged to spend our afternoon lab time together, so I quickly developed the ability to be in a small area with a bunch of people and a lot of talking and interruptions, and still stay on task. At my previous job, I often had to use earbuds and brown noise to block everything out – now I don’t even notice it.

How to learn

I’ve always been a capable student and never had a problem learning things. But with bootcamps, it’s a firehose of information, and this job has been no different – learning in this kind of environment is a beast. The brain has to quickly filter through the hundreds of things being thrown at it, decide what’s most important and useful, grab onto those varying pieces of information, and then plug them in where needed hours or days or weeks later. I was able to practice this at The Iron Yard for twelve straight weeks and it has paid off immensely.

How to ask questions

Part of our pre-bootcamp coursework was to watch this talk on getting technical help. You should definitely check it out. Asking for help is complicated in our field. Knowing what information I need to convey to my team and how to communicate it succinctly, quickly, and in a way that gets the most helpful answer is something I work on daily – if I hadn’t spent so much time practicing it at The Iron Yard, my first weeks here would have been much worse.

How to ride the emotional rollercoaster of dev work

You caught that, right? What I said about it being worse? It implies those first weeks on the job were bad, and they were. If you’ve read my posts, you know that I almost quit in week 3 of bootcamp. Every week was so full of ups and downs that I could oscillate between wanting to quit and knowing I’d made the right career change decision four times a day! And so when I wanted to walk out of this job in week three and never return, I knew enough to ride it out. When I’m feeling especially stupid (happens often), I know that I just need to give it time and I’ll get it.

How to talk to complete strangers

Not only were we encouraged to go to meetups all over Salt Lake City, we were often thrown into on-campus networking events with little notice, or required to pair with people we didn’t know at all. The result? I can approach anyone at my job or at meetups, and I can successfully pair with any teammate. I know this isn’t a big deal to plenty of folks, but this was a skill I did not have before The Iron Yard, and it’s been huge for me.

* * * * *

I can’t be the only bootcamp grad whose first job uses a different language than the one studied in school, and I’m so glad I can still get some ROI for my $25,000 (tuition plus three months of not working). So, my advice to anyone attending or considering code school — spend as much time focusing on the soft skills as you do on the actual code. It’ll pay off.

Console.log is my friend (yours, too)

I don’t get to use a lot of JavaScript at this point in my new job, so to keep up on my JS skillz I spend some of my weekend time practicing old things or learning new things. Right now I’m learning Node. And while reading some code for a basic Express server, I was reminded of the lovely thing that is console.log.

Here’s the code:


var express = require('express')
var app = express()

var jsonData = {count: 12, message: 'hey'}

app.get('/', function(req, res){
  res.sendFile(__dirname + '/index.html', function(err) {
    if (err) {
      res.status(500).send(err)
    }
  })
})

app.get('/data', function(req, res) {
  res.json(jsonData)
});

var port = 3000
app.listen(port, function(){
  console.log('listening on http://localhost:', port)
})

I can see the code is pulling in Express, that it’s declaring a jsonData variable and assigning an object to it, that the get method will call one of two functions depending on the path that’s being requested, and that the listen method will show me what’s happening on my localhost:3000. And I can see those two get functions are going to use req and res, and I can see what happens with res…but what about req? I figure it’s the request coming in, but I have this need to know what all parts of all things look like, so how do I find out? Put a console.log in those functions, of course! It’s about a gazillion lines of data so I won’t repost it all here but at the very bottom, I see something like this for the first get function when I ask for the root path(‘/’):


route: Route { path: '/', stack: [ [Object] ], methods: { get: true } } }

And something like this for the second get function when I ask for the data path (‘/data’):


route: Route { path: '/data', stack: [ [Object] ], methods: { get: true } } }

Doing things like this helps the code make more sense in my brain. While I understood that the functions were taking in requests and returning responses, now I can see what the requests actually look like and I can see how the functions are seeing the path. Yay!

Flex-basis, flex-grow, & flex-shrink

Flex-basis, flex-grow, and flex-shrink are three Flexbox properties that can make things easier when dealing with responsive design. So what’s the difference between them? Let’s take a look at some code and find out!

Flex-basis is how much space we want our element taking up in an ideal world, before we start addressing extra space or less space. So in this instance, we want each of these divs to be 100px wide.

.div1 {
  flex-basis: 100px;
}

.div2 {
  flex-basis: 100px;
}

Now, when we’re viewing these two divs in any browser wider than 200px, there’s going to be some leftover whitespace. Flex-grow helps us decide how we want to divvy up any extra whitespace between our elements. So, as whitespace expands, div1 will take up twice as much of it as div2:

.div1 {
  flex-basis: 100px;
  flex-grow: 2;
}

.div2 {
  flex-basis: 100px;
  flex-grow: 1;
}

Flex-shrink helps us decide how we want our elements to behave as space decreases. In this case, we want div2 to shrink twice as much as div1:

.div1 {
  flex-basis: 100px;
  flex-grow: 2;
  flex-shrink: 1;
}

.div2 {
  flex-basis: 100px;
  flex-grow: 1;
  flex-shrink: 2;
}

To make it much more concise, we can re-write our code like this:

.div1 {
  flex: 2 1 100px;
}

.div2 {
  flex: 1 2 100px;
}

I hope that helps make sense of these three properties. If you want to learn more about Flexbox, you can’t go wrong with Wes Bos’ free series.

On object manipulation in JavaScript

Honesty is important to me, even when it means coming clean about things I struggle with. Today, I confess that I struggle with comprehending object manipulation in JavaScript. Earlier this morning I was pairing with a friend on some katas in Code Wars, and I was struggling to understand what was happening with this code:

let staff = {
  tim: 'finance',
  jim: 'accounts',
  randy: 'canteen'
}

function boredom(staff) {
  var map = {
    accounts: 1,
    finance: 2,
    canteen: 10
 }

  var score = Object.keys(staff).reduce((a, b) => {
    return a + map[staff[b]]
  }, 0)

  return score <= 13 ? 'kill me now' : 'party time!!'
}

As you can see, boredom is taking in the staff object, where it wants to match up the staff values with the corresponding numbers in the map object, then tally the numbers to produce a score and return that score’s relevant string. So theoretically I understood all that, but not this specific part:

map[staff[b]]

My brain was reading it like this…

map.staff.b

…which is sort of right, but also why I was getting confused.
I mean, map and staff are two separate objects, not connected in any way, so how is that working? Let’s walk through it! And by let’s I mean me, so I can solidify my understanding 🙂

Alright, so the first time through, a is 0 and b is ‘tim.’ Which means map[staff[b]] is basically map['tim']. And what’s Tim’s value? It’s finance. Since Tim’s value is ‘finance,’ map['tim'] is basically map.finance. And what is map.finance? That’s right, it’s 2! So the first time through, 2 gets added to 0, and on the next time through 2 becomes a, and b is now ‘jim,’ and on and on until the numbers are reduced down and boredom spits out how you feel about your office’s fun level.

Check out the reduce method on MDN.

Find out more about objects in Eloquent JavaScript.

And don’t forget, you can walk through code step-by-step on this site.

Thoughts from week 5 of coding bootcamp

Early in week 4 I’d wanted to quit for at least the 10th time; things got better after that. I don’t think it was because the material became easier or my brain suddenly understood everything – rather, I finally realized I am doing all I am capable of and there’s little sense in beating myself up over incomplete or not-up-to-my-standards homework. There is literally nothing more I can do. I barely see my family, my TV time is limited to Sunday evening’s Westworld, I haven’t gone to a movie or out with friends in who knows how long, I’m not doing the cleaning or the laundry or the cooking or the grocery shopping – all I am doing is bootcamp stuff!

And while my brain isn’t necessarily understanding things completely, it is beginning to grasp how all the pieces fit together and that’s making me feel a little less like drowning and more like (mostly) keeping my head (halfway) out of the water. I am still struggling with the execution of JavaScript itself, but conceptually I’m having no difficulties comprehending things like this, objects, constructors, or prototypes. We’re also dealing with Webpack this week and that’s been fun and interesting. If given the chance, I will still spend 10 hours of an assignment on the logic itself and maybe a half hour on styling and I don’t expect that to change anytime soon. JavaScript is just too interesting 🙂

Let’s learn about objects and this

No really, let’s. Because I’ve learned this already, but I need all the reviewing I can get. This should take 6-8 hours.

First, watch these videos by one of my very favorite JS resources, Mattias P. Johansson. (And later on, find time to watch all his other videos – he’s highly entertaining, very human, and also super nice on social media.) No need to code along.

Then read chapters 1 and 2 of this book by another one of my favorites, Kyle Simpson. You may, like me, feel both dumber and smarter after reading Kyle’s material, but that’s okay – he knows his stuff and it’ll be worth it. I like to code along with the examples Kyle provides, but you don’t have to.

Now, code along with Mary while she makes a fun little game. She moves fast and you may have to stop the video every few minutes to catch up. After you’ve got all your code written and working, watch the video again while adding comments to your code about what every single thing is and what it’s doing. You’ll learn more in this second run-through than you could catch in the first, trust me.

There, now you’re an expert! Okay, not really – but you learned some stuff, right? BOOM.

Thoughts from week 4 of coding bootcamp

Oof. Week 4 of bootcamp was tough. Tuesday morning found me feeling very down on the way to school. I wanted to quit. The day before, we’d been given an assignment using APIs, and I couldn’t get one small part of mine figured out. The issue wasn’t even getting the Ajax call to work – it was getting down into the right level of each object as I pushed them to the DOM in a table. This is the story of my JavaScripting life: knowing conceptually what I need to do and knowing how to do it, but missing one tiny piece of the puzzle. Terribly frustrating! But by Tuesday afternoon I’d solved my problem and was feeling good about the world. This lasted until Saturday, when I went to my third meetup of the week, and it all came crashing down again.

I’d wanted to quit in week 3, too. Actually, if I don’t want to quit at least 3 times in a week, I consider it a good week. Before bootcamp started, I had naive worries about the schedule, my class, the location. I never suspected the real battle would be convincing myself to keep going back. Every. Single. Day. Don’t get me wrong – I absolutely adore my classmates, our instructor, the campus director…everything about The Iron Yard, really – but it is hard to get a third of the way into this and still feel like I know basically nothing. Every day I feel like I am repeatedly throwing myself against a brick wall, with naught to show for it but a mutilated sense of self-worth.

(Pretty dramatic, right? I know.)

I’m trying to trust that this isn’t reality. That my brain is absorbing the things it needs to, and it’s all going to come together eventually. I asked a local Iron Yard alumni if she ever stopped feeling like she didn’t know anything, and she said it was in week 11 of 12. 7 weeks away. If you find yourself experiencing this during coding bootcamp, you’ll want to know how to hang on until then. Here’s what’s working for me so far.

Trust your instructor. So many times I’ve felt behind and didn’t want to do the morning exercises from our instructor; I’d want to read up on things to fill in the holes in my learning. But two days later, I would find myself relying on what I had learned during the morning exercises. Even when it’s frustrating, go with it!

Look back over your notes from previous weeks of class. Do you need those notes anymore? No, because you know that stuff by heart now. Tell yourself that in the future you won’t need the notes you’re relying on today. You will make progress!

Immerse yourself! You might as well, right? Read a JS book on the train, listen to a JS podcast on the walk, read JS blog posts in the morning with your coffee. Right before I go to bed, I like to give my brain one last concept to play with while I’m sleeping. The JS dreams are getting exhausting, it’s true – but if it helps me learn, I’m willing to deal with it.

Go to meetups for rejuvenation and inspiration!! I’ve mentioned that I’m terrified of meetups, but I go anyway – because no matter how bad my day has been, I always come away feeling amazing. Even the meetup on Saturday, which I felt woefully unprepared for and almost walked out of halfway through, reminded me that hey, I may not know anything yet, but JavaScript is still completely fascinating to me and I am on the right path.

It is so much info. Your brain is processing it whether you realize it or not. Hang in there. You can do it!

JavaScript thoroughly. JavaScript and repeat.

An image of a JavaScript book by Kyle Simpson.
A fantastic book series I read on the train to and from school every day.

This won’t be a ‘thoughts from week 3 of bootcamp’ post, because I have no thoughts left in my head.

There is only JavaScript.

If the thing I’m trying to think about is not JavaScript, my brain is just not interested, thank you very much.

The hour-long journey to and from campus every day has become a blur. Some days I cannot remember if I walked the final two miles or took Trax. Spans of time the length of entire workdays pass without me noticing. A couple of nights ago Dustin came home from work to find me sitting in the dark with my MacBook, not having bothered to turn a single light on during the past 5 hours because hey, not JavaScript. I misplaced my phone four times between heading upstairs for bed and actually getting into bed. One evening I was water-flossing while mulling over my code when my brain developed a solution, and I walked straight to my computer to write the code, accidentally leaving the WaterPik on – full and running.

My brain is only interested in JavaScript even when it’s supposed to be sleeping. I wake up multiple times a night to find it tossing around coding assignments in an infinite loop. I imagine what it must be like for my loved ones right now: They talk to a blank-faced robot about their daily struggles, and when they’re finished the robot comes to life and responds with a bunch of jibberish about callbacks, promises, prototypes, and inheritance. Frequently the robot has a breakdown and cries just like a human would, but don’t be fooled – it’s only crying about JavaScript.

It’s not like I want my brain to be this way. I appreciate its preoccupation with JavaScript, because my goodness, it is fascinating stuff – but damn, a girl would like a break! 10 hours of JS a day should be enough, right? I’d like to have oysters and champagne with Deez without thinking about let, const, and var. I’d like to shower without reminding myself, “Now I’m shampooing my hair, now I’m conditioning my JavaScript…” and 5 minutes later having to repeat the process. I would love to be able to answer questions like, “Do you want roasted peppers on your salad?” or, “Do you want a beer?” with a word besides, “What?”

I really can’t expect anything else of my brain right now with all that’s being thrown at it. The first two weeks of bootcamp were pretty chill compared to the acceleration that’s happening now, and I know our instructor is still holding back. How do people doing this without a support network survive? I’m trying to imagine not having Deezus doing the grocery shopping, cooking, cleaning, laundry, and offspring-wrangling while I’m in bootcamp, and I can’t even. I did all that stuff myself while in college and working full-time, which was incredibly difficult – and this is waaaaay harder than college! If you are a bootcamp grad who made it through without any help, @ me, because I need you to teach me things!

In the meantime, I’m going to go get some JavaScript.

Specks of victory

They warn you to be okay with being uncomfortable. You read a hundred blog posts that say the same. YOU RETWEET QUOTES ABOUT IT. You think to yourself, “It’s part of why I’m doing this, because I was too comfortable in my previous life – I was getting too stagnant.” But no…you have no idea.

No idea what it will be like to go from having every answer you need, from being queen of your domain, from feeling good about yourself because in general you’re doing shit right, to experiencing day after day of failure, to being thrown so off-balance by the paradigm shift that it even starts affecting the rightness of stuff you do in your home life, to feeling afraid to do anything at all because recent experience has taught you the probability of getting it right is NOT GOOD.

And you thought you had this discomfort thing down because hey, you’d already survived letting down the ones who count on you by quitting your cushy job; and hey, you’d already gone against everything you believed about money in order to take a giant risk with basically your entire savings account; and hey, you’d already spent countless hours over the last 16 weeks alone, with yourself, dealing with the crazy beasts inside your head. But no…you had no idea.

No idea that this discomfort would tear you down, but it doesn’t build you back up, no – it leaves you to fend for yourself, leaves you to sift through the rubble looking for the tiniest speck of ANYTHING you can call a victory. Last week you were aware that you had strengths and weaknesses. This week you only have weaknesses and a keen desperation to not feel like a fool. So you search, and you search, and eventually your brain comes up with:

Weakness: Teaching others.
Speck of victory: Within that inability to guide/teach someone else, there lies a window for them to find their own way. And I do have the ability to support people as they discover their own best way of doing things, and encourage them, and help them feel safe making mistakes.

Weakness: JavaScript solutions don’t come naturally to me.
Speck of victory: My code is organized, detailed, and at least I do understand what it’s doing.

Weakness: Basically terrified of meetups.
Speck of victory: I still make myself go.

And your brain has to be satisfied with these three itty bitty victories it found, because you now have 5 hours to sleep before getting up and throwing yourself at failure again. And you’re not quite sure if the rest of your life will be this way, but it’s the decision you made, so ¯\_(ツ)_/¯