fling has quit [Remote host closed the connection]
fling has joined #openscad
sellorm has quit [Ping timeout: 246 seconds]
sellorm has joined #openscad
califax has quit [Remote host closed the connection]
califax has joined #openscad
guerd87 has quit [Read error: Connection reset by peer]
epony has quit [Remote host closed the connection]
epony has joined #openscad
ToAruShiroiNeko has quit [Ping timeout: 260 seconds]
ToAruShiroiNeko has joined #openscad
mmu_man has quit [Ping timeout: 268 seconds]
ToAruShiroiNeko has quit [Ping timeout: 264 seconds]
ToAruShiroiNeko has joined #openscad
guso78k has quit [Ping timeout: 250 seconds]
Guest77 has joined #openscad
mmu_man has joined #openscad
<Guest77>
Hi, I have a little question about programming style in OpenSCAD. I developed already some little things and what I see often is, that my parameter lists explode. As example, I define a module A with 5 parameters, then this is called from a module B which has also 4 parameters, but the 5 parameters of module A needs to be also accessible from
<Guest77>
outside. This means module B has potentially 9 parameters and so on and so on... currently I tried to make my scripts a bit more object-oriented, so that my modules get more an object instead of 5 single parameters. Here is a small example. Of course you can then build other classes than MyObject and build composites of objects with objects. The
<Guest77>
only I hate is the C style of functions MyObject_width(object) instead of object.width(). But currently I find my code much more readable with that and of course I can build much more easily such computing functions that uses primitive attributes, where I would need else a big parameter list. Are there any other/better solutions to overcome the
<Guest77>
exploding parameter lists?
<Guest77>
/ constructor functions
<Guest77>
/
<Guest77>
function MyObject_new(width, height) = [width, height];
<Guest77>
/ accessor functions
<Guest77>
/
<Guest77>
function MyObject_width(receiver) = receiver[0];
<Guest77>
function MyObject_height(receiver) = receiver[1];
<Guest77>
/ computed functions
<Guest77>
/
<Guest77>
function MyObject_surface(receiver) = MyObject_width(receiver) * MyObject_height(receiver);
<InPhase>
Guest77: Object literals are being worked on for a following release, but these aren't really ready yet.
<InPhase>
Guest77: This will provide a built-in solution to that particular problem, however. I have occasionally tried to do as you describe, but I rarely hit scenarios where the manual overhead of what you've done is worth it. Object literals will fix that up by removing the overhead and making it all more natural.
<J24k23>
it depends what your style is, but if you need so many parameters it doesn't matter how - i am using some defined within the module so i can change them but they shouldn't
<InPhase>
Guest77: One obvious way to get a quick gain, is to package up everything that's naturally multi-dimensional. I usually preference a "size" parameter over width, height, etc. You can then do size.x, size.y, size.z as this is already supported for 2 or 3 element lists.
<Guest77>
yeah, I tried also something like global variables, which I had in a settings.scad, coz most modules of a project depend mostly heavily of parameters of others. But from viewpoint of reusing code it is not the best idea.
mmu_man has quit [Ping timeout: 264 seconds]
<J24k23>
else keep them readable so you know what to set you can use var=[10,20] with var.x or var.y i personally would not use arrays bigger 4 to store variables
<Guest77>
Funny, hidden compiler language leaks, that I can create an array and access the elements with x, y, z :')
<Guest77>
why not using the full alphabet XD then we have 26 variables
<J24k23>
there is also rgbw
<Guest77>
I tried it and it works :-)
<Guest77>
this is not what I call consistent language design, but ok
<Guest77>
interesting to know
<J24k23>
ah rgba (alpha)
<J24k23>
and you can do var.xzy
<Guest77>
but I guess it does not help me really for readable code, coz I do not want to write at caller side.something like object.x, when I mean object.width
<InPhase>
Guest77: In the master branch we also have some wild features like size.xy giving [5,6] out of an input [5,6,7]
<J24k23>
(at least in the dev snap)
<Guest77>
currently I implemented also a OpenSCAD wrapper in Squeak Smalltalk, which makes OOP/code reuse much more easier and of course debuggable. But to use existing OpenSCAD libraries I need to add their source to the Smalltalk side and write it also down to the generated output. So I am thinking currently what is better, plain OpenSCAD with my semi-OOP
<Guest77>
solution or generated code by Smalltalk :-)
<Guest77>
I read also about OpenSCAD2 with the objects and all-first-class-things... is there anything anywhere that I can download which has these new features?
<Guest77>
currently I use a development version anyway, coz the official download is very outdated and rendering there is ultra-slow
L29Ah has left #openscad [#openscad]
rawgreaze has joined #openscad
epony has quit [Remote host closed the connection]
mmu_man has joined #openscad
ToAruShiroiNeko has quit [Ping timeout: 255 seconds]