The OpenSCAD Language

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

The OpenSCAD Language

G. Wade Johnson
I know this subject comes up every few months, but it seems to have run
longer than most times I can remember.

I wonder why people cannot understand that OpenSCAD is not a general
purpose programming language, it is a language for describing 3D
objects. As such, the creator of the language made design trade-offs
different than what you might make for Python or Java.

Over a pretty long programming career, I've seen people make a similar
mistake in general purpose languages. They confuse a design choice with
an error in judgment. In the end, they end up spending an inordinate
amount of time "fighting" the language, when they could be getting work
done.

I'm not going to try to say that OpenSCAD is perfect. Everyone here
knows there are deficiencies. Some people are even volunteering their
time to fix some of them. I really appreciate the work that has been
done to make OpenSCAD the tool that it is, and I definitely don't thank
the maintainers enough.

Many of the improvements I have seen in the last seven years of using
OpenSCAD have come from suggestions from this list. Almost all of them
have come from understanding the tool and pointing out a change within
the scope of the design.

Try to be respectful of the work that has gone into a tool we all use,
and assume that the maintainers made the choices they did for valid,
intelligent reasons.

Sorry for the rant,
G. Wade Johnson
--
Cannot say. Saying I would know, do not know, so cannot say.
                                  -- Zathras - "The War without End"

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: The OpenSCAD Language

Troberg
Well, I love my wife, but there are still things I wish she did differently.

Same thing here. I love OpenSCAD, but there are some situations where it
becomes extremely cumbersome to use, for example that I can't assign an
object to a variable and then ask that variable about the object (location,
size, rotation et cetera).

Besides, software is never perfect. It can always be better. When there is
nothing to improve, it dies. Once you accept that, it's easier to handle
flaws in software.



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: The OpenSCAD Language

cacb
On 2019-05-06 09:31, Troberg wrote:
> Well, I love my wife, but there are still things I wish she did
> differently.
>
> Same thing here. I love OpenSCAD, but there are some situations where
> it
> becomes extremely cumbersome to use, for example that I can't assign an
> object to a variable and then ask that variable about the object
> (location,
> size, rotation et cetera).

Different software have different philosophies. In OpenSCAD, a design
choice was at one stage taken to use what is called a "functional
language" which by definition disallows the types of operations you
mention. I also raised this issue when starting to use OpenSCAD a few
years ago, and I soon realised that the OpenSCAD language was not going
to change in this area.

Back then someone stated along the lines that in CSG modelling you
describe data instead of programming. To me this is just a software
design choice, it is not in itself dictated by the CSG technique. You
can generate at a CSG model in different ways, not just by describing it
directly (also in OpenSCAD you could say algorithms are used). So I
started exploring what it would take to make a different design choice
wrt. scripting for CSG modelling.

The result is AngelCAD, now open source
https://arnholm.github.io/angelcad-docs/

A small taste of the AngelCAD language
https://gist.github.com/arnholm/2ad1cb525803695c73de37b84e480d4a

In this context, objects can be assigned to variables that are allowed
to be modified at any time. The objects can be queried for information
about their bounding boxes etc., for example:
https://gist.github.com/arnholm/23c482530fd1882c615f5e6e3c9eedca

Sometimes, the styles of code in OpenSCAD and AngelCAD can be similar:
https://gist.github.com/arnholm/98b007bb960e328ef9a986a96b412607

The design choice in AngelCAD was to use an existing language for CSG,
rather than invent a new one. The choice was AngelScript
http://www.angelcode.com/angelscript/sdk/docs/manual/doc_script.html , a
language that allows many different styles of writing code. It is easily
extended for CSG modelling in AngelCAD (ref. link above for details).

The strength of OpenSCAD is its wide adoption and user base, it has
brought CSG modelling "to the masses" which is a great achievement. It
is relatively simple to use for medium complex tasks, but sometimes it
is easier to express things using algorithms and even user defined data
types. You don't have to use such features in AngelCAD, but you can if
you want to.

Carsten Arnholm


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: The OpenSCAD Language

