What is HackerRank? Tips when joining HackerRank
What is HackerRank?
HackerRank is a platform for practicing code, according to its founders, where developers from all over the world gather to solve scientific problems. computers such as algorithms, machine learning, artificial intelligence as well as practice various programming models such as functional-oriented programming.
Not only that, HackerRank has gradually become a platform for companies and employers to test the candidate's coding skills. It's convenient to be able to learn to code and show results to employers in the same place at the same time.
Interested in visiting HackerRank.com website to participate and learn to try offline.
However, there are a few issues to keep in mind when practicing code on this platform, this is the advice of Devon Campbell, a web developer from Seattle, posted on the dev.to page that I have translated. again for you to read.
Note when learning code on HackerRank
function Rectangle(a, b) { }
This is the first line of a function that they ask you to write in 10 Days of Javascript. Write a rectangular object lying on the 4th day in 10 days. Most coders will use this first line and fill in the gaps between the marks {}. This is probably also what HackerRank expected.
By looking at this first line, you can understand that a is one side of the rectangle and b is the other side. If you read the article description, it is clear that a is the length of the rectangle and b is the width.
Why do you need a secret?
Batman needs to keep his identity a secret because he often spends the night doing illegal things, even though it's a good thing, he can still be arrested. In order to be free and bring justice to others, he cannot let others know that he is Bruce Wayne.
But, a
and b
here do not need to keep their true identities secret (the length and width of the rectangle). In fact, all they will do in this function is the length and width of the rectangle. That means they don't need to be a
and b
. So why can't length
be length
(width in English) and width is width
(width)?
What are the harmful effects of that naming?
In this HackerRank exercise, you will only write a few lines of code. Not to mention the only two logical parameters for creating a rectangle are its length and width. You probably won't forget what a and b are in the code. However, not only do you read your code, there are others, and many of them may not know what a and b are.
You can feel the code is very concise and smart, and it seems that HackerRank does that very well.
OK, but think a bit, in your work have you ever written an app, which program has so little code? If the application were 10,000 lines of code, each function had parameters with the letters a, b, c, d, e, the story would be very different. You can read and understand this code because you wrote it down, but if someone were to hand over this code from you they would probably have read it and cursed it inside.
You may think Devon is difficult or find the worst example on this platform to disparage. Of course, not every exercise on HackerRank uses obscure variable names, but there are many such exercises. Here is another example:
'use strict'; process.stdin.resume(); process.stdin.setEncoding('utf-8'); let inputString = ''; let currentLine = 0; process.stdin.on('data', inputStdin => { inputString += inputStdin; }); process.stdin.on('end', _ => { inputString = inputString.replace(/s*$/, '') .split('n') .map(str => str.replace(/s*$/, '')); main(); }); function readLine() { return inputString[currentLine++]; } // Complete the minimumBribes function below. function minimumBribes(q) { } function main() { const t = parseInt(readLine(), 10); for (let tItr = 0; tItr < t; tItr++) { const n = parseInt(readLine(), 10); const q = readLine().split(' ').map(qTemp => parseInt(qTemp, 10)); minimumBribes(q); } }
Many variables in the above code are not easy to understand, what is t
, what is q
, what is n
, what is tItr
. The main purpose that the author wants to say here is to just name the variable clearly, write. The code so that anyone who is new to reading it can imagine what this function does, what this variable is. Why do we need that?
Writing code is for humans
You might think that the code is for computers. No, it is not. Code for humans. If it's computer-specific, we don't need high-level languages like Javascript or Python.
Keep this in mind when you write code: Write how others read the code you write that they understand. Variable names, parameters, and functions should contain as many contexts as possible to help readers understand what they have read.a
is a very bad variable name. legnth
is a good variable name and lengthInInches
even better (if you expect the measurement is in inches). If the code changes, make sure you update the names given to reflect what they represent.
Because HackerRank is a big, reputable company, having a well-rated code on the platform also makes employers more interested.
It's just that, when you practice on HackerRank, train yourself the habit of restructuring terrible names of nonsense into a name that can convey the meaning and context necessary to read the code. When you work with projects off the ground, don't let obscure naming harm your code and earn you a reputation as an unreadable code developer.
By keeping in mind that writing code is something you can read later, you not only make it easier for other developers to work with you, but also make customers want to hire you and introduce you. with other companies that need your help.
There was a funny comment below that: When I got into the business I was told, "How to code the guy in the can read and understand" and "Imagine the person who inherits your code is a tall guy. Hot temper, knowing where you are "(If he doesn't understand, he will come to your house and give you a match - a translator).
You should read it
- The 'battlefield code' and job opportunities for you
- The confidences of a Coder: Finding bugs must rely on both hunch and rules
- 27 things I wish I knew before programming
- The wedding invitation card of the coder is completely different from what you think!
- 13 tips to help you learn code super fast without being too expensive
- 10 best programming games to test and develop your coding skills
- How to get your kids excited about coding
- The Wonders of Learning How To Program And Its Benefits To Your Business
- 12-year-old coder earns 350,000 USD selling NFT dolphin collection
- Female 10-year-old coder was invited by Google and Microsoft to work
- Set of multiple choice questions about programming with P7 prize
- AI makes coding skills no longer necessary: Here are 5 reasons that prove this statement is incorrect!
Maybe you are interested
Latest Mobile Legends Codes 12/2024
Latest Three Kingdoms 3D Code and how to redeem code
The latest Giftcode for Queen Gia Lam and how to redeem the code for rewards
Latest Call of Dragons Codes and How to Enter Codes
Latest Edward the Man-Eating Train Codes and How to Enter
Latest Goose Goose Duck Code 12/2024