loading...

HackerRank Is Teaching You to Write Terrible Code

Devon Campbell on September 13, 2019

In case you’re not familiar with HackerRank, it’s a platform for practicing coding, and, increasingly, it has become a platform for companies to te... [Read Full]
markdown guide
 

HackerRank also taught me how to write pretty clever code. Clever, unreadable, one-line code.

Now I'd rather write 3 lines of code and spend half a second reading the function than writing 1 line of code and spending 10 seconds to read what I was doing.

As you say, coding is for humans.

 

Agreed. Clever code makes you feel smart but doesn't do other the things that code should.

 

I feel stupid explaining code, so I tend the other direction. If I'm explaining then I feel like I did it badly and it's very embarrassing to me. Funny how we as humans see the same thing, but view it very differently.

I tried hackerrank and after two of those kinds of questions I quit for the simple reason that I didn't want to feel like an idiot. Opaque code is just tiring and IRL I always just ask. It's not worth my time doing it any other way.

Thank you so much for shining a light on this issue. It needs more attention and I thank you for taking the time to call them out on a very bad practice.

 

I was told early in my career to "code for the next developer after you" but also "imagine the next developer is a very big, angry man who knows where you live". Worked a treat, my naming and commenting is now explicit and verbose!

 
 

One thing I also noticed as someone who has appplied to hundreds of jobs. 100% of the companies that have used Hackerrank on me never even followed up about the solution. If Hackerrank was the first step. You'd expect to discuss some of your implementation and maybe extend functionalities just to confirm you actually wrote the code. Never has this happen.NEVER. I mean not just once. They usually just move you to the next stage and pretend there was never an Hackerrank test.

It means employers just used this to judge if you can write any code at all. The problem is I could have employed anyone to write the code.Why don't you just take a cursory look at my github. That gives more info than Hackerrank.

There is literarily no Haackerrank problem you can't google if you search enough. Except few ones that are custom made by companies. It is a waste of everybodys time.

 

The problem is I could have employed anyone to write the code. Why don't you just take a cursory look at my github. That gives more info than Hackerrank.

This 100%! If my resume, cover letter, portfolio, projects, github, linkedin, etc. aren't enough then what are we even doing?

The hiring process really needs to take a step back and reevaluate itself. What's worse is the fact that it's a well known issue and nobody does anything...

 

The best part is that if you google you can find the tests of the company/job you apply for. They don't even bother to iterate the questions.

 

This is the part I hate the most. The problem description is so academic and pointlessly long. I have no CS background and find this off putting.

 

I agree for the most part. I'm a huge advocate for responsible coding. Shoot, a huge part of Dead Simple Python is dedicated to it. More on coding challenges and good practice in a moment...


With that said, I think there is an exception for competitive code golfing (which I usually do over on Codingame instead of HackerRank), which I've found to be beneficial in a different way:

  • The goal of making the code as compact as possible forces me to understand the underlying processes and alternative ways of doing things. Brute-force seldom wins in length-based code golfing.

  • The same processes you should follow to make your code smaller in length-based code golfing are the same processes you would use in real world refactoring, although the outcomes are different. You always start by writing a simple, straightforward solution and verifying it works, and then you begin rewriting it piece-by-piece until it's a small as possible.

  • Time-restricted code golfing hones your ability to distill human thought (the prompt) into computer logic quickly and efficiently. In practice, this has helped me write better code in real world scenarios; it takes me less time to work out the logic, so I have more time to pay attention to matters of design and good practice. (After all, don't we usually skip good practice because of time?)

These unique benefits justify terrible variable naming practices in that specific context, so long as one remembers to use good names elsewhere.


None of that is to invalidate your concerns, of course. One should be aware of the profound differences between code golfing and real-world coding, and HackerRank doesn't always make that difference clear. Given its lack of time constraints, and the fact it isn't formal length-based code golfing (as far as I know), there's no reason why you shouldn't apply good practice to your code there! I literally always delete HackerRank's default code.

Personally, I do prefer Codingame, as it has proper multiplayer code golfing which is separate from the standard coding challenges. Their default code is almost always better, too.

 

Thanks for making me aware to Codingame. Didn't realize that was a thing.

 

As a former competitive programmer, I can't completely agree with the premise of the article for a simple reason:
Hackerrank and similar websites are NOT teaching you code.

The purpose of those websites is to test for and practice algorithms and algorithmic thinking and, last time I checked, the code editor there allows you to delete everything entirely and write your own.
Their premise is that if the core of the problem is to test your knowledge of say... Dijkstra, the way you'll parse your input files and read input and write output are a distraction with respect to knowing whether you can or not write a Dijkstra based solution.
Some websites choose to let you upload your code entirely or others give you these placeholders. I'd dare say that competitive programmers would be smart enough to never take that code as production-ready at face value.
Also as a sidenote, I never, ever needed to read/parse files in a professional setting in any non-trivial way besides reading the file as a list of lines.

 

Here's the problem with that: junior developers are using HackerRank to practice because they're being sent there by recruiters and companies to complete coding problems as part of job interviews. If that's the site that gets them the job, it seems natural to practice there as well.

It's easy for you and I to look at this with a more robust perspective and say, "Well, of course this isn't the code you're supposed to write in production," but that's not made clear to a new developer. They don't have the tools yet to be critical of the efficacy of this code in other contexts. Competitive coders will have those tools, but HackerRank does nothing to keep out those who are not competitive coders and it doesn't make it clear that the platform is only intended for them or even just that the code is not production-quality.

If I were inexperienced, interviewing for a job and they sent me to test for the job on HackerRank, I would assume the code used on HackerRank reflects the code they will want me to write on the job. Why would they want to test whether or not I can write code they won't accept from me if I'm an employee?

So, HackerRank may not claim to teach people to code, but they are teaching people to code, for better or for worse (in my opinion, for worse).

Thanks for reading and sharing your perspective, Bruno.

 

Wow, thank you so much for your reply! :) (I assume you're also far more experienced than me, so this is a great perspective)
I agree with what you say indeed, junior devs or people just "going at it for the job", even if they're good at algorithms, can definitely pick up very bad habits from that scaffolding code that lies there.
Unfortunately competitive programming is literally a competition so writing unsafe, sluggish but blazingly fast I/O routines and taking some dubious shortcuts it's the norm there (top competitors using C/C++ would have hundreds of lines amongst macros and custom I/O routines just to shave off ms on reading and processing input) and unfortunately some junior devs can definitely approach those platforms completely misguided and start their career with the left foot there... Ultimately experience and long exposure to production code will fix all of these quirks but I agree it's a big problem with more and more companies "outsourcing" code challenges on these platforms nowadays. Thanks a lot for your reply

 

Thank you for this post. I'm 3 months into a Python Bootcamp and started doing a basic Python path there. The code they suggest in their basic arithmetic tasks is really weird and questions all I've learned so far. It's good to hear that I'm not the only confused person around.

 

I use sometimes hackerrank but never thought about this. In everyday code, I am trying to be explicit and least ambiguous software as though as if I was woken up at 12 at night and had to debug it. But I noticed that comes with experience I think and after eating a few humble pies myself and writing crap code :).

 