Troberg
Well, as nice as it looks, I have a parts library with several hundred parts
in OpenSCAD, and I have several external tools I've written to help extract
information from a running script and to extract code documentation. So, I'm
pretty mucheh stuck with OpenSCAD for now, unless something really epic
comes along.



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: The OpenSCAD Language

alexgibson
In reply to this post by cacb
Hi Carsten

Couple of questions:

Is there a way to translate OpenSCAD code to AngelCAD?
And is AngelCAD able to export STEP files?

Thanks,

Alex Gibson

admg consulting

edumaker limited

. Project management
. Operations & Process improvement
. 3D Printing


-----Original Message-----
From: Discuss [mailto:[hidden email]] On Behalf Of
[hidden email]
Sent: 06 May 2019 09:42
To: OpenSCAD general discussion
Subject: Re: [OpenSCAD] The OpenSCAD Language

On 2019-05-06 09:31, Troberg wrote:
> Well, I love my wife, but there are still things I wish she did
> differently.
>
> Same thing here. I love OpenSCAD, but there are some situations where
> it
> becomes extremely cumbersome to use, for example that I can't assign an
> object to a variable and then ask that variable about the object
> (location,
> size, rotation et cetera).

Different software have different philosophies. In OpenSCAD, a design
choice was at one stage taken to use what is called a "functional
language" which by definition disallows the types of operations you
mention. I also raised this issue when starting to use OpenSCAD a few
years ago, and I soon realised that the OpenSCAD language was not going
to change in this area.

Back then someone stated along the lines that in CSG modelling you
describe data instead of programming. To me this is just a software
design choice, it is not in itself dictated by the CSG technique. You
can generate at a CSG model in different ways, not just by describing it
directly (also in OpenSCAD you could say algorithms are used). So I
started exploring what it would take to make a different design choice
wrt. scripting for CSG modelling.

The result is AngelCAD, now open source
https://arnholm.github.io/angelcad-docs/

A small taste of the AngelCAD language
https://gist.github.com/arnholm/2ad1cb525803695c73de37b84e480d4a

In this context, objects can be assigned to variables that are allowed
to be modified at any time. The objects can be queried for information
about their bounding boxes etc., for example:
https://gist.github.com/arnholm/23c482530fd1882c615f5e6e3c9eedca

Sometimes, the styles of code in OpenSCAD and AngelCAD can be similar:
https://gist.github.com/arnholm/98b007bb960e328ef9a986a96b412607

The design choice in AngelCAD was to use an existing language for CSG,
rather than invent a new one. The choice was AngelScript
http://www.angelcode.com/angelscript/sdk/docs/manual/doc_script.html , a
language that allows many different styles of writing code. It is easily
extended for CSG modelling in AngelCAD (ref. link above for details).

The strength of OpenSCAD is its wide adoption and user base, it has
brought CSG modelling "to the masses" which is a great achievement. It
is relatively simple to use for medium complex tasks, but sometimes it
is easier to express things using algorithms and even user defined data
types. You don't have to use such features in AngelCAD, but you can if
you want to.

Carsten Arnholm


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: The OpenSCAD Language

cacb
On 2019-05-06 15:17, Alex Gibson wrote:
> Is there a way to translate OpenSCAD code to AngelCAD?
> And is AngelCAD able to export STEP files?

Hi Alex,

No effort has been made to translate OpenSCAD code to AngelCAD so the
answer is no. The opposite is possible, AngelCAD can generate an
OpenSCAD .csg file.

AngelCAD is mesh based as it uses xcsg ( https://github.com/arnholm/xcsg 
) which again is based on Carve. This is similar to OpenSCAD that is
also mesh based using CGAL.  When you ask about STEP, I guess you are
talking about boundary representation
https://en.wikipedia.org/wiki/Boundary_representation, a rather
different description of 3d geometry compared to mesh based Constructive
Solid Geometry (CSG). So just like OpenSCAD, AngelCAD/xcsg cannot export
B-REP STEP files. The export formats include (via xcsg)

   --amf                 AMF output format (Additive Manufacturing
Format)
   --csg                 CSG output format (OpenSCAD)
   --dxf                 DXF output format (AutoCAD DXF - 2D only)
   --svg                 SVG output format (Scalar Vector Graphics - 2D
only)
   --stl                 STL output format (STereoLitography)
   --astl                STL output format (STereoLitography) - ASCII
   --obj                 OBJ output format (Wavefront format)
   --off                 OFF output format (Geomview Object File Format)

