I've struggled for the last couple of months to come up with some clean code to report progress to a user. Everything always seems to boil down to:
ReportProgress("Starting Task 1");
doTask1();
ReportProgress("Task 1 is done");
ReportProgress("Starting Task 2");
doTask2();
ReportProgress("Task 2 is done");
//etc... where report progress does some form of output to the user.
The good coder in me screams "There's got to be a cleaner way!" But I'm stumped. Any thoughts?
EDIT :: I'm looking more for information on architectural information as opposed to implementation specific. The code given is very oversimplified.
The following characteristics of clean code are what make it easy to read: The entire application's order of execution is logical and clearly structured. The connection between different parts of the code is quite obvious. The task or role of each class, function, method, and variable is immediately understandable.
Clean code is a reader-focused development style that produces software that's easy to write, read and maintain. Often, you may be tempted to consider your work complete when the application operates as expected. But we're not merely writing code for computer consumption.
When we talk about clean code, we talk about a reader-focused development style that produces software that's easy to write, read, and maintain. Clean code is code that is easy to understand and easy to change. The word “clean” has become very trendy nowadays if you look at design, photography, etc.
set up your tasks as an event stream, and have the event-processing 'engine' report progress. Each event instance can have its own name, progress-reporting blurb/template, etc. if you want to go that far
if this is a pattern that occurs often, it is worth the effort for the infrastructure. When you're done, the usable code might look something like:
EventQueue tasks = new EventQueue();
tasks.Add(new TaskEvent(this.doTask1,"Foo-ing the bar"));
tasks.Add(new TaskEvent(this.doTask2,"Bar-ing the foo"));
tasks.Add(new TaskEvent(this.doTask3,"Glitching and whinging"));
...
tasks.Execute(this.ProgressEventHandler);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With