It would break my code, as I sometimes use the word "center" as variable name
or module name.
--
Sent from: http://forum.openscad.org/
Troberg wrote
It would break my code, as I sometimes use the word "center" as variable
name
or module name.
Hmmm... if you set a variable named center to anything but true, it defaults
to false.
And it doesn't seem to cause a problem with a module named center.
translate([20,20,20])
center();
module center(){
sphere(10);
}
center = true;
cube(10,center);
--
Sent from: http://forum.openscad.org/
lar3ry wrote
Troberg wrote
It would break my code, as I sometimes use the word "center" as variable
name
or module name.
Hmmm... if you set a variable named center to anything but true, it
defaults
to false.
Still, it's not a nice way of doing it. At the very least, prefix such
pre-defined constants, for example scadcenter, which will both reduce the
risk of namespace clashes and clearly show what's a predefined constant.
--
Sent from: http://forum.openscad.org/
lar3ry wrote
Troberg wrote
It would break my code, as I sometimes use the word "center" as variable
name
or module name.
Hmmm... if you set a variable named center to anything but true, it
defaults
to false.
And it doesn't seem to cause a problem with a module named center.
center = true;
cube(10,center);
I'd say that's a confusing way to put it. (I couldn't quite figure out what
you meant.)
A default is something that happens when data is missing, but if you pass a
value to center then there is no missing data, so the default doesn't have
obvious relevance. However, it seems that the behavior of the cube module
is that if center=true then you get a centered cube. And if center is
anything else, you get an uncentered cube. This is arguably a bug. One
would expect that anything which tested as true should cause the cube to be
centered. (That is, [3,4] is true in a boolean context, but acts like false
when given as the center argument to cube().) Or perhaps you should get an
error message if a non-boolean value is passed to center.
But I think Troberg's point is that he likes to use "center" as a variable,
which conflicts with this approach, and conflicts with your original idea of
being able to write "center" instead of "center=true" when specifying a
centered cube.
It might for example be natural to define the center of some component, so
center=[3,4,5];
This will conflict with "center=true" and will cause cubes that were
supposed to be centered come out not centered if you've got invocations of
cube(size,center) with the intention that this produce a centered cube.
If I saw some code that had stuff like
cube(size,center);
in it then I'd wonder what the value of center was. It doesn't read as
"centered cube" to me. And the goal is just to avoid typing "=true"? I
suggest that if you're so offended by the need to type "center=true" and you
have a lot of centered cubes, the answer is to make a centered cube module:
module center_cube(size) { cube(size,center=true);}
You can make similar pass-through modules for other things you want to have
centered. You can give it a shorter (more cryptic) name if you're really
frustrated by all the typing. I suppose also if the goal is brevity you
can do "cube(1,true)".
--
Sent from: http://forum.openscad.org/
adrianv wrote
lar3ry wrote
Troberg wrote
It would break my code, as I sometimes use the word "center" as variable
name
or module name.
Hmmm... if you set a variable named center to anything but true, it
defaults
to false.
And it doesn't seem to cause a problem with a module named center.
center = true;
cube(10,center);
I'd say that's a confusing way to put it. (I couldn't quite figure out
what
you meant.)
A default is something that happens when data is missing, but if you pass
a
value to center then there is no missing data, so the default doesn't have
obvious relevance. However, it seems that the behavior of the cube module
is that if center=true then you get a centered cube. And if center is
anything else, you get an uncentered cube. This is arguably a bug. One
would expect that anything which tested as true should cause the cube to
be
centered. (That is, [3,4] is true in a boolean context, but acts like
false
when given as the center argument to cube().) Or perhaps you should get
an
error message if a non-boolean value is passed to center.
Well, I said default, because anything other than true acts the same way a
false acts.
If I saw some code that had stuff like
cube(size,center);
in it then I'd wonder what the value of center was. It doesn't read as
"centered cube" to me. And the goal is just to avoid typing "=true"? I
suggest that if you're so offended by the need to type "center=true" and
you
have a lot of centered cubes, the answer is to make a centered cube
module:
Let me ask you a question. If I want a sphere that is not centered, why
can't I write sphere(10,center = false);? Is there ANY object that is
centered that could be made not centered by using center = false?
It isn't so much the typing. It's more like I don't see a need to ever use
center = false.
You can make similar pass-through modules for other things you want to have
centered. You can give it a shorter (more cryptic) name if you're really
frustrated by all the typing. I suppose also if the goal is brevity you
can do "cube(1,true)".
I could, but false by itself is less "self-documenting" than center = true,
or even just center, if it would be a parameter that ALWAYS evaluated as
true in the parameters of an object that allowed center.
--
Sent from: http://forum.openscad.org/