Yep this seems right; HackerRank is closer to TopCoder, the goal is to pass the test and whatever other criteria there is. For HackerRank it's to pass the test and prove you can code to the interviewers. For TopCoder it's to pass the test and make the code as performant as possible.

I'm hoping that no one is really using either of those as a model for production code though!

 

I'm afraid people are taking those exercise starting points as models for how they should code because they don't know to be critical of them. Hope this post can reach at least a few of them.

Thanks for reading, Rudolf.

 

This is so true!! I remember joining my first job and being surprised when micro optimisations, clever tricks that save lines and obscure logic that you think is super cool are not applauded, and rather discouraged.

Being in college, hackerrank and countless other similar platforms taught me to value the wrong things and continue to do so. Smh

Rant over.

Totally agree. I have a CS (actually msc) background and after 14 years working for an international company I wanted to move along and find a new job (yes, I am not the typical jobhopper). To my greatest surprise most of the companies here asked for HackerRank tests. I started working on hacker rank exercises and eventually passed them. However, it was like practicing for an exam, and totally removed from real-life problems. Now, either every company needs to solve complex algorithmic problems on a daily basics (which I am pretty sure they don't) or this is some kind of quick test just because it seems easy for the recruiters. The code I had to write in hacker rank was ugly and would never pass any of my own code review for sure.

 

I agree I'm the way that anyone writing about software development should be guiding others to be the kind of person that adds finesse to a team, not the one bringing speed bumps to the team. Help others create positive software engineer habits!

 

I say the best code is "dumb code".

Code that is so blatantly obvious, so simple, and so boring to read that you don't need comments. I'm not saying this is always possible, but it should always be the goal.

 

"Code is for humans." That is the strongest, and in my opinion, most important, point made in this article.

All code we write is made to be extended and improved by the people around us who, in many ways, would have a more clever way of extending and improving it. I am 100% guilty of rewriting functions myself if I can do it more quickly than I can understand what the previous developer was trying to. Not a great practice, I admit. But many times, an END PRODUCT is required that does certain things, to certain specifications, for a certain price, by a certain date. How clever the current codebase was is totally meaningless if it can be rewritten faster than extended. Don't let good code die when you leave. Variable, parameter, argument, function, class, and module names COUNT!! I want to work with the code I've been given. But I want to not have to explain delays to executive managment more. Just saying...😁😁🤪🤪

 

"Code Is For Humans"

Often forgotten, the interpreter/compiler doesn't care how you name things, your coworkers will.

 

What is the reason behind HackerRank using Node.js instead of vanilla JS? The first time I saw that I was thrown off but I'm curious as to the actual reason. If there is one. It just seems overly complicated.

 

IMO, if you want to learn algorithm in pro way, you should go with hackerrank, topcoder, codeforces, kattis, Atcoder, SPOJ, codewar ...

If you want to learn code as a beginner you can learn from pluralsight, ... (sorry I do not learn this way so I do not have much experience about site like this, I often learn from language's docs instead)

I love algorithm, code golf (one line, unreadable code) but in my production code, I write everything pretty clear so anyone can get it.

Everything exist for a reason, you may wonder but almost winners in Olympiad for Programming or Google CodeJam, Facebook hacker cup have profiles in the sites that I mentioned above with highest rating.

You can get benefit from them if using in smart ways and open-minded, and you can leverage your critical thinking in the next level.

Btw: my favorite sites is: dwitter.net/ and codegolf.stackexchange.com/

 

Gah, JavaScript is a language where so many things/opinions matter. It's pretty daunting at times. Thank you for this article! It's a good one :)

 

“There are two hard things in computer science: cache invalidation, naming things, and off-by-one errors.” — Leon Bambrick

 

What's the best language for programming softwares?

 

The least helpful and also only accurate answer to this question is, "It depends." If you want to write software that runs in a web browser, you have no choice but Javascript. If you want to write native mobile applications with full access to device APIs, Swift or Objective C for iOS or Java for Android. If you want to write software that automates some task, Python might be a good fit. If you want to write a web API, you've got lots of good choices.

Depends on the kind of software you want to write and your priorities.

code of conduct - report abuse