AngelCAD can import AMF, OBJ and OFF

Regards
Carsten Arnholm

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: The OpenSCAD Language

doug.moen
In reply to this post by cacb
The OpenSCAD language has the following limitations:
* You can't store a shape in a variable.
* You can't query the attributes of a shape (eg, get the bounding box, or the list of faces and vertices).
* Functions are not values. They can't be stored in variables, passed as parameters, or returned as results.
* The only data structure is the list. There are no records (or maps).
* There is no assignment statement, and no mutable variables.

When I first got involved with OpenSCAD, I hoped to pitch in and fix these limitations. I wrote a number of design proposals, and created "OpenSCAD2" as a design proposal for fixing these limitations.

Once it became clear that I wouldn't be able to make these changes within the OpenSCAD project, I renamed OpenSCAD2 to Curv, and evolved the project in a different direction from OpenSCAD. The Curv language fixes all of the limitations that I listed above, and I changed the representation of shapes from triangle meshes to signed distance fields, which I believe is a more powerful representation. It can represent curved shapes and deeply iterated fractals using a mathematically exact representation, and there is a larger set of shape operations available. This representation also supports full colour 3D printing.

Carsten wrote:

> In OpenSCAD, a design choice was at one stage taken to use what is called
> a "functional language" which by definition disallows the types of operations
> you mention.

OpenSCAD is not a functional language. Functional programming is all about programming with functions. But functions are not values in OpenSCAD.

It would be fair to call OpenSCAD a domain-specific, declarative language.

It is untrue that functional languages "by definition" disallow the feature that Troberg wants: "I can't assign an object to a variable and then ask that variable about the object (location, size, rotation et cetera)."

Curv is a pure functional language (the strictest type of functional language), and it nevertheless supports all of the features I mentioned in the first paragraph, including assignment statements and mutable variables. Curv also supports the usual functional programming idioms: curried functions, pattern matching, full tail recursion optimization.

It would be possible, in principle, to extend OpenSCAD to support the same features. But it would be a big, disruptive change to the language, and that conflicts with OpenSCAD's conservative approach to change. OpenSCAD is almost 10 years old and the project has emphasized stability, incremental change and backwards compatibility.

AngelCAD certainly represents one approach to overcoming OpenSCAD's limitations.

However, AngelCAD is just CSG embedded in a general purpose imperative language. There is a lot of verbosity and boilerplate, compared to a domain-specific declarative language such as OpenSCAD or Curv. The lack of boilerplate is something that I really value about OpenSCAD.

AngelCAD:
shape@ main_shape()
{
    cube@ cu = cube(size:45, center:true);
    return cu;
}

void main()
{
   shape@ obj = main_shape();
   obj.write_xcsg(GetInputFullPath(),secant_tolerance:0.01);
}

OpenJSCAD:
function main ()
{
   return cube({size: 45, center: true});
}

OpenSCAD:
cube(45, center=true);

Curv:
cube 45

 Doug Moen.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
rew
Reply | Threaded
Open this post in threaded view
|

Re: The OpenSCAD Language

rew
On Mon, May 06, 2019 at 10:59:04AM -0400, Doug Moen wrote:
> OpenSCAD:
> cube(45, center=true);
>
> Curv:
> cube 45

OK ! I want to switch. Where do I download it?

-> https://github.com/curv3d/curv

It is not fair to compare the nondefault in one language with the
default on the other.

Openscad
cube (45);

curv:
cube 45 dontcenter=true
        ^^^^^^^^^^^^^^
don't know how to write that in curv yet.


        Roger.

