4 ms·
Ask HN: What languages include implicit condition checking?
Not even sure if I'm using the right name. I've been doing a lot of precondition / type checking in PHP, and it occurred to me that it might be a cool language feature to bake into a language. For example, perhaps I could write `$i = count($keys) = count($values)` if I want $i to be set only on the conditions that $keys and $values are equi-lengthed array. An more advanced implementation could include auto checking a function's inputs, based on some set of rules defined in syntax or comments.
- Spoom 12y agoI know it's not exactly the same, but couldn't you achieve the same thing with getters and setters? http://www.php.net/manual/en/language.oop5.overloading.php#object.set http://www.php.net/manual/en/language.oop5.overloading.php#o...
- jtfairbank 12y agoYes and know, I'm mostly doing this in the constructor and some creation functions that call the constructor, not so much when the variables themselves are changed. Great link though! :)
- berdario 12y agoIf what you're thinking is the so called Design by Contract (using preconditions and postconditions), there are plenty of languages with that feature: The original one is Eiffel, if I'm not mistaken: http://en.wikipedia.org/wiki/Precondition#Eiffel_example http://en.wikipedia.org/wiki/Precondition#Eiffel_example Clojure: http://blog.fogus.me/2009/12/21/clojures-pre-and-post/ http://blog.fogus.me/2009/12/21/clojures-pre-and-post/ Ada 2012, apparently: http://www.adacore.com/uploads/technical-papers/Ada2012_Rationale_Chp1_contracts_and_aspects.pdf http://www.adacore.com/uploads/technical-papers/Ada2012_Rati... The slightly lesser known Cobra: http://cobra-language.com/trac/cobra/wiki/Contracts http://cobra-language.com/trac/cobra/wiki/Contracts (of these, I only ever wrote Clojure, and I've used a couple preconditions in production, I definitely like the concept)
- jtfairbank 12y agoThanks for the name and links!