Re: Why no type hints for built-in types?
Berislav Lopac wrote:[color=blue]
> Terje Slettebø wrote:[color=green]
> > "Terje Slettebø" <tslettebo@hotm ail.com> wrote in message
> > news:41f69cfd$1 @news.broadpark .no...[color=darkred]
> >>
> >> The problem with "too eager" conversion - which also happens in C,
> >> even though it may be a little more dangerous, and a little safer,
> >> than PHP, anyway (more dangerous in that you may use invalid[/color][/color][/color]
casts,[color=blue][color=green][color=darkred]
> >> getting nonsense results - much of this has been fixed in C++, and
> >> more safe in that it does have a kind of strong typing - you have[/color][/color][/color]
to[color=blue][color=green][color=darkred]
> >> explicitly convert between numbers and strings, for example).[/color]
> >
> > I see I never finished that sentence. :) So to finish it:
> >
> > is that it may mask errors or make them harder to diagnose, such as
> > passing an object to a function expecting a number, and it "bombs
> > out" inside the function, somewhere, with perhaps hardly any clue[/color][/color]
to[color=blue][color=green]
> > what the actual error was, rather than getting an error at the
> > function call about type mismatch. A more dangerous version is to
> > silently get wrong results, such as the function returning null,
> > which then gets converted to 0, and everything looks just fine....[/color]
>
> You are absolutely correct. But this take us back to the issue of
> strongly-typed vs. weakly-typed languages. PHP is a weakly-typed[/color]
language,[color=blue]
> just like Python, Perl or Smalltalk (the paramount OO language), and[/color]
you[color=blue]
> should get used to that.
>
> And weakly-typed languages, just for the reasons you mentioned,[/color]
benefit the[color=blue]
> most from TTD, so use that if you have a problem with weak types.[/color]
Yes, tests certainly help, regardless of language. However, I still
feel this is complementary to automatic type-checking, as there's a
large class of errors that may be caught by the compiler/runtime
(type-related errors), so that you may concentrate on testing more
high-level things.
When I've been doing C++, it's often been the case that when a program
finally compiles without errors, it's correct, too. In PHP, that a
source file parses successfully, doesn't mean a lot...
Regards,
Terje
Berislav Lopac wrote:[color=blue]
> Terje Slettebø wrote:[color=green]
> > "Terje Slettebø" <tslettebo@hotm ail.com> wrote in message
> > news:41f69cfd$1 @news.broadpark .no...[color=darkred]
> >>
> >> The problem with "too eager" conversion - which also happens in C,
> >> even though it may be a little more dangerous, and a little safer,
> >> than PHP, anyway (more dangerous in that you may use invalid[/color][/color][/color]
casts,[color=blue][color=green][color=darkred]
> >> getting nonsense results - much of this has been fixed in C++, and
> >> more safe in that it does have a kind of strong typing - you have[/color][/color][/color]
to[color=blue][color=green][color=darkred]
> >> explicitly convert between numbers and strings, for example).[/color]
> >
> > I see I never finished that sentence. :) So to finish it:
> >
> > is that it may mask errors or make them harder to diagnose, such as
> > passing an object to a function expecting a number, and it "bombs
> > out" inside the function, somewhere, with perhaps hardly any clue[/color][/color]
to[color=blue][color=green]
> > what the actual error was, rather than getting an error at the
> > function call about type mismatch. A more dangerous version is to
> > silently get wrong results, such as the function returning null,
> > which then gets converted to 0, and everything looks just fine....[/color]
>
> You are absolutely correct. But this take us back to the issue of
> strongly-typed vs. weakly-typed languages. PHP is a weakly-typed[/color]
language,[color=blue]
> just like Python, Perl or Smalltalk (the paramount OO language), and[/color]
you[color=blue]
> should get used to that.
>
> And weakly-typed languages, just for the reasons you mentioned,[/color]
benefit the[color=blue]
> most from TTD, so use that if you have a problem with weak types.[/color]
Yes, tests certainly help, regardless of language. However, I still
feel this is complementary to automatic type-checking, as there's a
large class of errors that may be caught by the compiler/runtime
(type-related errors), so that you may concentrate on testing more
high-level things.
When I've been doing C++, it's often been the case that when a program
finally compiles without errors, it's correct, too. In PHP, that a
source file parses successfully, doesn't mean a lot...
Regards,
Terje
Comment