--
** [hidden email] ** https://www.BitWizard.nl/ ** +31-15-2049110 **
**    Delftechpark 11 2628 XJ  Delft, The Netherlands.  KVK: 27239233    **
The plan was simple, like my brother-in-law Phil. But unlike
Phil, this plan just might work.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: The OpenSCAD Language

nophead
I am quite happy with openscad. It does every thing I want and is simple, which is what I crave. The only thing I eny is speed.

On Mon, 6 May 2019, 16:40 Rogier Wolff, <[hidden email]> wrote:
On Mon, May 06, 2019 at 10:59:04AM -0400, Doug Moen wrote:
> OpenSCAD:
> cube(45, center=true);
>
> Curv:
> cube 45

OK ! I want to switch. Where do I download it?

-> https://github.com/curv3d/curv

It is not fair to compare the nondefault in one language with the
default on the other.

Openscad
cube (45);

curv:
cube 45 dontcenter=true
        ^^^^^^^^^^^^^^
don't know how to write that in curv yet.


        Roger.

--
** [hidden email] ** https://www.BitWizard.nl/ ** +31-15-2049110 **
**    Delftechpark 11 2628 XJ  Delft, The Netherlands.  KVK: 27239233    **
The plan was simple, like my brother-in-law Phil. But unlike
Phil, this plan just might work.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: The OpenSCAD Language

William Adams-2
As long as we're asking for stuff --- I just wish there was an easier way to get curves / vectors out as something other than triangles or line segment approximations.

Currently working through re-drawing parametric designs using METAPOST based on the JSON output from the OpenSCAD customizer.

