

Ask HN: What languages include implicit condition checking? - jtfairbank

Not even sure if I&#x27;m using the right name.  I&#x27;ve been doing a lot of precondition &#x2F; 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&#x27;s inputs, based on some set of rules defined in syntax or comments.
======
berdario
If 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_Rati...](http://www.adacore.com/uploads/technical-
papers/Ada2012_Rationale_Chp1_contracts_and_aspects.pdf)

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
Thanks for the name and links!

------
Spoom
I 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#o...](http://www.php.net/manual/en/language.oop5.overloading.php#object.set)

~~~
jtfairbank
Yes 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! :)

