code simplification but how much ?

how to simplify codes and is it good ?
i have a lot of mesh/ob that i make in many functions

so to simplfy things i can replace the part where i add a vertex and edge like this
vid+= 1

replace with


def vertedgadd1(vadd1,id0,id1):
global vid,verts1,edges

vid+= 1

is it too oversimplified or acceptable
i also have to use global vars here!

it does save a few lines but makes the code more difficult to read and understandble!
any advice on this simplification process!

thanks happy 2.5

Everything should be made as simple as possible, but not simpler.

ok hum
still wondering about the compromise i guess

but what i did up in first post is it too much simplified or about right?

i know that some noobies might say it’s already too much!LOL


You may think you are simplifying the code but actually complicating matters… First, going from an inline instruction to a function call will impact performance and you are separating the logic from the operation. Additionally, if you want to improve performance and you have several cases where the same variable is used - “YC+h2+h4” - set a variable to the value and reference the variable in each instruction rather than repeating the calculation.


this “YC+h2+h4” is a specific value which is not repeated for a vertex location

but i do have a lot of vertex to add with edge

let say in a function i may have 5 to 10 vertex

but i have over 30 functions overall

so i can keep it very simple and readable

like this

h1= genr*0.2 # UP

vid+= 1

or as i did to simplify in order to reduce the number of lines

i know that it also makes it more difficult to read and understand and it’s even worst for noobies

but what would be a good compromise is what i’m wondering !

right now i did not finish my overall script may be 70 % and i already have over 3000 lines!


Coding is like any religion/philosophy - different factions have different beliefs and expectations. Best I can say is do what you think is best.

Rule 1 - it’s gotta work. After that you can pretty much do anything you want.

Having a common function is valuable when making changes to the operation and logic. Only need to change in one place… this is a good thing. However, this method is typically slower due to passing parameters and other system overhead.

Optimization, for number of lines, is best left for last when you are done. If you see a case where you can simplify the logic for repeated operations, typically a loop variable, or consolidated repeated code as a function, go ahead. Just be sure to comment well since there will likely be differences that aren’t obvious for different cases you are using. To clarify - I have two functions that do basically the same thing, just in a different order. I could probably make these into a single function and use a negative value or specific flag to determine the logic difference.

This puts the code in one place for two similar operations - handy for maintenance. But, the trade off is working through modifications to implement when it’s already working :slight_smile:

Have fun working out your own preferences for how to program/code - you will always find folks that are fanatical about trivia and nuances.

Sure, I just added a function - to create a curve, so I don’t have to repeat it each time (by mode/model) inline. So, function wins vs. inline for each instance. Ten lines of code * 3 (30) vs. a call for each time I used it is only 13 lines of code.

– PS got less than 1K code and can make… columns :slight_smile:


1 make it works
2 - simplify first level like repeating functions ect.

3 - simplify to lower qty of lines but with good descriptions

i guess it sound right

ok i’ll see if i can come up next week with a new addon applying these principles!