Conversion rate of Grasshopper definition to normal coding

I have a really large deifinition as a part of my thesis work. It would be nice if I could tell to the teachers how big is my program. Anyone have thought about a conversion rate of Grasshopper definition to traditional coding? What I mean is if I have let’s say a difinition of 1000 widget on my page, roughly how many program lines would it be equivalent to. Any suggestion?

It really depends on how much “entangled” is your definition.
There is not a fixed conversion rate.
It depends on how much complex are the functions you used, on how many trees there are.
You can have a linear sequence of blocks which will translate good and fast in traditional coding, probably with fewer code lines…
… but you can also have a really “entangled” situation where the algorithm is almost “impossible” to translate in traditional coding (or it will a big pain… visual programming have its own great advantages).

To have an idea it should be useful to see the actual definition, or at least see an image of it whole.
You can post an image of your whole solution (File> Export Hi-Res Image…) , all the wires should be set to visible (if you want to hide your code, use a zoom level where component names are not shown…) … hopefully you did’t use many plug-ins… (as often they are almost clusters or many line of code themself…)

AS I said my definition si really “BIG”. Despite I gave 32Gid of ram, the image could not be created. Howerver David Rutten wrote an app which displays the object count. (Hovever I dont know how to save the file data into a text file. If could, I could sum all objects in the file, and that would give you an idea. Maybe a rough estimation based on object count can be made. (from to till program lines.)

If the object-count app outputs text you can connect a Panel and stream the content to a text file on disk, like so:

// Rolf

You’re measuring the wrong thing. More code is not better. Less code also isn’t automatically better.

Code should be modular and understandable. Ideally it also handles incorrect input or failed steps gracefully, but that is really hard to do in GH.

Most components have about 10 to 100 lines of code in them that do the work. However this code calls into other code elsewhere, so when you’re offsetting a curve the amount of instructions involved may well be in the tens to hundreds of thousands. Do you want to use that as a metric to impress people?

If I were a teacher evaluating some work I’d be most impressed if the algorithm presented a proof of the correctness of the output, especially if that includes some error-margins.

It shouldn’t matter whether doctors used the machine that goes PING during the procedure, what matters is how the patient is doing.

2 Likes

I agree totally. Is not about impressing people rather it says something about the work I have invested in it. (even it is not 100 percent perfect). That is why I need eben a very rough estimation.

I meant exporting the data from David’s anylizer apllication.

I thought the app was a Gh component. Anyway, have you tried type the app command as follows?

Drive:\GhFileAnalyzis.exe >> gh_statistics.txt

// Rolf

That is why I need eben a very rough estimation

not possible

I think it is possible. It is a question of how accurate we want to be.
Lets say have 100 of widgets (actually I have much more than that). David wrote: most of them 10-100 lines-
Based on this my definition is at least 1000-10000 lines isnt it?

No, because if you coded the entire definition as one code then lots of optimization can happen because of the ability to loop and create methods rather than constantly collect tons of data to sort as data trees. Code is not linear. You would not code in the same logic as you would connecting grasshopper components.

You could get a number of how many lines of code are literally making your grasshopper definition yes, but the point is, if you were coding it to be a process you would not code it that way. Grasshopper is coded in a way to be a linear node based code system.

Additionally, some things are Rhinocommon one liners but behind the scenes of rhinocommon it could be many lines of code not exposed to the code writer.

1 Like

I just wanted to make a figure so that someone can have a rough idea how work was invested in it. Sorry to hear that I cannot say any figure in my presentation.

Code is not the figure you are looking for, you should quantify it as grasshopper components and time you worked on it if anything. Especially since you did not write the code, it makes no sense for you count the work invested in the code, and as said once again, the code in gh components does not correlate to what the code would be directly as a process.

2 Likes

I agree with Michael that lines of code wouldn’t do your work justice. But what seems to really say something is the number of components AND their connections. Connections it a huge and important part of what makes your component mix unique.

See for example the definition pictured, which I saved as .ghx and then counted the input connections, by running a simple regular expression on the xml file. You should expect to find five input connections in the following ghx file:

bild

Now, using the following regex … :

bild

… and sure enough, you would get the following result:

And that is what you would want to know, plus of course the number (and names) of components (the regex first):

… and the result:

This collected info can be saved into a text file and - in my opinion - it would say very much about the work you have done in the file. Perhaps adding some info about the number of groups as well, would be a good idea.

// Rolf

Rolf, this is very nice of you. I am just a simply architect. I have no clue what regex is.

How is it your teachers cannot appreciate the complexity of a GH def by looking at it? Are they familiar with it at all?

If I had to judge your code as a teacher, I’d look at the outcome of the script and the organization of it. What sense does the size of a script mean? It could well be a very inefficient script. So in terms of invested hours maybe less code means more time invested, more optimizations have been done. And there is one more way to explain how much time you invested: by telling your teacher.

1 Like

Hello,
I’ve been thinking about what might be more meaningful statistics for you - testing the time your code takes to run with different numbers of inputs would be interesting, and seeing which components take the most time. Does the time taken scale proportionally to the number or size of input objects ? Or to the square ? Or more ? Does this give clues as to ways the script could be sped up, and to the complexity of different operations ?

Regex: https://docs.microsoft.com/en-us/dotnet/standard/base-types/regular-expressions
also: https://regex101.com/
and: https://extendsclass.com/regex-tester.html