Mark Gritter (markgritter) wrote,
Mark Gritter


I've read some of the literature on programming errors, about what sorts of mistakes programmers are likely to make and some analysis of why. But so far I haven't really seen analysis of more basic problems like that illustrated in today's WTF, where the programmer wrote an array to a file in order to determine the length of the array:
private static int GetPhysicalFileSize(byte[] Imgbyte, string InputObject, string OutFolder) {
  int PhysicalFileSize = 0;
  try {
      ExtractImage(Imgbyte, "Photo_" + InputObject + ".jpg", OutFolder);
      var Outfile = OutFolder + "\\Photo_" + InputObject + ".jpg";
      if (File.Exists(Outfile)) {
         FileInfo fi2 = new FileInfo(Outfile);
         PhysicalFileSize = (int)fi2.Length;
      if (File.Exists(Outfile)) {
  } catch (Exception ex) {
  return PhysicalFileSize;
There are several things that could be going on here:

* The author might not be making the connection that "size in memory" is equal to "size in file". This is actually a good thing to wonder about, given that (say) a UTF-8 encoded text file does not have the same size in bytes as its memory representation with wide characters. Better safe than sorry?

* The author might not know how to take the length of the array. Unlikely, but possible.

* The author is exhibiting poor planning skills. Rather than taking the shortest possible route to the answer, the programmer instead engages in some sort of depth-first search across operations he or she knows how to implement. (Given the second example in the article, this seems the most likely explanation.)

It would be interesting to read analysis of these more "basic" errors--- maybe in the educational literature rather than systems literature? Any ideas?
Tags: programming
  • Post a new comment


    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.