discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Humble pie

PV
Paul van Dinther
Thu, Sep 2, 2021 6:44 AM

As a new openSCAD user I have struggled so much to get my programmers mind
out of the usual way of thinking. It just seemed so stupid. I was rather
vocal about it too as I recall. One might say, disrespectful and I should
own it.

Because, I actually have not put this tool away. It is too damn powerful
and I like working with it. I have spent an enormous amount of time
reading, learning, cursing and still at times I wonder why the hell it has
to be so hard.

BUT...

I also realise that the projects I build using openSCAD can get quite
elaborate yet, I don't get myself in the usual mess when projects grow.
This can be entirely contributed to the functional language.

What I am trying to say is, I am starting to understand why openSCAD has a
functional programming language. I am still struggling with many things but
it slowly becomes a way of thinking. So thank you for this fantastic piece
of software.

--
Regards

Paul van Dinther

As a new openSCAD user I have struggled so much to get my programmers mind out of the usual way of thinking. It just seemed so stupid. I was rather vocal about it too as I recall. One might say, disrespectful and I should own it. Because, I actually have not put this tool away. It is too damn powerful and I like working with it. I have spent an enormous amount of time reading, learning, cursing and still at times I wonder why the hell it has to be so hard. BUT... I also realise that the projects I build using openSCAD can get quite elaborate yet, I don't get myself in the usual mess when projects grow. This can be entirely contributed to the functional language. What I am trying to say is, I am starting to understand why openSCAD has a functional programming language. I am still struggling with many things but it slowly becomes a way of thinking. So thank you for this fantastic piece of software. -- Regards Paul van Dinther
NH
nop head
Thu, Sep 2, 2021 8:57 AM

The simple explanation for the functional style is that an OpenSCAD script
is a static description of an object, not a program that
executes procedurally. That is why variables only have one value as nothing
changes over time when you describe something.

It is also the same if you read a mathematical paper. You never see x =
x+1. The only time maths variables have changing values is in sigma
summation symbols, integration and the like where they iterate over a range
or through a set, just like OpenSCAD for loops.

Code tends to be less buggy when you know modules and functions can't
change variables as a side effect and easier to read when you know each
variable only has one value. For example people try to define a box with
width and depth and then subtract the wall to get the inner dimensions.
With mutable variables they can do width = width - wall part way through
the code and then when you read width it can mean two things in two places.
In OpenSCAD you have to do inner_width = width - wall and then it is clear.

On Thu, 2 Sept 2021 at 07:44, Paul van Dinther vandinther@gmail.com wrote:

As a new openSCAD user I have struggled so much to get my programmers mind
out of the usual way of thinking. It just seemed so stupid. I was rather
vocal about it too as I recall. One might say, disrespectful and I should
own it.

Because, I actually have not put this tool away. It is too damn powerful
and I like working with it. I have spent an enormous amount of time
reading, learning, cursing and still at times I wonder why the hell it has
to be so hard.

BUT...

I also realise that the projects I build using openSCAD can get quite
elaborate yet, I don't get myself in the usual mess when projects grow.
This can be entirely contributed to the functional language.

What I am trying to say is, I am starting to understand why openSCAD has a
functional programming language. I am still struggling with many things but
it slowly becomes a way of thinking. So thank you for this fantastic piece
of software.

--
Regards

Paul van Dinther


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

