OT: This Swift thing

Marko Rauhamaa marko at pacujo.net
Thu Jun 5 17:53:44 EDT 2014


Mark Lawrence <breamoreboy at yahoo.co.uk>:

> On 05/06/2014 21:07, Alain Ketterlin wrote:
>> Sturla Molden <sturla.molden at gmail.com> writes:
>>> On 05/06/14 10:14, Alain Ketterlin wrote:
>>>> Type safety.
>>> Perhaps. Python has strong type safety.
>> Come on.
>
> I don't understand that comment, please explain.

I guess what is referred to is static typing. It serves two purposes:

 1. It makes the managers of software development teams believe the
    junior developers in their teams won't be able to do too much damage
    as the compiler at least enforces some rigor in the code. Hence,
    "safety."

 2. It makes it much easier to automatically optimize the code.

Unfortunately, it also has serious downsides:

 3. The code becomes very tedious to type in. You may need hundreds of
    lines of boilerplate code before it actually does anything. It also
    easily makes you lose your focus.

 4. The flow of the code becomes hard to understand because of the
    boilerplate. Ironically, the very straitjacket that seeks to force
    good quality on you prevents you from seeing the forest for the
    trees.

Example:

    
    Map<StreetAddress, ZipCode> makeStreetAddressMap(
        List<StreetInfo> infoList) {
        Map<StreetAddress, ZipCode> map =
            new HashMap<StreetAddress, ZipCode>();
        for (StreetInfo info : infoList)
             map.put(info.getStreetAddress(), info.getZipCode());
        return map;
    }

vs

   def make_street_address_map(info_list):
       map = {}
       for info in info_list:
            map[info.get_street_address()] = info.get_zip_code()
       return map

or:

   def make_street_address_map(info_list):
       return dict((info.get_street_address(), info.get_zip_code())
                   for info in info_list)


Marko



More information about the Python-list mailing list