snoofle

After surviving 35 years, dozens of languages, hundreds of projects, thousands of meetings and millions of LOC, I now teach the basics to the computer-phobic

Dec 2013

Where's Windows?

by in CodeSOD on

Java was touted as write once, run anywhere to emphasize its cross-platform advantages. Of course, the devil is in the details, and to interact with the local operating system, you still need to know something about it.

Without a built-in facility, the only real way to figure out the local OS is to try to exec commands unique to each OS and then check to see which ones succeed, and what value(s) get returned. For example, uname -a provides useful information on *nix systems, but is useless on Windows. It can be as painful as trying to find Waldo.


Calling All Zip Codes

by in CodeSOD on

It's been an active couple of months for O. Z.'s group.

In an effort to combat keying errors and all around bad data, some long overdue validation was added by one of O. Z.'s co-workers to several of the screens, and perhaps most importantly, to the address entry screens.


Printing Decimal Numbers is HARD!

by in CodeSOD on

Decimal numbers are sometimes difficult to work with because they can't always be stored with exact precision. This also leads to difficulty in displaying the value of a decimal number because you need to deal with getting the precision right. Fred G. found this bit of ingenuity:

  // File format
  //
  // ABBBBBCDDDDDEEEEEEE...
  //
  // A - bytes 0-0   integer portion of field x (range: 0-9)
  //     (done this way because we can not represent a decimal number exactly)
  //
  // B - bytes 1-5   decimal portion of field x (range: 00000-99999 to represent 0.00000-9.99999)
  //     (done this way because we can not represent a decimal number exactly)
  //
  // C - bytes 6-6   integer portion of field y (range: 0-9)
  //     (done this way because we can not represent a decimal number exactly)
  //
  // D - bytes 7-11  decimal portion of field y (range: 00000-99999 to represent 0.00000-9.99999)
  //
  // E - bytes 12-18 discount rate (range: 0.00000-9.99999)
  // ...
  public class Xyz {

    public class Data {
       private double ab;
       private double cd;
       private double e;
       // ...

       public Data(double ab, double cd, double e /* ... */ ) {
         this.ab = ab;
         this.cd = cd;
         this.e  = e;
         // ...
       }

       public double getAB() { return ab; }
       public double getCD() { return cd; }
       public double getE()  { return e;  }
       // ...
    }

    public String createDataToWriteToFile(List<Data> list) {
      DecimalFormat df1 = new DecimalFormat("0.00000");
      DecimalFormat df2 = new DecimalFormat("00000");
      DecimalFormat df3 = new DecimalFormat("0");

      StringBuilder sb = new StringBuilder();

      for (Data d : list) {
          String s = df3.format(Math.floor(d.getAB())) + 
                     df2.format((d.getAB() - Math.floor(d.getAB()))*100000) +
                     df3.format(Math.floor(d.getCD())) + 
                     df2.format((d.getCD() - Math.floor(d.getCD()))*100000) +
                     df1.format(d.getE());
          sb.append(s);
          sb.append("\r\n");
      }

      return sb.toString();
    }
  }

Call Me Ishmael

by in Feature Articles on

David E. and his peers were pirates back in the pioneering days of the wide open seas of the internet back in 1998. Their small group consisted of a few just-out-of-college adventurers and one slightly more seasoned manager. They sailed by the seat of their pants while writing a new product for their company. It was like sailing over the ocean, looking for something, but not knowing what...

The application they had cooked up looked promising, but the initial roll-out went... badly. It performed fine when they tested it-- but when clients started hitting it all at once, it choked. They felt as though they were locked in a pillory, and gleefully mocked by David's boss's arch nemesis-- let's call him Ahab. Ahab swaggered into the review and ripped at their design, convinced it would never work, all the while touting his own example. David's team had to concede that he was right, and re-factored a lot of their code. After all, Ahab was The Man!


Fixing Delphi

by in CodeSOD on

Delphi has a rounding function that uses bankers' rounding instead of mathematical rounding, which can cause issues in mathematical applications. Throughout the years, folks have used numerous solutions, frequently rewriting the round function to use mathematical rounding, or else adding both a bankers rounding function and a mathematical rounding function to allow for both methods. These have typically been only a few lines long.

Paul M. was upgrading some legacy code when he happened upon a unique solution to "fix" the Delphi rounding issue:


Exceptionally Hard to Swallow

by in CodeSOD on

Does a tree make a sound if it falls in the woods and there's nobody there to hear it?

B. M.'s coworker was the stuff of which legends are made; code was always delivered ahead of schedule and it never threw an error. Her code was the least buggy in the entire department, and so became the standard against which all other code was measured.