Ruby and duck typing: design by contract impossible?

后端 未结 8 1548
别那么骄傲
别那么骄傲 2020-12-14 09:16

Method signature in Java:

public List getFilesIn(List directories)

similar one in ruby

def get_fi         


        
8条回答
  •  佛祖请我去吃肉
    2020-12-14 09:41

    It's by no means a maintenance nightmare, just another way of working, that calls for consistence in the API and good documentation.

    Your concern seems related to the fact that any dynamic language is a dangerous tool, that cannot enforce API input/output contracts. The fact is, while chosing static may seem safer, the better thing you can do in both worlds is to keep a good set of tests that verify not only the type of the data returned (which is the only thing the Java compiler can verify and enforce), but also it's correctness and inner workings(Black box/white box testing).

    As a side note, I don't know about Ruby, but in PHP you can use @phpdoc tags to hint the IDE (Eclipse PDT) about the data types returned by a certain method.

提交回复
热议问题