Bools and explicitness [was Re: PyWart: The problem with "print"]
Russ P.
Russ.Paielli at gmail.com
Thu Jun 6 14:08:52 EDT 2013
On Thursday, June 6, 2013 2:29:02 AM UTC-7, Steven D'Aprano wrote:
> On Thu, 06 Jun 2013 12:29:44 +1000, Chris Angelico wrote:
>
>
>
> > On Thu, Jun 6, 2013 at 11:56 AM, Steven D'Aprano
>
> > <steve+comp.lang.python at pearwood.info> wrote:
>
> >> On Wed, 05 Jun 2013 14:59:31 -0700, Russ P. wrote:
>
> >>> As for Python, my experience with it is that, as your application
>
> >>> grows, you start getting confused about what the argument types are or
>
> >>> are supposed to be.
>
> >>
>
> >> Whereas people never get confused about the arguments in static typed
>
> >> languages?
>
> >>
>
> >> The only difference is whether the compiler tells you that you've
>
> >> passed the wrong type, or your unit test tells you that you've passed
>
> >> the wrong type. What, you don't have unit tests? Then how do you know
>
> >> that the code does the right thing when passed data of the right type?
>
> >> Adding an extra couple of unit tests is not that big a burden.
>
> >
>
> > The valid type(s) for an argument can be divided into two categories:
>
> > Those the compiler can check for, and those the compiler can't check
>
> > for. Some languages have more in the first category than others, but
>
> > what compiler can prove that a string is an
>
> > HTML-special-characters-escaped string? In a very few languages, the
>
> > compiler can insist that an integer be between 7 and 30, but there'll
>
> > always be some things you can't demonstrate with a function signature.
>
> >
>
> > That said, though, I do like being able to make at least *some*
>
> > declaration there. It helps catch certain types of error.
>
>
>
> *shrug*
>
>
>
> I don't terribly miss type declarations. Function argument declarations
>
> are a bit simpler in Pascal, compared to Python:
>
>
>
>
>
> Function Add(A, B : Integer) : Integer;
>
> Begin
>
> Add := A + B;
>
> End;
>
>
>
>
>
> versus
>
>
>
>
>
> def add(a, b):
>
> if not (isinstance(a, int) and isinstance(b, int)):
>
> raise TypeError
>
> return a + b
>
Scala also has isInstanceOf[Type] which allows you to do this sort of thing, but of course it would be considered terrible style in Scala.
>
>
>
> but not that much simpler. And while Python can trivially support
>
> multiple types, Pascal cannot. (Some other static typed languages may.)
>
>
>
> Whatever benefit there is in declaring the type of a function is lost due
>
> to the inability to duck-type or program to an interface. There's no type
>
> that says "any object with a 'next' method", for example. And having to
>
> declare local variables is a PITA with little benefit.
>
>
>
> Give me a language with type inference, and a nice, easy way to keep duck-
>
> typing, and I'll reconsider. But until then, I don't believe the benefit
>
> of static types comes even close to paying for the extra effort.
Scala has type inference. For example, you can write
val x = 1
and the compiler figures out that x is an integer. Scala also has something called structural typing, which I think is more or less equivalent to "duck typing," although I don't think it is used very often.
Are you ready to try Scala yet? 8-)
More information about the Python-list
mailing list