Bools and explicitness [was Re: PyWart: The problem with "print"]

Rick Johnson rantingrickjohnson at gmail.com
Tue Jun 4 12:09:12 EDT 2013


On Jun 4, 10:44 am, Rick Johnson <rantingrickjohn... at gmail.com> wrote:

> What we need is a method by which we can validate a symbol
> and simultaneously do the vaidation in a manner that will
> cast light on the type that is expected. In order for this
> to work, you would need validators with unique "type names"
>
>     if var.is_validList():
>     elif var.is_validString():
>     elif var.is_vaildTuple():
>     elif var.is_validInteger():
>     elif var.is_validFloat():
>     elif var.is_validDict():
>     etc...

Actually, instead of forcing all types to have many "specific"
methods, one builtin could solve the entire issue. The function would
be similar to isinstance() taking two arguments "object" and "type",
however, it will not only guarantee type but also handle the
conversion to Boolean:

   if is_valid(var, list):
       # if this block executes we know
       # the var is of <type list> and
       # var.length is greater than one.
   else:
       # if this block executes we know
       # that var is not of <type list>
       # or, var.length equals zero.

The is_valid function would replace implicit Boolean conversion for
all types in manner that is "explicit enough" whilst maintaining
finger longevity. This is how you design a language for consistency
and readability.

Again. PUCKER UP WHO-VILLE!



More information about the Python-list mailing list