In my deliberate practice plan for software developers, I suggested that aspiring programming experts find a source of programming problems to use as part of a deliberate practice routine. It turns out that there are more pre-packaged programming problems out there than you could get through in a lifetime. Many of them come from the world of competitive programming. Competitive programming is a “mind sport” like a quiz show or a chess tournament. Contestants are given a set of programming problems, and they have to write programs to solve them. In most cases, programs are submitted to an online judge, which verifies that they produce the correct answer and don’t run longer than a specified time limit. Participants are scored according to how quickly they submit a correct and sufficiently fast program. They may also have a chance to submit challenges to try to stump their colleagues’ programs. Competitive programming is most popular among high school and college students outside of the United States, but there are plenty of competitive programmers who don’t fit that profile. For a colorful description of one contest, the 2010 International Olympiad in Informatics, see the Wired article Teen Mathletes Do Battle at Algorithm Olympics. Regular online contests take place at TopCoder, CodeChef, and Codeforces. These sites also provide access to past problems, which can be used for practice.
Programming contests offer numerous benefits for developers interested in practice their coding skills. Sometimes these benefits can get lost in the online chatter about competitive programming. Critics grumble that contests teach bad habits, that people obsess over ratings, and that programmers should be working on real projects rather than puzzles. There’s some truth to each of these criticisms, but they don’t have to apply to you. The key to getting the most out of time spent studying competitive programming is to be clear about your goals. With that in mind, here are some reasons why competitive programming is a good way to spend your free time.
1. You can structure your deliberate practice routine around it
Deliberate practice begins with the tools of the trade and a source of practice material. Golfers need balls, clubs, and sand traps. Musicians need instruments and sheet music. Programmers need a computer and a description of what to build. While there are other ways to structure deliberate practice for software development, the world of competitive programming is such a convenient source of practice material that it’s hard to ignore. The contest host provides problems, test cases, and community. The practitioner is then free to focus on building good study habits and refining their learning process. Pick a problem, solve it, reflect on how your process worked, repeat.
2. It will prepare you well for technical interviews
The standard coding interview has much in common with a programming competition. They both require solving a clearly-defined programming puzzle, tend to focus on well-known algorithms rather than domain-specific technologies, and reward quick solutions. There are also some differences. In a programming competition, you have access to a computer, while in an interview, you will generally be coding on a whiteboard. Competition problems tend to be harder, especially once you have some experience. And online judges don’t require you to explain why your solution works. But the key point is that experienced competitive programmers will find the coding part of an interview, a dreaded experience for most developers, to be rather straightforward.
3. You’ll get used to working on challenging problems
In discussions of competitive programming, people sometimes point out that the skills developed for competitions are overkill for typical software development jobs. Here are a couple of examples of that line of thinking:
A lot of software gets written in spaces where optimality doesn’t matter because a lot of smart people have engineered the system to make it irrelevant. — Kostadis Roussos
The reality at work is, most time, you don’t really need to deal with [algorithm optimization] problems and, if those are in fact real problems, one or two guys in your team or the company will handle them because they are just smarter than you. — An anonymous Quora user
It’s true that many people with a software development background are hired for jobs that don’t require extensive knowledge of algorithms or performance optimization. Some of these jobs may not even involve much coding at all. But clearly there are also quite a few developers working on operating system kernels, compilers, graphics rendering engines for multi-player games, and other projects that require specialized skills. If you’re interested in that type of job, then it doesn’t really matter what the typical programming job looks like. The skills that you learn preparing for programming competitions will be quite relevant to the job that you’re looking for.
Technical interview expert Gayle Laakmann McDowell suggests that one reason companies use algorithms questions when hiring for positions that don’t require detailed understanding of algorithms is that “What distinguishes mediocre programmers from great ones isn’t their ability to do the 80% that’s straightforward. It’s their ability to do the 20% (or less) that’s hard and interesting.” Almost all developers occasionally run into situations where their baseline skills aren’t sufficient to solve a problem. In Deliberate Practice for Software Developers, I mentioned the example of Tiger Woods practicing a particular sand trap shot that rarely comes up in play, so that he is ready for it when it counts. Similarly, mastering the skills required for competitive programming is valuable for your overall programming competence even if you don’t use those skills every day on the job. By practicing work that is harder than what you are normally called on to do, you’ll be prepared for a difficult assignment when you get the chance to work on it.
4. It’s a way to publicly demonstrate your skills
Competitive programming communities have leaderboards that list competitors’ performance in the contests. A good ranking demonstrates that you can solve problems under pressure, and it shows where you stack up compared to your peers. You don’t have to be at the top of the leaderboard, or even in the top 1000, for your ranking to be beneficial. Most developers don’t have any kind of public record other than their resume, which often contains claims that are hard to verify because they involve non-public work. A competitive programming score, like a history of commits to GitHub projects, is a way to demonstrate that you can actually code, without the need to stand in front of a whiteboard while an interviewer looks over your shoulder. Don’t like the idea of a public profile? Imagine that you’re in the market for a new programming job. If a hiring manager sees a link on your resume to a profile showing steadily increasing programming contest performance, they’ll be a lot more likely to schedule a technical phone screen or bring you in for an interview, since you have already proven that you can do well.
5. It’s guaranteed brain exercise
On any given day, what you’re asked to do at work may or may not be challenging, or you may be exercising one of the many non-technical skills required of software developers. By practicing regularly with competitive programming problems, you can ensure that the coding part of your brain receives a regular workout. It’s like one of those brain training apps, but for real skills.
6. It’s a way to focus on the fundamentals
In his essay on deliberate practice strategy, popular blogger James Clear writes:
No matter how advanced they become, experts never lose sight of the fundamentals. In many ways, they are advanced for that very reason: they understand the fundamentals better than anyone else.
Developers who get a traditional computer science education take classes that cover the fundamental concepts of the field: algorithms, data structures, discrete math. Most of them then branch out into other computer science topics, and eventually apply their education to writing software systems. Since traditional programming competitions use problems that require math and algorithms skills, a competitive programming hobby is a way for programmers to maintain a focus on computer science fundamentals, even while they continue to apply their skills in other areas. Furthermore, it encourages a deep understanding of those topics, since algorithms must be repeatedly applied to different problems. Every time you modify an algorithm to apply it to a different problem, your reinforce your knowledge of that algorithm.
7. It’s fun
Like joining an amateur sports league to get exercise, participating in programming competitions to get better at programming provides built-in motivation. Keeping an eye on the leaderboards and looking forward to facing off against your peers is a way to encourage consistent practice. Some people take the position that programmers should participate in competitions only for entertainment. I don’t agree with that, but the fun certainly doesn’t hurt.
8. It’s a way to practice fast coding
Most commercial software development work has a deadline, but it’s usually measured in weeks or months. In competitive programming, the deadlines are measured in minutes. This provides a unique perspective on problem-solving and implementation. There isn’t time during a contest to search the Web for answers. You must have language syntax and algorithm knowledge at your fingertips (literally).
There’s a school of thought that practicing competitive programming will lead to bad habits that programmers will then carry over into their regular work. I suppose it’s possible that a programmer who would otherwise write clean code ends up using short variable names and long functions due to their competitive programming training. But it seems more likely that they already had those habits. Writing a short program in 30 minutes to solve a puzzle is different enough from writing a complete application that it shouldn’t be hard to remember to take more care for code that is going to be maintained over time. And even for work that has to last, there is a benefit to being able to code quickly. Assuming good code quality, a developer who can finish a particular task in a day is more valuable than one who takes two days. In Joel Spolsky’s classic The Guerrilla Guide to Interviewing, he recommends starting the programming part of an interview with a very easy question, while paying attention to how long the candidate takes to solve it. The reason for this test is that “If the basic concepts aren’t so easy that you don’t even have to think about them, you’re not going to get the big concepts.” Competitive programming can help you learn the basic concepts well enough that you don’t have to think about them, which frees you up to think about more complex issues in the system you’re building.
9. You’ll really learn your chosen language
It’s common knowledge among learners of human (natural) languages that the best way to get to intermediate level in a new language is immersion: once you know the bare minimum, put yourself in a situation where you have no choice but to use the language. Travel to a country where the language is spoken, and hang out with the locals. The analogous plan for really learning a programming language is to use it in a contest. There won’t be any time to consult your phrase book or dictionary, so you’ll find out soon enough if you’re actually fluent. If you’re not, then contests will push you to get there, whether by making you use the correct fingers to hit those special characters, learning the syntax for common library methods, or just writing a lot more code.
10. Competitive programming has an active community
The idea of using deliberate practice as a process for getting better at software development is not an unknown concept, but it’s also not mainstream advice in the world of programming. So it can be hard to find people who are working on that style of learning. Competitive programming, on the other hand, has an active community on the major contest sites, and it’s easy for beginners to get questions answered on Quora. Just as the gamified nature of competitive programming encourages participants to keep coming back, having a community to hang out with can encourage sticking with what might otherwise be a solitary deliberate practice effort.
11. Bite-sized programs are convenient to work on
For various reasons, you may not have time to contribute to a full software system. Maybe you finally got that management offer you couldn’t refuse, or you have some other non-programming day job that keeps you busy. Working your way through a list of self-contained programming problems is less of a commitment than contributing to an open-source project or starting your own, but it’s a way to keep programming.
12. Reading (code) is educational
Many competitive programming sites let you look at the other contestants’ code once the contest is over. And for those that don’t, developers often post their code on blogs and GitHub. This is a good opportunity to see how other developers approached the same problems that you just solved. (Make sure to solve them yourself first). In the real world, it’s rare that two developers will each implement a solution to an identical problem. In a programming competition, a group of talented programmers do this all the time. Why not learn from them?
Remembering the Goal
I know of one competitive programmer whose full-time job is writing contest editorials. (He also has a good post in which he responds to critics of coding contests). On TopCoder, experienced competitors can make a bit of money by winning contests. For the rest of us, winning competitions is not the goal. The purpose of getting better at competitive programming is to improve your fundamental programming skills. That’s what will give you the chance to work on the most interesting projects, because you’ll be able to solve problems that other developers aren’t prepared for.
(Image credit: Kiewic)