Replies: 6 comments 5 replies
-
Your both basic assumptions are wrong, so the rest is just the result of wrong assumptions.
That's wrong. Many UI's are dynamic, not static. Dialogs are created and closed, editors are opened and closed etc. All non trivial UI code usually has some tasks that should be done asynchronous (listeners, jobs etc). All these are calling back to UI that can be not there anymore because user decided to close dialog / editor / switch off some toggle etc.
Throw an exception, as it is done today.
Wrong again. If you don't do anything in a non-trivial code, you might not notice that the "XYZ" button didn't do anything useful because the respective UI element was disposed meanwhile. Today, if you done your work right, user will get an error dialog saying that XYZ operation failed, or at least and "unhandled execution error in the log"...
Wrong impression. As said, UI's aren't always static and only dispose on shutdown. |
Beta Was this translation helpful? Give feedback.
-
When i call setText(s) i would expect getText() to return s. That contract would be broken with silent ignoring calls. I prefer to get the code fixed avoiding calls to already disposed widgets. |
Beta Was this translation helpful? Give feedback.
-
I think the net effect would be fewer visible "widget is disposed" errors. But what does that bring? How much development effort would be saved? Somehow, we can also wonder why Java sends a NullPointerException instead of just being silent. |
Beta Was this translation helpful? Give feedback.
-
I think the direction "rethink the dispose check" will go down a long and frustrating path that you won't like and that no one else will like. It's likely one of those things that everyone will find frustrating including and perhaps especially you. And of course, as @mickaelistria suggests, it's in the API
So this is simply water under the bridge and there is no pushing the water back upstream to the year 2000 to set it on a different course... |
Beta Was this translation helpful? Give feedback.
-
The typical usecase of isDisposed should be eager stop work on something that is not visibly anymore anyway |
Beta Was this translation helpful? Give feedback.
-
An action on an UI control leads to tons of side effects - listeners are called, focus is shifted, scroll moved, data updated etc. The assumption is that unless an exception is thrown, all side effects have completed successfully. This will no longer be the case without disposal checks - some side effects would be quietly skipped. This can't be worked around in Java code as some side effects are processed by windowing system. |
Beta Was this translation helpful? Give feedback.
-
Considerable effort in client code is taken to check for disposal, and also there is again check in the code is self for handling a case that is (at least for me and others I talked about it) rather strange:
So what I'd like to discuss here is if we should not relax the rules and simply allow widgets to do exactly this (e.g. JFace do it on some places) to check but ignore the disposal.
Lets assume a very basic example of a the 'Label#setText` (quite common also for shells, text, buttons,...) it is currently implemented as (for gtk):
and corresponding getter:
So why not simply change it to
It is often argued that this might "hide" errors, but I always asking how is something like
any better?
Won't I notice the bug (if there is any) even better in the UI because my label is not shown than I ever could by the disposal checks? Do we really help the developer here? My impression is that most of these missing disposal checks are not discovered at development time but on runtime in situations where e.g there is something shutting down, an event is getting late and I actually can't do anything and it is not an programming error at all (unless I want to write a program that has one strict linear workflow).
Beta Was this translation helpful? Give feedback.
All reactions