Replies: 5 comments 4 replies
-
Beta Was this translation helpful? Give feedback.
-
Worth looking at other languages that support this https://en.wikipedia.org/wiki/Design_by_contract#Language_support and in particular, Java, which has many including https://en.wikipedia.org/wiki/Java_Modeling_Language. |
Beta Was this translation helpful? Give feedback.
-
Indicating what exceptions can be thrown and under what conditions can also be part of the contract. |
Beta Was this translation helpful? Give feedback.
-
Let's rename this discussion to |
Beta Was this translation helpful? Give feedback.
-
I'm sorry I haven't responded earlier. This has been a very busy month for me. Rather than juggle too many things, I put some balls down. That being said, now that I'm responding, I'm in an awkward state. Specifically, Damian and I have had Design by Contract (DBC) discussions before, but these were parts of private conversations we had, with no expectation of them going public, so I can't share everything, but they were generally along the lines of:
And then he'd kindly share with me a careful explanation of why my idea was bad. Design by Contract (DbC) was one of these discussions. DbC was not the bad thing, but I had a spectacularly bad idea about the implemementation of a related idea and Damian had to talk me off the ledge (though I was taking inspiration from the Beta programming langauge at the time, which probably explains why my idea was so bad). That conversation, however, sparked some ideas which led to the discussion of DbC and different approaches by different languages. What I can say about our conversation is that DbC works well in the context of Corinna, which was the crux of the discussion. DbC handles pre- and post-conditions, input and output data constraints, invariants, exceptions, etc., and is basically what it says on the tin: it's a contractual software guarantee for an exposed bit of software. It's also a heck of a lot of overhead and DbC systems are often only used in testing or development, but not on production, so there needs to be a way to ensure that not only are they easy to disable. There are also plenty of tricky bits with class composition, such as respecting Liskov, which contracts could theoretically verify, but many languages get this wrong. In short, considering DbC is great, but DbC for Oshun would be using a AK-47 Type 2A gas-operated assault rifle for killing a mosquito. It'll do the job, but I just swat 'em with my hand. Your mileage may vary. You also mention assertions and those seem a great fit here, but I'd probably open up any DbC discussion on Corinna because that is well within the scope of future work. For the DbC, one thing that struck me as interesting is that so many people have taken swipes at implementing DbC in Perl, but I can't find any evidence that anyone uses existing systems. I don't know if that's because they find the implementations clumsy or because they just don't like DbC. Or it could be that Perl devs do such a terrible job of writing OO code that it would be, um, hard to create a contract for many classes. However, for Perl+Corinna, here are some thoughts for that discussion:
Exceptions+Stack Traces would be a bit of a blocker. Without having them native, I suspect it would be awfully hard to specify that |
Beta Was this translation helpful? Give feedback.
-
Per a discussion on Facebook, I wrote the following as possible way to extend the idea of checks to the idea of contracts as defined by the Eiffel programming language:
Eiffel language created the concept of Design by Contract and it is a core part of the language design. https://www.eiffel.org/doc/eiffel/ET-_Design_by_Contract_%28tm%29%2C_Assertions_and_Exceptions. They unify a lot of different specifications of what a method does/guarantees into a single approach.
Ada has particular subsets/implementations that use Design by Contract in order use a prover to formally verify that the code follow certain kinds of contracts https://en.wikipedia.org/wiki/SPARK_(programming_language), https://archive.fosdem.org/2021/schedule/event/safety_opensource_ada_contracts/.
I understand if this is not within the scope of the MVP and have no idea how difficult this would be to do, but it would be nice to be open to this possibility. It would be nice if there were sets of these contracts as libraries that could help with, say, making sure code is portable across different OSes or that thread-unsafe constructs are used properly.
I know that there are libraries that implement some of these contract ideas on CPAN which means it is possible to add these dynamically to the language.
Beta Was this translation helpful? Give feedback.
All reactions