
lengthInInches is even better (if, in fact, you’re expecting the measurement to be in inches).
.png)
Variable, parameter, and function names should encapsulate as much context as possible to help the reader understand what they’re reading. Write it to be read by someone other than you. Take this to heart as you’re writing your code. If it was exclusively for computers, we’d have no need for a high-level language like Javascript or Python.
GOLF IT OUT HACKERRANK CODE
You may think that code is for computers. I help people like you start their web development careers. t? tItr? n? q? qTemp? Why are these practice exercises not more readable? The variable naming in that main function is seriously making my head spin. Here’s your starting code for another indecipherable exercise: Not every exercise uses this opaque variable and parameter naming, but many do and some are even worse than my first example. You might think I’ve cherry picked the only example or maybe the worst example of this on HackerRank. I pity anyone else who has to pick this app up and work on it. You’re going to spend most of the time you work on this application just trying to figure out what it does. Since you learned this is OK, your variables are probably not thoughtfully named either.

Each function has parameters with cryptic single-letter names. Now take this new naming issue and blow it up to an application with 10,000 lines of code. Any idea what those parameters are? Yeah, me neither. Maybe you have a function that displays an alert on your page. Now put that in a context where the meaning of the parameters are not so clear. Imagine the split second it takes to remember what a and b are in the Rectangle function. In your career, you’ll never write an application that’s this short and that does so little. And if HackerRank does it like this, it must be right right way… right? !😰 Muggles look at a and b and throw their hands into the air, but you… you can decipher it in a fraction of a second. Like you’re part of a fun club with a secret code. Even so, there’s still going to be a split second where you don’t know what a and b are. You’re probably not going to permanently lose track of what a and b are. Not to mention the only two logical parameters to create a rectangle and its length and width. In this HackerRank exercise, you’re going to write a few lines of code at most. So, why not just call a spade a spade? Why can’t the length be length and the width be width? The names length and width are not reserved by Javascript. That means they don’t even need to be a and b. In fact, all they’re ever going to do in this function is be the length and width of the rectangle. In order to stay on the streets delivering vigilante justice, he can’t let anyone know that he is actually Bruce Wayne.īut, as far as I can tell, a and b don’t need to keep their true identities (the length and width of the rectangle) hidden. Even though he’s doing it for good, he could still be arrested.

If you read the problem description, they’ll tell you explicitly that a is the length of the rectangle and b is the width.īatman needs to keep his identity secret. If this is all they ever gave you, you could probably work out that a is one side of the rectangle and b is the other side. That’s probably what HackerRank expects you to do with their problems: leave the starting point they’ve given you as-is and fill in what’s missing. Most coders will take this starting point as it is and fill in the space between the brackets.

Creating a rectangle object is day 4 of those 10 days. This is the starting point of a function they ask you to write for their 10 Days of Javascript. Enter fullscreen mode Exit fullscreen mode
