Re: Bug in spinbox
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

Re: Bug in spinbox

From: Adrian Ho <tcl@03s.net>
Date: Sun Feb 26 2006 - 10:07:22 CET

On 2006-02-26, bgd <bgd73@verizon.net> wrote:
> "Ulrich Schöbel" <ulrich@outvert.com> wrote in message
> news:pan.2006.02.25.21.33.49.509055@outvert.com...
>>> foreach {day mon year} [clock format [clock seconds] -format "%e %B %Y"]
>
> Should it be
> foreach x {e B Y} y {day mon year} {
> set [set y] [clock format [clock seconds] -format %$x]
> }

No. Your code can return incorrect results if run during, say, 31 Dec
2006 23:59:59. Depending on when your Tcl instance processes each of
the three [clock seconds] commands, it could return any of the following:

  day=31 mon=December year=2006
  day=31 mon=December year=2007
  day=31 mon=January year=2007
  day=1 mon=January year=2007

Only the first and last are (obviously) acceptable, and Ulrich's code
will *always* return either of the two.

More importantly, Ulrich's code is *obviously correct*. Anyone with
basic Tcl experience can see that it takes a single timestamp, formats
it into a list-compatible string, and uses [foreach] to assign the
string-list's elements into the appropriate variables.

The logic in your code, however, is so obfuscated that I:

* spent at least a minute inspecting it to determine that the logic
  was at least similar to Ulrich's,

* actually felt the need to run your code in a tclsh to assure myself
  that my reasoning was correct, and

* only realized 5 minutes later that there's at least twelve corner
  cases each year (ie. the last second of every month) for which your
  code can return incorrect results

As a demonstration of just how flexible Tcl is, I applaud your attempt,
but frankly, if any of my co-workers tried to put something like that
in their code, I'd kick their posteriors with a steel-toed boot. IMO,
there's no place for that sort of contortion in a production environment.

- Adrian
Received on Sun Apr 30 02:15:55 2006