Tuesday, March 26, 2013

The protocol of IProgressMonitor


Very nice write-up on this:
http://www.eclipse.org/articles/Article-Progress-Monitors/article.html
http://www.eclipse.org/articles/Article-Progress-Monitors/article.html#Ensure_to_always_complete_your_monitor


One contract pattern described above is that if beginTask() is ever called, done() MUST be called. This is achieved by always following this code pattern (all code is simplified):
monitor = … // somehow get a new progress monitor which is in a pristine state
// figure some things out such as number of items to process etc…
try
 {
 monitor.beginTask(…)
 // do stuff and call worked() for each item worked on, and check for cancellation
 }
finally
 {
 monitor.done()
 }

Tuesday, March 19, 2013

Javascript functions and difference



The two ways to declare a java script function:
var functionOne = function() {
    // Some code
};
function functionTwo() {
    // Some code
}


The difference is that functionTwo is defined at parse-time for a script block, whereas functionOneis defined at run-time. For example:
<script>
  // Error
  functionOne();

  var functionOne = function() {
  }
</script>

<script>
  // No error
  functionTwo();

  function functionTwo() {
  }
</script>