Asking for Advice is Easier than Taking It

Advice

We have good options these days for getting answers to programming questions. Stack Overflow provides answers to fact-based questions. They can be targeted questions like How to sort a Collection? or even somewhat speculative questions like Why is there no SortedList in Java? that can be answered factually (does Java provide a list data structure that is always sorted?). Beyond that, things can get tricky on Stack Overflow, which has strict policies about question topics. For example, questions like Best ways to teach a beginner to program? tend to get locked and/or closed. Even on Programmers StackExchange, a question like How to deliberately practice computer programming?, which happens to be the top Google search result for deliberate practice for programmers, is considered off-topic. (Update 6/18/2016: And the question has finally been deleted).

As essential as Stack Overflow is for programmers, sometimes you need an answer to a question that doesn’t work there. For those types of questions, there is Quora. Although Quora does have mechanisms to maintain content quality, the rules are much looser. The advantage of this approach is that you can get answers to a wider variety of questions. The disadvantage is that it’s a lot harder to control quality. For example, Quora gets bombarded with questions of the form Is it too late for an X-year-old to learn how to program? But questions like How should I get started in competitive programming?, which would get closed on the Stack Exchange sites, can actually collect some useful answers on Quora.

There are other sources of programming information that people use for questions and answers. Reddit and Hacker News come to mind. They have voting and, in the case of Reddit, even an “accepted answer” feature. But in my experience, these sites are not as effective when used for Q&A. They are mainly designed to show a link to an article followed by comments from users. This can be adapted for Q&A, but it’s easier to use a site that was designed from the ground up for questions and answers.

« Continue »

Why is Java I/O Slow?

Tortoises

You can read a lot on Quora about the best language to use for competitive programming. Here are some of the points covered by those questions:

  • C and C++ execute quickly, and their macro support can reduce the amount of code that you end up typing in your solution.
  • A language like Java can be useful for problems with some specific requirements (such as integers that don’t fit in 64 bits, or calendar problems).
  • The main contributor to execution speed is the algorithm that you use, not the language that you choose to implement it. But the language can provide a performance edge at the margins.
  • Choice of language is less important for more recent contests, since problem setters have made an effort to level the playing field (e.g., by testing Java solutions to ensure that the time limit is sufficient).

I decided to use Java for Project 462, mainly because it’s similar to my primary language (C#), and I’m more interested in learning about problem solving and algorithms than learning a new language that I’m unlikely to use much outside of competitive programming.

One thing about the uHunt problems that I’m working through is that they draw from a database of contest problems going back to the 1990s. Competitive programming and programming languages have changed a lot since then, so what the problem setters were going for in the original contest may not match up with how a contestant sees the problem today. Modern contests tend to be more forgiving of the slower execution time of languages that aren’t C or C++, and they know about the fancy libraries that programmers have access to.

Last week I wrote about Solving UVa 11340 in Java, and covered some performance tips related to reading files that are larger than those typically found in programming puzzles. It turns out that the very next starred problem, UVa 12356: Army Buddies, is an even stricter test of I/O performance. And for this one, there is no particular hint in the problem statement that I/O will be an issue.

Once I came up with an Accepted solution for UVa 12356 in Java, I decided to do some more benchmarking, and use the results to update my solution template. Figuring all of this out once is educational, but I’d rather not be fiddling with I/O issues for every problem that happens to have large input or output requirements.

« Continue »

Solving UVa 11340 in Java

ISO-8859-1

UVa 11340: Newspaper, despite being ranked at only Level 2 difficulty on uHunt, turned out to be rather tricky. Apparently others thought so too, judging by the 11 pages (151+ posts) of discussion on the UVa OJ message board. Many of the message board posts focus on the characters used in the test input. The consensus is that they are 8-bit characters (with values from 0 to 255). At a minimum, these characters need to be stored in an unsigned char data type in C++. Nevertheless, people seemed to run into problems even after getting that hint. I solved the problem in Java, which doesn’t have an unsigned char data type, but it has its own set of difficulties. I’ll cover the two issues that I ran into when solving this problem.

« Continue »

The Long Game

AnathemDoom

The theory of deliberate practice is a popular starting point for online article writers. I subscribed to an alert for the term, and I generally get a few results every day (of varying quality). Its popularity isn’t surprising. Deliberate practice offers a process that anyone can use to get better, assuming they are willing to follow it carefully and put in the required hours. Articles and books on the topic often provide examples of well-known experts who followed a deliberate practice process. Geoff Colvin’s Talent is Overrated mentions Tiger Woods pushing golf balls into the sand to make them harder to hit. James Clear writes about Kobe Bryant’s 800 jump shots before practice. But there are also examples of people who didn’t have coaches to steer them towards the right practice steps, but nevertheless achieved incredible results. I recently finished reading Masters of Doom, the story of the founders of id software. One of the recurring themes in the book is the incredible work ethic of John Carmack, co-founder, graphics engine developer, and all-around game programming legend.

« Continue »