Detect problems in JavaScript automatically with ESLint

February 10, 2015 – 1:06 pm Tags: , ,

I’ve been programming JavaScript for 15 years or so, and I still keep making various silly mistakes – I type things wrong, I forget to rename everything, I forget to follow the coding styles… then I waste my time clicking around in the browser and feel like slapping myself.

Thankfully tools like ESLint exist. ESLint helps by finding errors automatically, so you can spend your time doing something more interesting.

Let me show you a real-world example from a codebase I worked on of how ESLint can help.

Read the rest of this article

How to unit test NodeJS HTTP requests?

January 30, 2015 – 5:16 pm Tags: ,

I have a nodejs app where I wanted to unit test some HTTP requests. Node usually makes things simple, so I expected this to be like that too… but I soon discovered that this was not the case at all.

When unit testing, you don’t want HTTP requests to go out and affect the result. Instead you create a fake request – a test double – to replace the real one, but because node’s streams are hard to fake, this is where I hit the wall.

It took some work, but I found a way to make it simple! Let me show you how with some examples based on real live production code.

  1. Sending a GET request and testing response handling
  2. Sending a POST request and testing the parameter behavior
  3. Testing that failures are handled correctly

Read the rest of this entry »

Strange JavaScript errors and how to fix them

January 22, 2015 – 9:30 pm Tags:

JavaScript has some of the strangest errors. Undefined is not a function? Ugh.

I wrote an article talking about JS errors and a guide on how to fix them on David Walsh’s blog, you should go check it out!

JavaScript errors and how to fix them

ES6: What are the benefits of the new features in practice?

January 6, 2015 – 11:00 am Tags:

You’ve probably seen people talk about the features in the upcoming JavaScript version, ES6, or ECMAScript 6. Promises, let keyword, iterators, etc.

But why should you care? I certainly heard a lot about it, but I hadn’t looked into it because I wasn’t interested in theory, but rather the benefits I would get in my day to day work. Is it just feature-bloat for sake of having fancy things in the language, or are they actually useful?

I then did some research and discovered a number of very useful features in ES6 that you can start taking advantage of right now. Let’s take a look at the most useful ones

Read the rest of this entry »

How to start using ES6 today?

December 18, 2014 – 3:36 pm Tags:

When you want to use ES6 you’re faced with a list of questions: Transpilers, shims, browser support…

In this article, I’ll give you a detailed guide on making sure you get started with ES6 the right way, and instructions on how you can set up a workflow for using ES6 in production easily.

Read the rest of this entry »

How to make your code self-documenting?

December 1, 2014 – 5:55 pm

Isn’t it fun to find a comment in code that’s completely out of place and useless? What if you could write fewer comments and still keep the code easy to understand?

One of the primary ways to do this is making your code-self documenting. When code is self-documenting, it doesn’t need comments to explain what it does or its purpose, which is great for making the code easier to maintain. As a bonus, with fewer comments, it’s less likely they’ll be crap!

In this article, I will show you several ways you can make your code document itself.

Read the rest of this entry »

AngularJS best practices: Be careful when using ng-repeat’s $index

November 10, 2014 – 12:54 pm Tags: ,

“A customer reported they deleted an item and the wrong item got deleted!”

Sounds like a pretty serious bug. This is what we got one time at work. Attempting to locate it was quite difficult, because naturally the customer had no idea what they did to reproduce the issue.

Turns out the bug was caused by using $index in an ng-repeat. Let’s take a look at how this happens, and a super simple way to avoid this type of bug entirely, and also a few lessons we can learn from this.

Read the rest of this entry »

What do the top 1% of software engineers do that the other 99% do not?

October 20, 2014 – 3:12 pm

This interesting question was recently posed on Quora: What do the top engineers do, that the rest do not? And how do you get the habits to become one?

Anyone can tell you something like “oh you should use source control!”, or “you should comment your code!” or other obvious things like that.

But there is a limit to how much code and how good code you can crank out daily, so how do you actually become better?

Read the rest of this entry »

Using techniques from statically typed languages in JavaScript

September 2, 2014 – 8:48 pm

I wrote an article discussing some techniques from statically typed languages. Head over to SitePoint to check it out!

Here’s what you can expect:

  • JavaScript type system, and how it tries to bite you
  • Expanding more about the rule of consistent types with more details on using it to reduce bugs
  • Dealing with type-checking and type-conversion in a way that doesn’t result in spaghetti and extra checks all over the code

Head over to SitePoint to read the article

In order to become a better developer, you must first become a teacher

August 18, 2014 – 1:20 pm

The headline might sound pretentious, but what is the most important skill for a developer besides actually writing code? Communication.

What do you typically do when you communicate as a developer with someone else?

You explain problems, you describe solutions, you talk to non-programmers about what you’re doing. You could also say that you’re teaching others about what you’re doing. Heck, when you’re writing code, you need to comment it and that is also a form of teaching – teaching someone what your thought process was when writing this code.

Being a good communicator is often completely overlooked. Sure, you might see a job placement ad wants someone who has “good communication skills”, but what does that even mean?

Let’s take a step back and think about why it’s really important for a developer to be a good communicator, and then we can come back to how you can become a better developer by teaching – but don’t worry, this process will only require a small amount of effort, although if you enjoy it, you can absolutely spend more time on it too, and reap bigger rewards!

Read the rest of this entry »