Re: New question on strings



On Feb 28, 7:44 am, Neil Madden <n...@xxxxxxxxxxxxx> wrote:
tom.rmadilo wrote:
OMG, is this another one of those regressions? I guess so. [Incr] now
auto initializes to zero if the variable doesn't exist.

See TIP 215

Right, from the TIP:

-------
There have been comments that incr modified as proposed would lose one
means of typo-detection: If the varname is mistyped, then instead of
throwing an error, it would turn into a noop.

My (TIP-originator) answer to this: relying on thrown exceptions for
mistyped varnames is a very weak strategy in dynamic (non-compiled)
languages like tcl, anyway, because it would require a 100%-test-
coverage of execution-paths.

--------

Of course, in the above code there was no mistyping of the variable
name! In addition, variables sometimes contain the name of the
variable to increment. The context needed to detect the intended
meaning of the above code could extend beyond the local context, or
the mistake will likely be embedded within a single line of code.

I really don't get the point of making the easiest possible thing
(initializing a variable) even easier. Who focuses on the easy stuff?
How many times have we seen code like this:

for {set i 0} {$i < 100} {incr $i} {
.....
}

This leads to instant failure in 8.4. In 8.5 we have the infinite
loop.

Here is an interesting example:

set i 1

while {[incr $i] < 100} {

set i [expr $i * 2]
}

If i starts out as 0, it returns instantly. If i starts as 1, you get
an infinite loop, and a memory exhausting memory leak, eventually your
computer will crash.
.