The simple explanation for the functional style is that an OpenSCAD script is a static description of an object, not a program that executes procedurally. That is why variables only have one value as nothing changes over time when you describe something. It is also the same if you read a mathematical paper. You never see x = x+1. The only time maths variables have changing values is in sigma summation symbols, integration and the like where they iterate over a range or through a set, just like OpenSCAD for loops. Code tends to be less buggy when you know modules and functions can't change variables as a side effect and easier to read when you know each variable only has one value. For example people try to define a box with width and depth and then subtract the wall to get the inner dimensions. With mutable variables they can do width = width - wall part way through the code and then when you read width it can mean two things in two places. In OpenSCAD you have to do inner_width = width - wall and then it is clear. On Thu, 2 Sept 2021 at 07:44, Paul van Dinther <vandinther@gmail.com> wrote: > As a new openSCAD user I have struggled so much to get my programmers mind > out of the usual way of thinking. It just seemed so stupid. I was rather > vocal about it too as I recall. One might say, disrespectful and I should > own it. > > Because, I actually have not put this tool away. It is too damn powerful > and I like working with it. I have spent an enormous amount of time > reading, learning, cursing and still at times I wonder why the hell it has > to be so hard. > > BUT... > > I also realise that the projects I build using openSCAD can get quite > elaborate yet, I don't get myself in the usual mess when projects grow. > This can be entirely contributed to the functional language. > > What I am trying to say is, I am starting to understand why openSCAD has a > functional programming language. I am still struggling with many things but > it slowly becomes a way of thinking. So thank you for this fantastic piece > of software. > > -- > Regards > > Paul van Dinther > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
RW
Ray West
Thu, Sep 2, 2021 10:14 AM

Hi Paul,

fwiw, many years ago (many depends on how old you are,I guess) I
struggled with the new fangled object oriented methodology. I was helped
by some wise IBMers. One of them said - 'you have to unplug your brain
and plug it in sideways - it'll take you a year, and it will suddenly
all click into place.' I think it's the same for openscad - It still
seems ass about face to me, e.g., design an object and then move it
where you want it is scripted as move it then make it. But, it is
consistent, although it takes getting used to , the [], {} etc. The
great thing is, the folk on this email list who try and set you on the
correct path, and 'the cheat sheet'.

On 02/09/2021 07:44, Paul van Dinther wrote:

As a new openSCAD user I have struggled so much to get my programmers
mind out of the usual way of thinking. It just seemed so stupid. I was
rather vocal about it too as I recall. One might say, disrespectful
and I should own it.

Because, I actually have not put this tool away. It is too damn
powerful and I like working with it. I have spent an enormous amount
of time reading, learning, cursing and still at times I wonder why the
hell it has to be so hard.

BUT...

I also realise that the projects I build using openSCAD can get quite
elaborate yet, I don't get myself in the usual mess when projects
grow. This can be entirely contributed to the functional language.

What I am trying to say is, I am starting to understand why openSCAD
has a functional programming language. I am still struggling with many
things but it slowly becomes a way of thinking. So thank you for this
fantastic piece of software.

--
Regards

Paul van Dinther


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Hi Paul, fwiw, many years ago (many depends on how old you are,I guess) I struggled with the new fangled object oriented methodology. I was helped by some wise IBMers. One of them said - 'you have to unplug your brain and plug it in sideways - it'll take you a year, and it will suddenly all click into place.' I think it's the same for openscad - It still seems ass about face to me, e.g., design an object and then move it where you want it is scripted as move it then make it. But, it is consistent, although it takes getting used to , the [], {} etc. The great thing is, the folk on this email list who try and set you on the correct path, and 'the cheat sheet'. On 02/09/2021 07:44, Paul van Dinther wrote: > As a new openSCAD user I have struggled so much to get my programmers > mind out of the usual way of thinking. It just seemed so stupid. I was > rather vocal about it too as I recall. One might say, disrespectful > and I should own it. > > Because, I actually have not put this tool away. It is too damn > powerful and I like working with it. I have spent an enormous amount > of time reading, learning, cursing and still at times I wonder why the > hell it has to be so hard. > > BUT... > > I also realise that the projects I build using openSCAD can get quite > elaborate yet, I don't get myself in the usual mess when projects > grow. This can be entirely contributed to the functional language. > > What I am trying to say is, I am starting to understand why openSCAD > has a functional programming language. I am still struggling with many > things but it slowly becomes a way of thinking. So thank you for this > fantastic piece of software. > > -- > Regards > > Paul van Dinther > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org
JB
Jordan Brown
Thu, Sep 2, 2021 9:19 PM

