sharedCode - work in progress

It's not really a mode since it works for all modes, but it didn't fit any category. Anyway:

This is what I have so far:

Screen Shot 2014-12-24 at 11.24.42 AM

Looks pretty normal right? Just a library import. But this ain't no library import!

We import .pde or .java:

Screen Shot 2014-12-24 at 11.24.58 AM

This from your sketchbook in a folder "sharedcode". You can also import a folder:

import sharedcode.math.*;

I need to clean up my code. After that I will push it, and I hope it will be added to processing. The thing is that the precompiler takes care of this so I can't release this as a library or tool. Anyway, I really like it. I finally can add my methods and classes that I use a lot in a shared way. Which is also nice when discovering a bug.

Another great thing is that you can use folders to create versions.

import sharedcode.somecrazymethod.v01;

Which will load:

sharedcode/somecrazymethod/v01.pde (or .java)

Hope you guys like it! O yeah is the name sharedcode good?

Tagged:

Comments

  • i like the idea. it's much easier than to copy paste code that you need into your new sketch. And with copy paste you can't change t he code at once in all places you used it.

    anyway I am also interested in the code itself you find so useful. Could you post it here or over there in the groups wiki: http://portalsfordeveloping.wikia.com/wiki/Snippets

    sounds like a great repository / ressource.

    Thank you!

    Chrisir ;-)

  • I can add the snippets later. I have for example a class to sort a List of PVector in a lot of ways. Like XY, YX, XZ, ZX, ZY, YZ, XYZ, YXZ, ZYX, etc. But also sort it based to a distance to a specific point. This ascending and descending etc. (It's a bit more then a snippet it's a huge class lol :) ).

    This would be a good snippet:

    static public final float distSQ(float x1, float y1, float x2, float y2) {
        return sq(x2-x1) + sq(y2-y1);
     }
    

    I'm also thinking of making a website where people can register and upload snippets. Then the import could be like this:

    import sharedcode.org.chrisir.snippets.box;

    Where you could also visit the domain directly in your browser to watch the code.

    But that can take some time since I have other projects to finish first. Also that might need some safety checking, not that you change your box code to format my HD :)

    This could also be a nice step for people to make the gap to making a library smaller.

  • thanks!

    I figure distSQ is much faster than dist?

    our wiki is open to anybody, you can edit it

    ;-)

  • Yeah distSQ is faster but it gives the distance squared. It's usefull if you need to find the maximum for example but don't care about the distance in pixels. If you sqrt the result then you have the normal dist result. And someday soon I will edit the wiki :)

  • Nice idea - is the 'shared' code statically embedded into the sketch or is it dynamic?

  • What do you mean?

  • Static - the code is imported into the sketch folder on first use and never changes even if the shared code is updated.

    Dynamic - the code is imported every time the sketch is opened, so changes in the shared code are reflected in the sketch.

  • edited December 2014

    It's dynamic. The code get's imported at compile time and appended to the bottom off all code. So you can even edit the code while the sketch is open.

    Also, it doesn't work fine with experimental mode. Cause it can't find the library. Cause it's not a library... Worst thing is that experimental mode tells you this every second, so the console output goes on and on. I don't use experimental mode anyway, at it's current state it's to frustrating. But I might fix the issue so experimental mode ignores it. Or even better but more work, can make use of it.

    java.lang.StringIndexOutOfBoundsException: String index out of range: -1 at java.lang.String.substring(String.java:1875) at processing.mode.experimental.ErrorCheckerService.prepareCompilerClasspath(ErrorCheckerService.java:750) at processing.mode.experimental.ErrorCheckerService.checkCode(ErrorCheckerService.java:405) at processing.mode.experimental.ErrorCheckerService.run(ErrorCheckerService.java:292) at java.lang.Thread.run(Thread.java:745) Experimental Mode: Yikes! Can't find "sharedcode.common" library! Line: 1 in tab: sharedCodeTest Please make sure that the library is present in /libraries folder or in the code folder of your sketch java.lang.StringIndexOutOfBoundsException: String index out of range: -1 at java.lang.String.substring(String.java:1875) at processing.mode.experimental.ErrorCheckerService.prepareCompilerClasspath(ErrorCheckerService.java:750) at processing.mode.experimental.ErrorCheckerService.checkCode(ErrorCheckerService.java:405) at processing.mode.experimental.ErrorCheckerService.run(ErrorCheckerService.java:292) at java.lang.Thread.run(Thread.java:745)

Sign In or Register to comment.