Would a 2D version of the OpenSCAD language which output nice SVG/PDF files be that difficult to do? (or does it exist and I'm missing it?)

William

On Mon, May 6, 2019 at 11:46 AM nop head <[hidden email]> wrote:
I am quite happy with openscad. It does every thing I want and is simple, which is what I crave. The only thing I eny is speed.

On Mon, 6 May 2019, 16:40 Rogier Wolff, <[hidden email]> wrote:
On Mon, May 06, 2019 at 10:59:04AM -0400, Doug Moen wrote:
> OpenSCAD:
> cube(45, center=true);
>
> Curv:
> cube 45

OK ! I want to switch. Where do I download it?

-> https://github.com/curv3d/curv

It is not fair to compare the nondefault in one language with the
default on the other.

Openscad
cube (45);

curv:
cube 45 dontcenter=true
        ^^^^^^^^^^^^^^
don't know how to write that in curv yet.


        Roger.

--
** [hidden email] ** https://www.BitWizard.nl/ ** +31-15-2049110 **
**    Delftechpark 11 2628 XJ  Delft, The Netherlands.  KVK: 27239233    **
The plan was simple, like my brother-in-law Phil. But unlike
Phil, this plan just might work.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: The OpenSCAD Language

doug.moen
In reply to this post by rew
Curv is in the early adopter phase (it's not finished yet). There are no precompiled binaries. You can compile the source on MacOS or Linux yourself. No Windows port exists because nobody has volunteered for that.

We are going to address the deployment problem later this year by porting Curv to run in a web browser.

To align a corner of a cube with the origin, you are supposed to use the `align` operator, but that isn't implemented yet. So for now you are stuck with:

    cube 10 >> translate[5,5,5]

to simulate `cube(10)` in OpenSCAD.

Note that in Curv, all of the geometric primitives are written in Curv. The `align` operator is probably 12 lines of Curv code, it just needs to be written.

On Mon, May 6, 2019, at 11:40 AM, Rogier Wolff wrote:

> On Mon, May 06, 2019 at 10:59:04AM -0400, Doug Moen wrote:
> > OpenSCAD:
> > cube(45, center=true);
> >
> > Curv:
> > cube 45
>
> OK ! I want to switch. Where do I download it?
>
> -> https://github.com/curv3d/curv
>
> It is not fair to compare the nondefault in one language with the
> default on the other.
>
> Openscad
> cube (45);
>
> curv:
> cube 45 dontcenter=true
>         ^^^^^^^^^^^^^^
> don't know how to write that in curv yet.
>
>
> Roger.
>
> --
> ** [hidden email] ** https://www.BitWizard.nl/ ** +31-15-2049110 **
> **    Delftechpark 11 2628 XJ  Delft, The Netherlands.  KVK: 27239233    **
> The plan was simple, like my brother-in-law Phil. But unlike
> Phil, this plan just might work.
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: The OpenSCAD Language

cacb
In reply to this post by doug.moen
On 06.05.2019 16:59, Doug Moen wrote:
 > OpenSCAD is not a functional language. Functional programming is
 > all about programming with functions. But functions are not
 > values in OpenSCAD. It would be fair to call OpenSCAD a
 > domain-specific, declarative language.

Whatever you call it is not important, I was simply loosely referring to
what has been said at various times when e.g. explaining why variables
are constant in OpenSCAD.
https://en.wikipedia.org/wiki/Functional_programming

The main point as I see it is being able to do things like assign and
re-assign variables and use them for anything, including holding shapes.
Also, I prefer not to be limited to recursion when iteration is natural.
It is all about choice.  Being able to declare user defined datatypes
(classes) in the script language is another thing I want to have, so I
enabled it. The list goes on.

 > It is untrue that functional languages "by definition" disallow
 > the feature that Troberg wants: "I can't assign an object to a
 > variable and then ask that variable about the object (location,
 > size, rotation et cetera)."

The main point is you can't do that in OpenSCAD, not which paradigm you
classify the language to.

 > It would be possible, in principle, to extend OpenSCAD to support
 > the same features. But it would be a big, disruptive change to the
 > language, and that conflicts with OpenSCAD's conservative approach
 > to change. OpenSCAD is almost 10 years old and the project has
 > emphasized stability, incremental change and backwards compatibility.

That is indeed a good principle to work from, given the large user base.
However, to have alternatives is also a good thing, so I am offering one.

 > However, AngelCAD is just CSG embedded in a general purpose
 > imperative language.

You could say a Ford is just a car :-)

 > There is a lot of verbosity and boilerplate,

This is not a competition in writing a trivial example using the least
amount of bytes, at least not the way I see it. I am more interested in
the examples that are somewhat more complex.  The cases you list don't
do the same things either. If you want a minimal,complete example that
generates and exports a cube it can be written as

void main() { cube(45).write_xcsg(GetInputFullPath()); }

 > AngelCAD:
 > shape@ main_shape()
 > {
 >      cube@ cu = cube(size:45, center:true);
 >      return cu;
 > }

You can write the above in various ways,  all below are valid and doing
the same thing

// 1
shape@ main_shape()
{
    return cube(45);
}

// 2
shape@ main_shape()
{
    cube cu(45);
    return cu;
}

// 3
shape@ main_shape()
{
    auto cu = cube(45);
    return cu;
}

But, this is not a competition in writing trivial code with the least
amount of bytes. With support for different programming styles in the
same language, one can select the most natural approach in each case. I
am more interested in readability and performance than sheer compactness
of trivial cases.

The motivation behind AngelCAD is to offer flexibility, expressiveness
and speed. It is also about offering a choice, if you like it you can
use it.

Carsten Arnholm



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
rew
Reply | Threaded
Open this post in threaded view
|

Re: The OpenSCAD Language

rew
In reply to this post by doug.moen
On Mon, May 06, 2019 at 12:45:06PM -0400, Doug Moen wrote:
>     cube 10 >> translate[5,5,5]

So
  cube 10

is (behind the scenes) the intersection between
  |x| - s/2
  |y| - s/2
and
  |z| - s/2

wher s is the size (10 in the example cube)?
Or can that intersection be written differently?

        Roger.

P.S. Curv built in one go on my home machine once I started following
the instructions.
PPS: Curv built in two goes on my work machine once I installed ttb-dev.
Thank you for not using autoconf!

--
** [hidden email] ** https://www.BitWizard.nl/ ** +31-15-2049110 **
**    Delftechpark 11 2628 XJ  Delft, The Netherlands.  KVK: 27239233    **
The plan was simple, like my brother-in-law Phil. But unlike
Phil, this plan just might work.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org