I hate ".dup"

Qian Xu quian.xu at stud.tu-ilmenau.de
Mon Mar 23 08:07:16 PDT 2009


I have spent one day to find out an error.

-----------------------------------------------------------------
class MyTime
{
  this(char[] timestring)
  {
     Time t;
     int p = tango.time.TimeStamp.iso8601(timestring, t);
     //...
  }
  // other methods
}
unittest
{
  MyTime mt = new MyTime("01:10:20,050");
  assert(MyTime.addMillis(mt, 1).toString() == "01:10:20,051"); // sometimes
failed
}
-----------------------------------------------------------------

I ran this unit-test together with some other tests. Sometimes no error,
sometimes with errors. 

Finally I have added timestring.dup in constructor, the problem does not
appear any more. 

Oh god. I have to add ".dup" at the end of every string to avoid potential
program errors. This is so incredible....


Best regards
Qian Xu


More information about the Digitalmars-d-learn mailing list