Showing posts with label computer science. Show all posts
Showing posts with label computer science. Show all posts

Thursday, June 17, 2010

Names

Yes, names. And the computer systems that handle them. If you write computer programs that handle people's names, read this blog post. Then read this article. Then go back and check your programs for how many of the assumptions in the article they make. Yes, all of those assumptions are invalid. Yes, you will have someone breaking them. Many someones. You'll have more people than you expect using your system. Think about this: right now if something occurs for one person in a million, you can expect more than 300 of them in the United States alone (307 as of July 2009).

And yes, someone out there undoubtedly has in fact legally changed their name to "Robert'); DROP TABLE users" just to be a prat. Your systems should be able to handle him in a suitably boring manner automatically, without needing special coding for SQL injection.

Sunday, May 2, 2010

Floating-point math

Most programmers don't get it right. They forget that floating-point numbers aren't precise, and that different numbers are irrational in base 2 than in base 10. End result: math errors and weird results.

So, on the web: a basic guide to floating point math.

And for the true math geeks: David Goldberg's paper on floating-point math, and the original ACM journal article if you have an ACM account with library access.

Monday, October 5, 2009

Signs your workplace may not be as professional as they claim to be

First sign: having to explain in small words what "significant digits" are, and why where the decimal point is doesn't matter when dealing with them. The targets of this explanation all have degrees in either computer science or an engineering discipline.

Meanwhile, over in alt.sysadmin.recovery, people with no degrees at all are having intelligent arguments over the differences between the various alephs and whether particular ones are ordinal or cardinal numbers.

Thursday, February 12, 2009

Code comments

Motivated by a Daily WTF entry on code comments. I know exactly what creates this: Comp Sci instructors. You know them, the ones who insist that every line of code be commented, no matter how trivial. After a couple of years of this, students get in the habit of including comments just to have a comment for that line of code. Of course the easy way to do this is to just restate what the line of code does.

Now, as a professional programmer doing maintenance on code I don't need to know what the code does. I can read that line of code and see exactly what it does. I need something a bit higher-level. I need to know what the code's intended to do, and I need to know why it's doing it and why that way of doing it was selected. I know it's interating down a list looking for an entry, I need to know what that list is for and why the code's looking for that particular entry. Instead of comments describing how to iterate through a list, I need a block comment saying something like "We've got our list of orders entered this week, we know they're ordered by vendor, and we're trying to find the first order for a particular vendor so we can extract all his orders quickly.". Probably followed by something like "Now that we have this vendor's first order, we'll grab everything until we see the vendor number change. When we see that, we've got all his orders.". Much shorter, wouldn't satisfy that instructor at all since most of the code won't be commented, but much much more useful when I have to change things. It tells me what the code's trying to do, and what assumptions it's making that I have to avoid invalidating.

Too many Comp Sci teachers need some real-life experience maintaining the kind of code they exhort their students to produce.