You are viewing a plain text version of this content. The canonical link for it is here.
Posted to rivet-dev@tcl.apache.org by "David N. Welton" <da...@dedasys.com> on 2002/10/18 04:09:16 UTC

How about "var get varname ?default?" ?

How about changing the semantics of "var get" to include a default
option?  Does this make sense?  Is there a better way of doing this,
such as scripting it in Tcl?

The potential problem is that people do var get foo {} and then check
to see if foo == "" for nonexistance, instead of doing [var exists
foo].  It might be worth the convenience in some cases, however.

What do you think?

-- 
David N. Welton
   Consulting: http://www.dedasys.com/
     Personal: http://www.dedasys.com/davidw/
Free Software: http://www.dedasys.com/freesoftware/
   Apache Tcl: http://tcl.apache.org/

---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org


Re: How about "var get varname ?default?" ?

Posted by "David N. Welton" <da...@dedasys.com>.
"David Brancato" <Da...@Brancato.com> writes:

> > I have gone ahead and backed out this change for now, due to
> > 'popular opinion'.

> Don't you mean 'consensus?'

That's what I'd like, but not enough people commented:-)  So I'll go
with what we got...

> Seriously though, how about in the future allowing scripters to turn
> on this level of strictness, per script?  Something akin to perl's
> "use strict" and VBScript's "Option Explicit" (but for
> form/querystring params)? That way scripters can choose which method
> they prefer.

Too ugly to do in C, I think.  I'd rather just "raw commands" that
throw errors, and "wrapped commands" that catch{} the raw command, and
let you know if anything went wrong.

-- 
David N. Welton
   Consulting: http://www.dedasys.com/
     Personal: http://www.dedasys.com/davidw/
Free Software: http://www.dedasys.com/freesoftware/
   Apache Tcl: http://tcl.apache.org/

---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org


Re: How about "var get varname ?default?" ?

Posted by David Brancato <Da...@Brancato.com>.
----- Original Message -----
From: David N. Welton <da...@dedasys.com>
>
> I have gone ahead and backed out this change for now, due to 'popular
> opinion'.
>
Don't you mean 'consensus?' Seriously though, how about in the future
allowing scripters to turn on this level of strictness, per script?
Something akin to perl's "use strict" and VBScript's "Option Explicit" (but
for form/querystring params)? That way scripters can choose which method
they prefer.

- David Brancato



---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org


Re: How about "var get varname ?default?" ?

Posted by "David N. Welton" <da...@dedasys.com>.
I have gone ahead and backed out this change for now, due to 'popular
opinion'.

So, 'var get foo' returns "" even if foo doesn't exist.

-- 
David N. Welton
   Consulting: http://www.dedasys.com/
     Personal: http://www.dedasys.com/davidw/
Free Software: http://www.dedasys.com/freesoftware/
   Apache Tcl: http://tcl.apache.org/

---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org


Re: How about "var get varname ?default?" ?

Posted by "David N. Welton" <da...@dedasys.com>.
Damon Courtney <da...@your.unreality.com> writes:

>     Sorry, I thought it was resolved, so I hadn't been following the
> thread.  What is the vote now?  To error out if [var get] doesn't
> get a variable?

I'd prefer to think of it as 'consensus', but... yeah:-)

Until yesterday, it returned "" if the variable didn't exist.  In some
ways, it would be more correct to error out, but maybe less
convenient.  It's not critical, because in any case, var exists can
always provide the answer.

-- 
David N. Welton
   Consulting: http://www.dedasys.com/
     Personal: http://www.dedasys.com/davidw/
Free Software: http://www.dedasys.com/freesoftware/
   Apache Tcl: http://tcl.apache.org/

---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org


Re: How about "var get varname ?default?" ?

Posted by Damon Courtney <da...@your.unreality.com>.
> Ok, we have two (also Makoto SATOH) against erroring out.
> 
> I think that, conceptually, it's more correct, but var exists can
> always be the determining factor.  And people could always get the old
> value by adding the default "".  I think that in some cases, it's
> better to get an error than incorrect information...
> 
> In either case, it'a always *possible* to be sure by looking at
> 'exists', so if people feel that it's better, I will go along and
> change it back to not erroring out.
> 
> Damon, you have any thoughts on this?

    Sorry, I thought it was resolved, so I hadn't been following the
thread.  What is the vote now?  To error out if [var get] doesn't get
a variable?

