Clean Coding in Grasshopper

I have suitable skin in this game as you might like to see in this thread:

On these multi thousand component scripts I’ve had to develop a discipline to prevent big piles of spaghetti.

Here are some screen shots of my latest project, just happened to be open on my desktop today.

So this one is 2600+ objects.

The rules:

#1 create subroutines - blocks of code that “Do One Thing” - what that one thing is depends on what the writer is doing, but these tend to be 10 to 50 function blocks. Subroutines are grouped, named and labeled with a scribble (use metahopper!!).

#2 All data into a subroutine on the left, All data out on the right, All data enters and exits via named parameters. No functional block is to have a connection outside of the subroutine! When built this way each subroutine is actually “cluster ready” though I find trouble shooting much easier with a “flat” canvas rather than having subroutines inside clusters.

Here is a subroutine example from the code above:

#3 Hide the wires going into (and by default also out of) a subroutine to keep the canvas tidy.

Here is what the code above would look like without the “inter subroutine wires” hidden:

Happy to go deeper into my work flow if you had questions.

Cheers

DK

3 Likes