On 9/2/2021 3:14 AM, Ray West wrote:

It still seems ass about face to me, e.g., design an object and then
move it where you want it is scripted as move it then make it.

That's prefix notation, versus suffix notation.  You say the verb first,
and then the object, versus the other way 'round.

Note that in conventional math, when you talk about functions, you give
the function first and then you give the argument.  You say log(x), not
(x)log.

One can have a perfectly good language based on suffix notation.  Some
OO languages are a bit suffix-y, when you say obj.method().  Forth and
PostScript are both almost purely suffix-y.  Most calculators are
suffix-y with respect to single-operand operations; you say "123 log",
not "log 123 =".

But by far most languages have prefix notation function/procedure
invocation, where you say func(arguments).  What's unusual about
OpenSCAD is that it has two kinds of arguments; you say mod(args) {
children }.

On 9/2/2021 3:14 AM, Ray West wrote: > It still seems ass about face to me, e.g., design an object and then > move it where you want it is scripted as move it then make it. That's prefix notation, versus suffix notation.  You say the verb first, and then the object, versus the other way 'round. Note that in conventional math, when you talk about functions, you give the function first and then you give the argument.  You say log(x), not (x)log. One can have a perfectly good language based on suffix notation.  Some OO languages are a bit suffix-y, when you say obj.method().  Forth and PostScript are both almost purely suffix-y.  Most calculators are suffix-y with respect to single-operand operations; you say "123 log", not "log 123 =". But by far most languages have prefix notation function/procedure invocation, where you say func(arguments).  What's unusual about OpenSCAD is that it has two kinds of arguments; you say mod(args) { children }.
W
Whosawhatsis
Thu, Sep 2, 2021 10:01 PM
It still seems ass about face to me, e.g., design an object and then move it where you want it is scripted as move it then make it. But, it is consistent, although it takes getting used to , the [], {} etc.

The trick is to think of it as an enclosure, rather than a sequence. If you want to translate several things at once, you need to enclose them in a translate statement, and it makes sense to name that statement and define its parameters at the the beginning of the statement, rather than the end. It helps if you've worked with markup languages like HTML before. Though I hate to admit it, an XML-based format would probably be more logical than something that looks more like a programming language, given what OpenSCAD is actually doing. So instead of something like:

translate([10, 20, 30]) {
    rotate(45) {
        cube(10);
        cylinder(r = 10, h = 10);
    }
}

You would see something like:

<translate vector = "[10, 20, 30]">     <rotate angle = "45">         <cube size = "10" />         <cylinder r = "10", h = "10" />     </rotate> </translate>

The former is more concise, and integrates more seamlessly with some of the more programming-like things that OpenSCAD can do, but the latter is really more consistent with how other languages think about equivalent operations.

If you want to see what it would look like in the other direction, where you create an object and then move it, give TinkerCAD's block-code scripting tool a try. It's AWFUL. You're basically scripting things that you could do with your mouse, and without the convenience of being able to enclose multiple objects in an operation or perform operations like rotation relative to a global coordinate system, it's a lot more work to get anything done than if you were just using the mouse to do it.

