Author Archives: kevin

About kevin

I write the posts

links for 2011-02-26

Liked what you read? I am available for hire.

links for 2011-02-25

Liked what you read? I am available for hire.

Everything I know about debugging

If you write programs, a large portion of your time is spent testing your code, and finding and removing bugs in your program. Not being able to understand a bug is one of the more frustrating experiences you can have as a programmer. I’ve been on the lookout for ways to reduce the amount of time I spend debugging, but I really haven’t seen any good articles on the theory of debugging. Here’s everything I know about debugging. If you have additions, feel free to leave a comment.

Write better code

The best defense is a good offense – if you write your code in a clear and concise way, and write by making incremental changes which are immediately tested, you are less likely to run into time-sucking bugs later on. Some people recommend test-driven development and code review as ways to cut down on the number of bugs that make their way into programs. Remember, the earlier you can catch bugs, the less expensive they are to fix.

Try simple fixes for 2-3 minutes

Some bugs are simple and can be fixed within minutes. I would recommend spending 2 or 3 minutes trying a few simple fixes before bringing out the big guns. Yes, this is “cargo cult” programming but maybe 50% of the bugs you find have trivial fixes, and it might not be cost-effective to bring out the big guns right at the start.

Set up a reduced test case

Try to set up the simplest possible version of your code that produces the error. In HTML and CSS, this is known as a reduced test case. This often involves deleting large swathes of your code, so I would recommend either copy/pasting to another page, or committing the current version of your code, then making changes, and reverting to the original version once you’ve identified the problem. If you have a unit test suite, this would be a good time to add a new test case to the suite.

Use print statements or a step-through debugger

If setting up a reduced test case is not feasible (multiple dependencies or complex code), use print statements to determine the values of variables before and after all method calls in your program that could be causing the bug. This is tedious, but systematic, and preferred to cargo cult programming, where you make changes at random and hope that they solve your problem. Another approach is to use a step through debugger – stop the program at a point where you know the output is correct, and then step through the program line by line, monitoring the information in the program. In python, the pdb module does this. In Java, the DrJava program is looked down upon for being mostly for students, but I’ve found it extremely useful for viewing the values of variables at points in the program. Most programming languages should have a step-through debugger.

Use assert statements

Alternately, you can use “assert” statements to assert that a variable should have a specific value at a point in your code. This will stop code from executing immediately at the point where a variable has an incorrect value. This has the added benefit of making sure you understand your code.

Concede defeat

If you’re still at a loss, consider ways in which you can “go around” the bug, by rewriting sections of your code in a way you understand, or trying something else entirely to solve your goals. Note: I struggle with this because not knowing the cause of a bug drives me up a wall, but you might have some success with it. Also, stepping away from your computer and thinking about the problem in more abstract terms can help – I’ve had some luck with just taking a shower and thinking through the problem.

Ask the Internet for help

If you’re still at a loss, try copying and pasting your error message into Google, or posting on StackOverflow. Be sure to be explicit about what you expected to see and what actually happened, and post the code of any error messages you might have. You can also try the IRC channel for the programming language, but I’ve had less success with this – there might be someone nice who’s willing to help you out, but more often than not your message will be ignored.

About me
My name is Kevin Burke and I’m a senior at Claremont McKenna College. I started programming in January of 2010. Read more about me, or follow me on Twitter here.

Liked what you read? I am available for hire.

links for 2011-02-22

Liked what you read? I am available for hire.

links for 2011-02-21

Liked what you read? I am available for hire.

The Robert Day School is hurting CMC’s leadership efforts

Note: I wrote this last year a few days after I was rejected from the Robert Day Scholars Program. This year’s Scholars were just announced, and I thought it was worth reposting.

Let’s say you had $360,000 to give away every year to undergraduates and you wanted to encourage future leaders, or increase the net amount of business success enjoyed by undergraduates at your school. What would be the best way to spend the money?

Observation #1: It’s difficult to predict who is going to be successful and who isn’t. Arguably, 2 of the top 3 earners that CMC has produced were C students when they were here. Robin Williams went to CMC and dropped out; so did Ben Casnocha. I have heard that Robert Day himself, and Henry Kravis, were C students; George Roberts would bet on horses at Santa Anita every day after class. Clearly, the Robert Day program wants to maximize the number of future Kravises and Robert Days, but Kravis and Day probably would not have had the grades to get into the program.

