Is there any trick to navigate on other page through synchronous process?
I'm guessing this is linked to your other question (http://stackoverflow.com/questions/4593463/about-synchronized-navigation).
Synchronous process are (generally) bad for perceived performance. This perception is amplified on mobile diveices (such as phones).
Because of this, most operations on WP7 happen asynchronously. As a general rule you should learn to work with this behaviour rather than against it as it's there for a reason.
If you have a specific issue where you wish to perform an operation synchronously then post the specific details and we'll advise accordingly.
Related
I've just realised that the code I'm going through sometimes uses load/DOMcontentloaded events and sometimes uses the onreadystatechange event.
I'm trying to uniformize it but I really don't know which one is better (I'm thinking about performance and resource use for mobile).
The only difference I can see is that onreadystatechange always applies to document and load/DOMcontentloaded is applied to window/document.
Does this mean that the way browsers implement them is different and matters or is this just a "too much" engineered question?
I am developing a web application with a somewhat complex user interface. It seems like it might be a good idea to back the UI with a corresponding state machine, defining the transitions possible between various states and the corresponding behavior.
The perceived benefits are that the code for controlling the behavior is structured consistently, and that the state of the UI can be persisted and resumed easily.
Can anyone who has tried this lend any insights into this approach? Are there any pitfalls I need to be aware of?
Off the top of my head, these are a bit obvious, but still, as nobody replied anything:
i'd advise to persist the state of the application server side, indexed via a session variable/user id for security and flexibility reasons;
interfaces are better modeled by an event-based approach IMHO, but this is a bit dependent on what layer of the UI you're developing, and also on your language of choice for development. You may be able to store some logic on item triggers and items themselves.
By event-based approach, i refer somewhat to this technique, which some "more visual" oriented environments (adobe flex, oracle forms and also html, in a sort of limited fashion) use. In a nutshell, you have triggers (item.on_click, label.on_mouse_over, text_field.on_record_update) which you use to drive the states of the interface.
One very common caveat of this kind of approach (distributed control) is endless loops: you have an item that enables another item, which when enabled fires its own triggers and eventually gets the first item to fire that same trigger again. This is quite often not obvious when developing, but very common to detect when testing.
Some languages/environments offer some protection against the more obvious cases, but this is something to be on the lookout for.
This is probably useful for your approach.
In this MSO bug report, our very own waffles makes the following observation:
This bug also happens to be a heisenbug, when debugging it if your first breakpoint is too early, stepping through shows that everything is good.
(Ref: Wikipedia's entry on Heisenbugs)
How is it even possible for the location of a breakpoint make a difference in whether a bug appears?
(Yes, I know the Wikipedia article answers this, but I thought it'd be a good question for SO to have the answer to, and I bet SO can do better anyways.)
If there is any kind of asynchronous activity going on then this could affect heisenbugs. e.g. threads, I/O, interrupts, etc. Setting breakpoints in different locations would affect the relative timing of the main thread and the asynchronous events which could then potentially result in related bugs either showing up or disappearing.
A common source is timing, in particular with multiple threads.
Lets say you have a GUI app with some event handlers and a bug where a table selection is not handled correctly, perhaps because Swing sometimes start updating the table before your event is handled.
By pausing a thread at a breakpoint, you may change the order in which the table component receives events and thus you might see a different outcome with and without the breakpoint. It's a very common problem, and one of the things that can make debugging complex GUI apps with lots of events really painful.
When a long-running process is being executed, it is a good practice to provide feedback to the user, for example, updating a progress bar.
Some FAQs for GUI libraries suggest something like this:
function long_running_progress()
do_some_work()
update_progress_bar()
while finish
do_some_work()
update_progress_bar()
end while
end function
Anyway, we know it is a best practice to separate business logic code from user interface code. The example above is mixing user interface code inside a business logic function.
What is a good technique to implement functions in the business logic layer whose progress could be easily tracked by an user interface without mixing layers?
Answers for any language or platform are welcome.
Provide a callback interface. The business logic will call its method every once in a while. The user layer will update the progress or whatever. If you want to allow cancellation – no problem, let the callback method have a return value which will indicate a need for cancellation. This will work regardless of number of threads.
If you used a MVC paradigm you could have the Model publish its current progress state as a property, the Controller could extract this every x seconds and then put it into the view. This assumes multi-threading though, which I'm not sure if you allow.
Publishing is a great way to go. It all depends on the platform how this is done. However, when it comes to the user experience there are a couple of things to consider as well:
Don't give the user a progress bar if you don't know how long the task is executing. What time is left? What does half-way mean? It's better to use hour-glass functionality (spinning wheels, bouncing progress bars, etc).
The only interesting thing to view progress on is time; what does Half-way in a process mean? You want to know if you got time for that cup of coffee. If you show other things you are probably displaying the workings of the system programming. Most users are not interested or just get confused.
Long running progress should always support the user with an escape, a way to cancel the request. You don't want to lock up the user for long time. Better still is to handle a long running request completely in the background and let the user get back when the result is back.
I have some forms that communicate with server using AJAX for real reasons: cascade combos, suggestions, multiple correlated selections (e.g. I have {elementary} knowledge of {French} [add], and {good} knowledge of {German} [add]...). I also have some regular fields that I handle trough get.
Thing is that once I've made connection to server-side, it would be easier to me to push all data that way. Is it going too far? What about if I have no reason for AJAX in the first place, and I still use it for pushing form data? I would feel obligated to provide fallback for people with javascript off, but most of the underlying logic would be the same, so it doesn't seam to me as an much of an overhead. It is a kind of data I would push through post anyway, so I'm not losing get parameters that would be good for something.
Any reason not to do things this way?
User experience is an important part of any software product. If you can improve the experience by providing better interactions, there's no reason not to do it.
Make sure though that you write unobtrusive and degradable javascript, so users with screen-readers or javascript-disabled browsers can still complete the interactions.
The only problem with this strategy is that you're in a lot deeper trouble if someone decides they want a non-javascript solution as well. I think it's fairly wise to use the "least fancy" mechanism that will get the desired result on the web. If it's just a form post, then keep it a form post unless there's a reason to do otherwise.