We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexSuggestions & BugsSoftware,  Documentation,  Website Suggestions › Easier code reuse in Processing
Page Index Toggle Pages: 1
Easier code reuse in Processing (Read 2771 times)
Easier code reuse in Processing
Jun 28th, 2008, 1:11pm
 
I discovered Processing some months ago, but at start, I only tweaked some existing code.
Then I started more ambitious stuff, and being a Java programmer, I found myself writing classes to encapsulate stuff, reuse code and ease animation.
I finally found that I can split a sketch in several files, Java or PDE kind. Or write a library, to package in a jar file.
The later is a bit heavy, particularly in the early stages of development, when the classes are not finalized.
The former is frustrating: if I write a generic class and want to use it in several sketches, I have to copy it in each and every project (sketch).
For example I made a class to draw a parametrized stylized heart, and I want to use in a static sketch (to show side by side various settings), to animated it (changing settings in real time), etc. Several different sketches, so I have to copy the Heart class in each.

I am aware that Processing aims at beginners, which don't need advanced features like namespace/packages and nightmares like classpath...
But beginners evolve and improve, and eventually need more flexibility and code reuse. It would be nice to support some optional simple form of library.

My idea is to define a special library folder. For example, make a folder with an arbitrary name in the sketch folder (eg. $classes, using $ to reduce risk of clashing with user defined sketch name) and/or define in the settings where such folder should go.
There, you could define class files (.java and .pde files) at the root or in sub-folders, thus allowing kind of packages.

Then in a .pde file, we could define at the start something like:

include shapes.nonabstract.Heart;

If in shapes/nonabstract/ folder we have Heart.java, it would be included outside of the Processing class. If we have Heart.pde, it would be included in the class. (Or always in the class, if it makes more sense.)

It would need a bit more pre-processing: parsing the path, managing the imports of the library class if any, to move them at the start of the main .pde file, etc. But it might be worth the effort.
Re: Easier code reuse in Processing
Reply #1 - Aug 6th, 2008, 3:30pm
 
I think this could be quite useful - I definitely would use it. just that one step simpler than creating libraries...
Re: Easier code reuse in Processing
Reply #2 - Oct 7th, 2008, 7:03pm
 
This is exactly what I've been looking for.  Promote! Wink
Re: Easier code reuse in Processing
Reply #3 - May 23rd, 2010, 5:14am
 
Indeed! Bump! Smiley

And upon this suggestion, it would be great if you'd configure Processing to open certain of these librarish pde's in new tabs on any new sketch creation.

It'd be great if you wouldn't need to wrap those into classes, because I really disliked how I used my real custom library that wrapped my standard functions:

import rapatski.functions.*
Functions f;

f = new Functions(this);

f.dottedLine(0, 0, 300, 300, 2, 1.3);

etc.
Page Index Toggle Pages: 1