We can observe which students have taken leadership roles, and which students have high status, and we can give a work sample assessment, but these are merely rough indicators – the work sample assessment has only a 0.52 correlation with future job success.

One crucial factor is luck; people have to be at the right place at the right time, and it’s hard to predict which fields are going to be huge, or which person will start the right company or strike up the right conversation at a bar, or join the right startup. Maybe we can assign a percentage chance of wild success to every student, but I would guess that the difference between students in the top GPA decile and students in the bottom GPA decile is maybe 0.4.

Observation #2: If you want students to succeed, instead of telling students they are smart, tell them they are not working hard enough. There’s a reason successful coaches don’t tell their players, “You guys are so athletic and so good. You deserve your #1 ranking and you are all surefire lottery picks. Let me buy you some pizza.” Complacency is not a good leadership trait, and successful students/athletes hear “You’re so smart” more than enough as it is. It’s not clear that, even if you could identify successful students, that giving them a large chunk of cash is ideal, if it could make them complacent. While we give scholarship money to athletes, this is largely a prize so that they want to choose our program, and we take it away if they are unmotivated, or unsuccessful.

Indeed, the students who are rejected from the cash/status giveaway program might develop a chip on their shoulder and become more motivated than the students accepted to the program. I am reminded of Michael Jordan, who was cut from his high school JV team, or CMC trustee Augie Nieto, who was told by his thesis adviser that his plan to develop a series of exercise machines would not work, and he went on to turn the thesis into the multimillion dollar LifeFitness company. There is a selection bias at play here, but it would be good to study if the Robert Day program had a measurable effect, and if so, what that effect was.

Observation #3: Leadership skills, as well as skill at becoming exceptional, can be taught. Some high status students are natural leaders and others have the decision-making skills to become leaders but maybe not the body language, or ability to inspire others. Where should we focus our attention: on making the potential stars into superstars or on sharpening the diamonds in the rough? Given the luck-based nature of success, I would be tempted to focus at the margin but it depends on your estimates of the your ability to make a difference, as well as the goal of your program.

Recommendation: The key is to design your program to send different messages to different groups. To the group of super-bright, super-driven, super-body language, super-ability to inspire students, you want to send a message that says, Don’t get complacent, no one’s looking out for you, if you want to get anywhere you need to work harder. These students are probably going to out-earn their peers, and everyone knows it; if you gave this group money, you would probably get the least bang for your buck, as well as cause resentment among other students and professors.

To the group of marginal students, who maybe aren’t as driven as the top group, you want to send an encouraging message, and spend more attention, in the hopes of boosting their leadership skills and giving them confidence and a better chance of success in the workplace. In theory, you could achieve this by setting up a status and cash-conferring scholarship for a select group of students and then deliberately choosing the candidates you think are second-best.

Either way, you’re not touching the C students who might turn out to be brilliant, or lucky, businessmen. I’d probably want to arrange lectures for everyone on how they can increase their impressiveness, and on the importance of body language. I would purchase cameras for every teacher and instruct them to film students any time they present something, and also randomly during class discussion, and then give the tape to students so that they can see the effects themselves. Given that the group who will attend lectures will self-select to be the group that needs it least, I’d want to consistently emphasize the importance of these qualities, maybe give out a cash prize for attendance or include them in the core curriculum.

Conclusion: If I’m in a position to have $360,000 to give away every year, I’m probably interested in showing that I care about future leaders by giving away money, and less interested in actually increasing the number or success of future leaders, e.g. how the program is designed. At the margin, of course.

If I’m so negative about the effects of the Robert Day School on the student body, then why would I bother to apply? It’s usually easier to change organizations from within, and given that the opportunity exists, it would be silly to turn it down. I would like to see more CMC students become future leaders, as they are my peers, and it will make me feel prouder to affiliate with CMC. That said, being a rejected applicant, it will be difficult to suggest and implement any changes to the program, as most of my suggestions will be taken as sour grapes.

Liked what you read? I am available for hire.

links for 2011-02-20

Liked what you read? I am available for hire.