On 26/02/2016 16:37, Alexandre Bergel wrote:
...
With Pharo you cannot, if you assert or throw an error in a sensible place, you
are likely to hang your image or to go for multiple errors poping everywhere
since you will break the state of an important object.
I do not think so. It is like putting a "self halt” (or “Halt now”). It is all
done using exceptions.
Yes, that's the point: they are lots of places where you simply cannot
put self halt (timers, background processes - though in this case it
works... debugger magic :), window resizing, mouse events )
Another thing is that with dbc paradigm (assertions about your code), there is
no 'one invariant' but lots of, you will not be able to express them in a
single method, even if you could it would be hundreds lines and you would have
to copy them in all methods you will want to check.
The complete horror to maintain when you change your code.
I would not be that pessimistic.
Even if you write dedicated check methods to avoid pollute your code,
you will have to call all the logic of your controls in each method, and
decide for each one what checks are applicable or not.
Thinking about object state checks (invariants), I cannot imagine I'll
have to add a: 'self checkThatxxx' in all the methods of my class...
...
Sure, you can imagine a solution using pragmas, but sincerely, I do not think
it will be more flexible than using #assert:. Again, Java’s assertions are very
similar to what we have now. However, I am pretty convinced there are great
opportunities on writing assertions. It is really hard to write them, which is
why not many are doing so.
Thinking again about java asserts, they are more powerful framework who
do not use assert but comments which is like using pragmas.
http://www.javaworld.com/article/2074956/learn-java/icontract--design-by-contract-in-java.html
(they are plenty others, look at the end of
https://en.wikipedia.org/wiki/Design_by_contract in the language support)
In fact you are pointing to at the whole benefit of contracts when you
say that you can call assert or another method: of you own :
the good thing is that they are not linked to your code logic, they are
here to check things that you did not anticipate where they could
happen. You express what is correct for each method on entry, exit,
about the state of the object and the checks are injected into your code...
And you see this method that you would never have thought it could do
that in this improbable place ... :)
It is just a different way of checking that things are running ok under
the hood
Ah, and I am not against asserts or breakpoints, using contracts does
not forbid you to use assert:
... :)
--
Alain