Technology Lab —

Are there any general techniques to speed up my coding?

Winning a programming contest is going to take more than a few shortcuts.

Stack Exchange

mcwise asks:


This leads to the question: what kind of coding techniques exist to speed up coding at a real job?

Related: "Software design: Build it fast or build it well?"

Answer: Go fast by slowing down (26 Votes)

Dima replies:

The way to produce working code fast is to slow down. Take very small steps. Make sure you know what each step is for. Make sure that after each step your code compiles and runs.


If you do not do this, then it is very easy to write a big pile of code which does not work. Then it will take you a very long time to figure out why it does not work.

See Also: "Learning test driven development..."

Answer: Know your STLs (13 Votes)

kevin cline replies:


Related: "What should and shouldn't be included in a standard library?"

Answer: Know your language (7 Votes)

DeadMG replies:


> "An example would be to use a macro to get the minimum of two ints"

Just use a function? [std::min] already exists.

> "or using memsets to initialize arrays"

[std::array] already initializes its contents.

> "what kind of coding techniques exist to use at a real job?"

The first step is to know the language you are using.


Answer: Veteran advice (5 Votes)

lccarrasco replies:

I participate regularly in ACM competitions. Hopefully some of these tips will help you:

  • As others said, familiarize yourself with the language, in C++, especially the STL, it has both common functions that you'd want to use (binary_search, min, max) and robust data structures to save you time (stack to avoid straight up recursion, queue for BFS, even priority_queue for Dijkstra if you like it that way).
  • Identify the category of the problem, if it's mathematical / dynamic programming / graph theory etc. Ask yourself how familiar are you with it. After doing this you should make decisions regarding the order in which you'll solve them; this goes hand to hand with the next point...
  • You want to understand the problem completely before typing. Solve the right problem. In my first competitions I thought that if I wasn't typing, I was wasting my time. I later found that this was a mistake.
  • Don't think comments are a waste of time. At least in "clever" code, you don't want to go debugging line-by-line to see what went wrong (that is a real waste of time). Value clarity.
  • Have fun.

Think you know how to code faster in a contest or professional environment? Disagree with the opinions expressed above? Bring your expertise to the original post at Stack Exchange, a network of 80+ sites where you can trade expert knowledge on topics like Web apps, cycling, scientific skepticism, and (almost) everything in between.

You must to comment.