It still seems ass about face to me, e.g., design an object and then move it where you want it is scripted as move it then make it. But, it is consistent, although it takes getting used to , the [], {} etc. The trick is to think of it as an enclosure, rather than a sequence. If you want to translate several things at once, you need to enclose them in a translate statement, and it makes sense to name that statement and define its parameters at the the beginning of the statement, rather than the end. It helps if you've worked with markup languages like HTML before. Though I hate to admit it, an XML-based format would probably be more logical than something that looks more like a programming language, given what OpenSCAD is actually doing. So instead of something like: translate([10, 20, 30]) {     rotate(45) {         cube(10);         cylinder(r = 10, h = 10);     } } You would see something like: <translate vector = "[10, 20, 30]">     <rotate angle = "45">         <cube size = "10" />         <cylinder r = "10", h = "10" />     </rotate> </translate> The former is more concise, and integrates more seamlessly with some of the more programming-like things that OpenSCAD can do, but the latter is really more consistent with how other languages think about equivalent operations. If you want to see what it would look like in the other direction, where you create an object and then move it, give TinkerCAD's block-code scripting tool a try. It's AWFUL. You're basically scripting things that you could do with your mouse, and without the convenience of being able to enclose multiple objects in an operation or perform operations like rotation relative to a global coordinate system, it's a lot more work to get anything done than if you were just using the mouse to do it.
JB
Jordan Brown
Sat, Sep 4, 2021 8:08 PM

On 9/2/2021 3:01 PM, Whosawhatsis wrote:

If you want to see what it would look like in the other direction,
where you create an object and then move it, give TinkerCAD's
block-code scripting tool a try. It's AWFUL. You're basically
scripting things that you could do with your mouse, and without the
convenience of being able to enclose multiple objects in an operation
or perform operations like rotation relative to a global coordinate
system, it's a lot more work to get anything done than if you were
just using the mouse to do it.

Although I don't think I'd want to work much in that kind of UI, I think
you're selling it short.

I added a block and a cylinder, and then did a "create group", and then
rotated the two of them together.

It seems to be an reverse-Polish environment, a suffix operation
environment, with a bit of a stack.

As for it being harder than using a mouse, yes, sort of... until you
want to go back and change the size of the box at the top of the
program, or change how much it's rotated, or whatever.  That's the big
advantage of any scripting environment, that you can change something
and re-run the program to get a different result.

Here's a non-trivial program that does something slightly interesting:

It's pretty tedious compared to just typing an OpenSCAD program, but on
the other hand it is almost entirely free of syntax.

It's a toy in a lot of ways.  It's hard to imagine building anything
even a little bit complex in it.  But it does let you do the basics.

(If you're wondering what's with the "Delete Object"... Objects aren't
subroutines.  Object0 runs and creates an object, and then Object1
runs and makes and modifies copies of it.  The "Delete Object" deletes
that original object.)

On 9/2/2021 3:01 PM, Whosawhatsis wrote: > If you want to see what it would look like in the other direction, > where you create an object and then move it, give TinkerCAD's > block-code scripting tool a try. It's AWFUL. You're basically > scripting things that you could do with your mouse, and without the > convenience of being able to enclose multiple objects in an operation > or perform operations like rotation relative to a global coordinate > system, it's a lot more work to get anything done than if you were > just using the mouse to do it. Although I don't think I'd want to work much in that kind of UI, I think you're selling it short. I added a block and a cylinder, and then did a "create group", and then rotated the two of them together. It seems to be an reverse-Polish environment, a suffix operation environment, with a bit of a stack. As for it being harder than using a mouse, yes, sort of... until you want to go back and change the size of the box at the top of the program, or change how much it's rotated, or whatever.  That's the big advantage of any scripting environment, that you can change something and re-run the program to get a different result. Here's a non-trivial program that does something slightly interesting: It's pretty tedious compared to just typing an OpenSCAD program, but on the other hand it is almost entirely free of syntax. It's a toy in a lot of ways.  It's hard to imagine building anything even a little bit complex in it.  But it does let you do the basics. (If you're wondering what's with the "Delete Object"... Objects aren't subroutines.  Object0 runs *and creates an object*, and then Object1 runs and makes and modifies copies of it.  The "Delete Object" deletes that original object.)
WF
William F. Adams
Sat, Sep 4, 2021 9:47 PM

Another option here is BlockSCAD, which is a front-end for OpenSCAD:
https://www.blockscad3d.com/editor/#

I rather like it and use it by preference.
William

Another option here is BlockSCAD, which is a front-end for OpenSCAD: https://www.blockscad3d.com/editor/# I rather like it and use it by preference. William