What's the best way to minimize the need of run time checks?

BartC bc at freeuk.com
Fri Aug 12 05:38:48 EDT 2016


On 12/08/2016 09:38, Marko Rauhamaa wrote:
> Lawrence D’Oliveiro <lawrencedo99 at gmail.com>:
>
>> With static languages, once a piece of code compiles without errors,
>> you have a slightly higher level of confidence in its correctness than
>> with a dynamic language.
>>
>> On the other hand, a dynamic language allows me to be much more
>> productive, because I have to write less code to begin with.

You can be too dynamic. Take an example like this:

  class date:
      def __init__(self,d,m,y):
          self.day=d
          self.month=m
          self.year=y

  d=date(25,12,2015)

  d.yaer=1999

  print (d.day,d.month,d.year)

'year' has been spelled wrongly, but this error is not picked up by the 
byte-code compiler and will not immediately be detected at runtime 
either. It will be seen in my example only if someone notices the 
printout isn't what it should be.

This would never get past a static language nor some that also have 
dynamic types.

-- 
Bartc





More information about the Python-list mailing list