D


---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org


Re: How about "var get varname ?default?" ?

Posted by "David N. Welton" <da...@dedasys.com>.
Ok, we have two (also Makoto SATOH) against erroring out.

I think that, conceptually, it's more correct, but var exists can
always be the determining factor.  And people could always get the old
value by adding the default "".  I think that in some cases, it's
better to get an error than incorrect information...

In either case, it'a always *possible* to be sure by looking at
'exists', so if people feel that it's better, I will go along and
change it back to not erroring out.

Damon, you have any thoughts on this?

-- 
David N. Welton
   Consulting: http://www.dedasys.com/
     Personal: http://www.dedasys.com/davidw/
Free Software: http://www.dedasys.com/freesoftware/
   Apache Tcl: http://tcl.apache.org/

---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org


Re: How about "var get varname ?default?" ?

Posted by David Brancato <Da...@Brancato.com>.
----- Original Message -----
From: David N. Welton <da...@dedasys.com>

> Hrm, does it make sense to throw an
> error instead of returning ""?  For some reason, I thought it did:-) I
> actually think that that is more correct, because "" really means
> foo=&bar=baz - an empty value.  Any objections?  If people want the
> default empty value, they can put it in:-)
>

Personally, I'm against erroring on this. I think the convenience of having
it return "" is well worth it. Otherwise, scripters the world over will end
up typing [var get foo ""] for everything that doesn't have a default
value just so they don't have to worry about triggering an error. In this
sense, the default value is no longer optional. Plus, most major scripting
environments don't error on this (CGI.pm, PHP, ASP). I know that alone is no
reason but I think in this case they all weighed convenience vs. more
correct. Rivet atleast has [var exists foo] if the scripter needs that level
of control.

- David Brancato






---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org


Re: How about "var get varname ?default?" ?

Posted by "David N. Welton" <da...@dedasys.com>.
davidw@dedasys.com (David N. Welton) writes:

> "David Brancato" <Da...@Brancato.com> writes:

> > Definitely makes sense to add this convenience and to add it in C.

> Ok, should have it shortly.

Done.

-- 
David N. Welton
   Consulting: http://www.dedasys.com/
     Personal: http://www.dedasys.com/davidw/
Free Software: http://www.dedasys.com/freesoftware/
   Apache Tcl: http://tcl.apache.org/

---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org


Re: How about "var get varname ?default?" ?

Posted by "David N. Welton" <da...@dedasys.com>.
"David Brancato" <Da...@Brancato.com> writes:

> Definitely makes sense to add this convenience and to add it in C.

Ok, should have it shortly.

> > The potential problem is that people do var get foo {} and then
> > check to see if foo == "" for nonexistance, instead of doing [var
> > exists foo].  It might be worth the convenience in some cases,
> > however.
 
> That's what [var exists] is for, I'll say. You didn't code it for
> nuthin :)

> And no one'll do [var get foo {}] because that's what [var get foo]
> already does (and would continue to do, I assume). Unless I
> misunderstood what you're saying.

Oops, yeah, now I remember that.  Hrm, does it make sense to throw an
error instead of returning ""?  For some reason, I thought it did:-) I
actually think that that is more correct, because "" really means
foo=&bar=baz - an empty value.  Any objections?  If people want the
default empty value, they can put it in:-)

-- 
David N. Welton
   Consulting: http://www.dedasys.com/
     Personal: http://www.dedasys.com/davidw/
Free Software: http://www.dedasys.com/freesoftware/
   Apache Tcl: http://tcl.apache.org/

---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org


Re: How about "var get varname ?default?" ?

Posted by David Brancato <Da...@Brancato.com>.
----- Original Message -----
From: David N. Welton <da...@dedasys.com>
Subject: How about "var get varname ?default?" ?


>
> How about changing the semantics of "var get" to include a default
> option?  Does this make sense?  Is there a better way of doing this,
> such as scripting it in Tcl?

Definitely makes sense to add this convenience and to add it in C.


>
> The potential problem is that people do var get foo {} and then check
> to see if foo == "" for nonexistance, instead of doing [var exists
> foo].  It might be worth the convenience in some cases, however.

That's what [var exists] is for, I'll say. You didn't code it for nuthin :)

And no one'll do [var get foo {}] because that's what [var get foo] already
does (and would continue to do, I assume). Unless I misunderstood what
you're saying.

- David Brancato



---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org