Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby and duck typing: design by contract impossible?
    primarykey
    data
    text
    <p>Method signature in Java:</p> <pre><code>public List&lt;String&gt; getFilesIn(List&lt;File&gt; directories) </code></pre> <p>similar one in ruby</p> <pre><code>def get_files_in(directories) </code></pre> <p>In the case of Java, the type system gives me information about what the method expects and delivers. In Ruby's case, I have <strong>no</strong> clue what I'm supposed to pass in, or what I'll expect to receive.</p> <p>In Java, the object must formally implement the interface. In Ruby, the object being passed in must respond to whatever methods are called in the method defined here. </p> <p>This seems highly problematic:</p> <ol> <li>Even with 100% accurate, up-to-date documentation, the Ruby code has to essentially expose its implementation, breaking encapsulation. "OO purity" aside, this would seem to be a maintenance nightmare.</li> <li>The Ruby code gives me <strong>no</strong> clue what's being returned; I would have to essentially experiment, or read the code to find out what methods the returned object would respond to.</li> </ol> <p>Not looking to debate static typing vs duck typing, but looking to understand how you maintain a production system where you have almost no ability to design by contract.</p> <h3>Update</h3> <p>No one has really addressed the exposure of a method's internal implementation via documentation that this approach requires. Since there are no interfaces, if I'm not expecting a particular type, don't I have to itemize every method I might call so that the caller knows what can be passed in? Or is this just an edge case that doesn't really come up?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload