kennetek / gridfinity-rebuilt-openscad

A ground-up rebuild of the stock gridfinity bins in OpenSCAD
Other
1.37k stars 200 forks source link

Lack of indenting/braces on nested options in gridfinity-spiral-vase.scad #241

Open reedy opened 1 month ago

reedy commented 1 month ago

There's quite a bit of code in gridfinity-spiral-vase.scad that becomes hard to follow because of conditionals and loops, with inexplicit following instructions due to lack of indenting, or braces etc

For example:

module block_x() {
    translate([-(gridx-1)*l_grid/2,-(gridy-1)*l_grid/2,0])
    for (i = [1:gridx])
    for (j = [1:gridy])
    if (xFunc[style_base](i,j))
    translate([(i-1)*l_grid,(j-1)*l_grid,0])
    block_x_sub();
}

I'm guessing is really something like

module block_x() {
    translate([-(gridx-1)*l_grid/2,-(gridy-1)*l_grid/2,0])
    for (i = [1:gridx]) {
        for (j = [1:gridy]) {
            if (xFunc[style_base](i,j)) {
                translate([(i-1)*l_grid,(j-1)*l_grid,0])
            }
        }
    }
    block_x_sub();
}

But maybe it's

module block_x() {
    translate([-(gridx-1)*l_grid/2,-(gridy-1)*l_grid/2,0])
    for (i = [1:gridx]) {
        for (j = [1:gridy]) {
            if (xFunc[style_base](i,j)) {
                translate([(i-1)*l_grid,(j-1)*l_grid,0])
                block_x_sub();
            }
        }
    }
}

due to the position of the ;. The inconsistency of usages of ; similar make it a little hard to follow, knowing which statements are related to each other...

EmperorArthur commented 1 month ago

The 2nd is correct, and the first should fail to compile. The rule is that there is an implicit scope (braces) around the next object.