Script

Since mentioning my earlier involvement with DesignScript, I've been meaning to follow up with a quick post on why this programming language is different to the others people are currently using with AutoCAD.

Hence the title of the post, which stands for "Yet Another Scripting Language?", inspired by two acronyms, Yacc and YAG (this is a subject-line often used by long-time Autodeskers leaving the company and stands for "Yet Another Gone"… I'm not sure if this term is used in the outside world – a quick Google would indicate not, but then you never know).

Anyway, back to the question: why did Autodesk choose to reinvent the wheel by creating another programming language? This question was clearly asked a lot when we first started developing it, but the ultimate answer is that it's unlike anything we have today – in AutoCAD or even elsewhere, I suspect.

The primary reason it's so different is its associative nature.

[Now I'm pretty sure what I'm writing here has been covered in a number of other places, but I tend to feel it's better to be safe than sorry. And I just felt like writing something about DesignScript today.]

Let's take a look at what the term "associativity" means, in this context. Take the following pseudo-code:

a = 0

b = a + 1

a = 2

In a traditional programming language, the value of b at the end of this code's execution would be 1. The difference with DesignScript is that the associations you create in your code are remembered by the DesignScript runtime, so that when changes are made to variables others depend on, a ripple of changes makes its way through the network, updating any dependent variables. So the above code – when run from DesignScript – would result in b having a value of 3.

In itself this may not seem like a dramatic departure from what we have today, but as you flesh out a model – as described by DesignScript, specifying dependencies in your code to map relationships between geometry – you end up with something that makes it really easy to play around with variables, tweaking the design to meet your particular requirements (whether they be aesthetic or functional). This is one reason this technology is likely to see adoption in domains where people want to explore design variations.

The vision behind DesignScript is very broad: you can already integrate data coming from analysis and simulation tools (Ecotect is one such example) and the interfaces are there for developers outside the company also to integrate their own systems.

So DesignScript is intended as a way to map relationships such as constraints using code. How does it relate to existing parametric systems? It's philosophically different, in many ways: rather than building a model with the constraints built in – as meta-data on existing geometry or data in its own right – you're creating them via code. This approach has similarities to a project I came across a few years ago, where a company called Resolver Systems used Python scripting to create a spreadsheet that is essentially generated by executing code. Incidentally, I first heard about this product, Resolver One, on Channel 9. It's very interesting the conceptual similarities between it and DesignScript: both attempt to unravel inherent model complexity in a way that people can understand and manipulate as code.

One last comment about DesignScript… you might also ask "why didn't you just add some extensions to an existing AutoCAD-capable scripting language, to facilitate moving code across to it?" That possibility was certainly considered but eventually discarded: while DesignScript is ultimately a programming language – from what I recall it has a number of similarities to Scala, although there may have been other, more recent influences – one of the primary design goals was for it to be fairly easy for non-programmers to pick up. And it doesn't make sense to port or migrate your code from (say) AutoLISP or VBA to DesignScript: the philosophical differences are such that you couldn't (or wouldn't) just move code across from one environment to the other.

A final note… many of these comments and observations are based on my somewhat stale knowledge of what's been happening with DesignScript, so please don't assume what I've said here is 100% accurate. Hopefully Luke Church (who has been largely responsible for the language's design, over the last few years) will step with with comments if he sees anything glaringly incorrect.

Photo credit: See-ming Lee 李思明 SML via photopin cc

14 responses to “YASL?”

  1. "the ultimate answer is that it’s unlike anything we have today – in AutoCAD or even elsewhere, I suspect".

    Geeze. It's been sitting right there in front of us for about 20 years. It's called LISP.

    (setq a 0)

    (setq b '(+ (eval a) 1))

    (eval b) -> 1

    (setq a 2)

    (eval b) -> 3

    ; Proof:

    Command: (setq a '(+ (eval b) 1))
    (+ (EVAL B) 1)

    Command: (setq b '(+ (eval a) 2))
    (+ (EVAL A) 2)

    Command: (eval b)
    Hard error occurred ***
    internal stack limit reached (simulated)

    Of course this is obtuse only because the AutoLISP flavor of LISP doesn't provide the means to make it any less obtuse, as other complete and mature implementations of the language do.

  2. Well, you could write some C# or C++ code to do the same thing, of course. But the point is the abstraction provided by the framework and how it creates and manages relationships between variables.

    And of course there's a lot more to DesignScript - this was just introducing a few bits of background and some fundamental concepts.

    Take it for a spin and see what you think then, Tony.

    Kean

  3. Kean,
    More languages is fine, but don't you feel like the whole .net conversion never finished off because VSTA never made it into aoutocad? I recall Jerry Winters saying at AU how we were close to that, being so careful to not reveal the exact release, as if Autodesk was keeping some secret. I don't mind if they decide to do this or that, and know predictions like that are not real until they happen, but is Autodesk still on the fence about VSTA? THe advantage being not having to restart acad at every debug run. Not that this is a new question, but this topic raises it again.

  4. James,

    I'm really not at liberty to discuss any future product plans via a public blog. If you come along to DevDays (or look for information on the ADN site - or ask the ADN team via their direct support channel, for that matter) then you'll be able to find out more.

    Regards,

    Kean

  5. "you could write some C# or C++ code to do the same thing".

    Not really.

    You can define functions dynamically at runtime in C++ 11.0 and in C# (or for that matter, any CLR language), and you can also manipulate CLR functions if they are defined as lambda expressions using Linq Expressions, but those objects are language-independent CLR constructs, as opposed to language constructs comprised solely of elements of the programming language used to initially define them.

    Also, allow me to correct my previous comment.
    The LISP equivalent of your DesignScript example is actually much simpler than what I showed:

    (setq a 0) -> 0
    (setq b '(+ a 1)) -> (+ A 1)
    (eval b) -> 1
    (setq a 1) -> 1
    (eval b) -> 2

    Before going further, I think it might be helpful to kindly ask you to clarify your previous comments, regarding what precisely it is about DesignScript that is 'new', 'unprecendented', or to the best of your knowledge, does not currently exist in other programming languages.

  6. C# and C++ were used to implement the DesignScript runtime, which is the main reason I mentioned them. If you'd chosen to write and execute that code yourself, you'd have "solved" the associativity problem. A ridiculous example, of course, but one that was intended to highlight that there comes a point where it makes sense to leave this work to the framework.

    I do need to spend some more time writing about DesignScript - I'll see what I can put together this week. I'm up to my eyeballs in preparation for my AU classes, but I'll see what I can put together.

    Kean

  7. Hi Kean,

    - Thanks for this, and as usual, you're pretty much spot on. Ultimately the reason we chose to build another language, as you say, is because we can give users a substantially better user experience - that starts off easier and goes further - than would be possible if we used an existing language.

    You can already see some parts of this, like the associative language or the ability to mix and match different coding styles (associative and imperative) within DesignScript itself. We're already seeing people do things with this that would be really hard in other languages.

    And you're absolutely right that like most languages we had a bunch of inspirations from many other sources including amongst others Scala, C#, Python, Rhino Grasshopper, Processing - even Javascript, as well as less frequently known sources like EPur, ThingLab and Field/CLA.

    Looking forwards to seeing what people do with DesignScript, and btw Kean, add something glaring incorrect next time so I have an excuse for commenting 😉

    Thanks, Luke

  8. Trust me, Luke - the further I get from the basics, the easier I'll find it to add glaring inaccuracies. 🙂

    Thanks for stopping by!

    Kean

  9. But the "associative nature" are necessary not always. At the some situations it can be not the same, what necessary by programmer. Has the DesignScript syntax for both cases?
    I think, "associative nature" can give to programmers some errors, which are difficult for catching.

    Necessary to write simple examples on DesignScript and on other languages (C++/C#/Lisp) for comparison and expediency of using DesignScript instead of other languages (at the different situations). Without such substantiations the DesignScript will a nice toy only, without which it is easily possible to live.

  10. I would say that if you don't want associativity then you should be using a different language: DesignScript is going to be very useful for a certain class of design problem, but that doesn't mean it's the right tool for many others.

    Kean

  11. Hi Kean,

    I apologise for my bad English. I don't want to offend you. I really want to understand, in what situations it is better to apply this language. The best explanation - the code samples showing advantages of this language in certain situations. I will be grateful to you if in your blog there will be such examples.

    Best Regards,
    Andrey

  12. Hi Andrey,

    No offence taken! It's just that there are places this will be a useful tool, but places where it won't: I'll work with the DesignScript team to get some helpful samples posted that make this distinction more clear.

    Regards,

    Kean

  13. Andrey Bushman (@AndreyBushman Avatar
    Andrey Bushman (@AndreyBushman

    Thank you.

  14. Hi Andrey,

    I agree that there are times when its nice to not have associativity, and there are some things that are a much easier fit for 'imperative' code like C#.

    As I'm sure you'll see in later blog posts, one of the features of DesignScript is that you can change the way execution is run for a block with an annotation.

    For example the below is already supported:

    [Imperative]
    {
    a = 10;
    b = 2;
    c = a + b;
    Print (c); //prints '12'
    a = 100;
    Print(c); //Still prints '12'
    }

    On your second point - I agree we need more samples explaining the different situations that we might use the different features in. We're working on it 🙂 Thanks for the suggestion.

Leave a Reply to Kean Walmsley Cancel reply

Your email address will not be published. Required fields are marked *