Wolfram Blog
Adam Berry

Boost Productivity: Leverage the Power and Flexibility of Workbench 2

March 25, 2010 — Adam Berry, Senior Kernel Developer

It happens to everyone—you spend forever digging around in your filesystem for the dataset you need to finish your work. But you can’t remember the name or enough about the contents to be able to search for it. Searching is wasted time, time that would be far better spent on productive tasks.

What users like myself really need is for our tools to reflect the way we actually work, and that’s where project-based workflows in tools like Wolfram Workbench come in.

When working with Mathematica, we need notebooks—some will contain rough work and some will be presentation material. We may also need some data and other forms of output, such as HTML for final delivery. So let’s walk through setting up a project, and some of the features that can enhance your workflow and improve your productivity.

First we need to create a Mathematica basic project, which will contain an empty .m file and a notebook. Workbench makes some additions to the configuration when it launches Mathematica; if we open the notebook and check the path, we see something similar to this:

Mathematica notebook paths as amended by Workbench

We can see here that the root of the project has been added to the path (it’s the second item in the output). Close the Mathematica session and return to Workbench. Opening the project properties and looking in the section yields some promising-looking settings for controlling the configuration:

Configuration controls in a Workbench project's properties

So we have a few tabs here that will be useful to us—Source, Palettes, and Stylesheets. As you have probably guessed, the Source tab is how we contribute entries to the path. By default just the root of the project is added, but as we add a structure to our work project we could add more things here. The options for adding palettes and stylesheets are great for managing resources that you may need for just this work, helping keep your Mathematica session clean both while working with this project and when in a normal session.

Now let’s add some additional structure to our project. We are going to be working with images, so a folder for them would make sense, and an output folder for manipulated images would be a good idea. We’ll add a couple of images into the originals folder. Additionally, lets make a folder for palettes, and add an Image Manipulation palette to it.

Workbench's Package Explorer, showing palettes

Now open the project properties again, and select the Palettes tab. Using the Add button we can select the Palettes folder in our project, which will now look like this:

Designating project-specific palettes in Workbench

It would be useful to add the original images folder to the path in project properties:

Adding to a project's path in Workbench

Finally, before we open Mathematica again, open the .m file and add the following and then save:

SetDirectory[Workbench`$WorkspaceDirectory &<><br />
 "/ImageManipulation/Images/Manipulated"]

Now launch Mathematica, by right-clicking on the notebook in Workbench and choosing Run As > Mathematica. Workbench will automatically set up the paths as before, and our SetDirectory call will be executed thanks to the auto-loading mechanism.

If we look in the Palettes menu in Mathematica, we will find our Image Manipulation palette, ready to be opened and used. It’s available to me when working on the images in this project, but does not crowd my environment the rest of the time.

Mathematica's Palettes menu, showing our project's palette

But what has all this bought us? Well now, if I want to import one of my images, I only need specify its name:

imageExpression=Import["eagle.jpg"]

Once I have completed my manipulations I can easily export. Thanks to setting the working directory, we do not need a full file path:

Export["eagle.jpg",newImage]

You will see this new image in the project structure. But once again, how has this helped? It has removed the need to use the file path insert dialog, and encourages you to organize what you are working on.

Both small gains to be sure, but when repeated over and over again, they add up to significant time savings and reduction of errors, increasing your efficiency. Add the use of the local history, or better yet a version control system like CVS or Subversion, and you make it easier to collaborate, as well as undo, when working on your projects.

This kind of feature is the very essence of modern IDEs: many small efficiency gains that stack up—taking time consuming, repetitive tasks (which computers are so good at) off your hands, freeing you up to solve the big problems—and you don’t even need to be doing development work to gain from them!

After all, if we don’t make computers do work for us, we might as well not use them at all. So why not try Workbench and start working better?

Leave a Comment

9 Comments


Mooniac

Hmmm … not that I am disputing any of this, but I think these are all relatively weak points (searching for a file, palettes, exporting into filesystem, …). There are MUCH stronger points that can be said about the WB and the productivity boost it provides: the editor itself, file outline view, the ability to write combined M/Java programs (and debug them together!), Run configurations, the Profiler, Eclipse integration, webM integration, paclet/documentation integration, …

Posted by Mooniac    March 26, 2010 at 9:13 am
Adam Berry

Thanks for the feedback. All of those points are already well addressed in the workbench documentation, screencasts and website. This is the first in a series of posts that will present using the workbench for something that isn’t directly documented, but can certainly help, even when not doing development work.

Posted by Adam Berry    March 26, 2010 at 9:46 am
Ludwig Weingarten

Hallo Adam Berry,

I’m really thankful for your contribution because I’m trying to find the benefits of using Workbench. I’ve been working with Developer Studio to program FORTRAN-Modules, but this has never been such a fun as programming in Mathematica. So, for me, using Workbench seems to be like a regression to some more uncomfortable obsolete methods, but I admit that this point of view must be prejudicial. So, please, go on to publish more on this subject and undermine my prejudice! And people like Mooniac who seem to have a better understanding might be polite and simply ignore those contributions which for their taste are to weak.

Sincerely

Ludwig Weingarten

Posted by Ludwig Weingarten    March 27, 2010 at 7:01 am
mathematicafan

Thanks for the blog entry. I hope you continue writing on efficient usage of Workbench (I started using Workbench 2.0 and am thoroughly impressed!).

Although a lot of stuff is documented, it is still not easy for users like me to fully appreciate it. I am particularly interested in how to create larger projects (with multiple .m files). The example code while good is still relevant for small scale applications. While documentation of individual bits and pieces is excellent, it is harder for me to see how to transition to really large projects of interest in industrial applications.

I do agree with the first commenter. Although, as you rightly pointed out a lot of stuff is in the docs, some repetition with a different perspective would be helpful. Personally, I prefer the videos over the Workbench docs (Mathematica docs are more mature, IMHO).

Anyway, please continue on the topic–Workbench makes it easier to generate powerful industrial applications remarkably well.

Posted by mathematicafan    March 28, 2010 at 7:23 am
George Wolfe

In contrast to Mooniac, I found the advantages discussed to be better reasons to use Workbench then Java, webM and paclet integration. I’ve written mostly Fortran, VB and VBA code until I started using Mathematica. I never used Eclipse, and I’ve been dubious about it’s advantages. It appears to be built around unit testing and other concepts that seem to me to have a low benefit to overhead ratio.

However, I have several multi-year Mathematica projects that are pretty complicated in terms of database access and input/output file use. I hadn’t thought about using Workbench to help manage that. It seems like it could be pretty helful. I wonder if many other people have been trying to find a reason to start using Workbench, but haven’t come up with one.

Posted by George Wolfe    March 28, 2010 at 1:51 pm
led lights

Thanks a lot for all of it.

Posted by led lights    April 1, 2010 at 1:44 am
淘宝点评网

great article!

good!

Posted by 淘宝点评网    April 5, 2010 at 10:34 am
Peter Čendula

Thanks for this blog entry. However, I get an error message with SetDirectory[Workbench`$WorkspaceDirectory"/ImageManipulation"] when I execute << ImageManipulation` . Context Workbench` seems to be not available to Front End.

I also share the view of mathematicafan that we'd need examples of transition to really large projects of interest in industrial applications.

thanks
peter

Posted by Peter Čendula    November 22, 2012 at 7:37 am
    Peter Čendula

    Correction:
    -make sure to put “SetDirectory[Workbench`$WorkspaceDirectory"/ImageManipulation/Images/Manipulated"];” in ImageManipulation.m file
    - right click ImageManipulation.nb and choose “Run as” -> Mathematica. This automatically load ImageManipulation.m and sets the directory.

    Posted by Peter Čendula    February 11, 2013 at 5:11 am


Leave a comment

Loading...

Or continue as a guest (your comment will be held for moderation):