• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Functional Programming?

Explorer ,
Apr 15, 2017 Apr 15, 2017

Copy link to clipboard

Copied

Just curious if anyone is using FP with their scripting?

And to what degree?

Thanks

TOPICS
Scripting

Views

651

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advisor , Apr 16, 2017 Apr 16, 2017

Javascript does support FP. But:
1) ExtendScript is not quite JavaScript, or more specifically is a implementation of EcmaScript (ECMA-262 3rd edition) stuck in the year 2000. Think of Internet Explorer 5.

2) Most of the things that make FP possible in JS are missing in ExtendScript (Array.map, Array.filter etc). Tail-end recursivity is also a no-no and even normal recursivity is iffy because memory leaks.

3) Some of the missing properties can be extended can be appended via polyfills etc, but Exte

...

Votes

Translate

Translate
Community Expert ,
Apr 15, 2017 Apr 15, 2017

Copy link to clipboard

Copied

Out of the box, InDesign supports JavaScript, AppleScript (Mac), and Visual Basic (Windows). Neither of these languages are well-known for their support of FP, which is a rather different programming paradigm -- these three fall under imperative programming languages. It may be possible to write a framework that runs pseudocode, written as FP ... but why would you? Do you see any advantages?

That said, InDesign contains a smalllish ("poor man's", heh heh) implementation of an XSLT processor, and XSLT is a proper example of FP. However, its implementation is messy (I find it's prone to crashing, and refusing even the simplest of stylesheets and/or XML documents, so I avoid it and use an external XSLT processor), and it lacks integration with the main engine of InDesign, so all you can do is move some text around.

Perhaps you can consider ScriptUI as some sort of Functional Programming, because this handles objects and message events.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 15, 2017 Apr 15, 2017

Copy link to clipboard

Copied

Javascript DOES support FP -- that's why I asked.

(I'm wondering if the investment would be worth the result)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Apr 16, 2017 Apr 16, 2017

Copy link to clipboard

Copied

Javascript does support FP. But:
1) ExtendScript is not quite JavaScript, or more specifically is a implementation of EcmaScript (ECMA-262 3rd edition) stuck in the year 2000. Think of Internet Explorer 5.

2) Most of the things that make FP possible in JS are missing in ExtendScript (Array.map, Array.filter etc). Tail-end recursivity is also a no-no and even normal recursivity is iffy because memory leaks.

3) Some of the missing properties can be extended can be appended via polyfills etc, but ExtendScript is stuck in the year 2000, so it is missing things like Object.create and property attributes, some polyfills will fail or give strange results.

4) InDesign's DOM is nat very well suited for FP because almost every access to it has side effects.

All this being said, with a bit of work and preparation you can use FP, or at least FP-like coding (side effects being unavoidable in InDesign scripting). I do it whenever I can and it makes sense.

LE: This GitHub - ExtendScript/extendscriptr: An NPM command line tool to compile modern javascript (es5 & es...  might also help you, but debugging is a major pain.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 16, 2017 Apr 16, 2017

Copy link to clipboard

Copied

Thanks. This what what I was looking for;

Like everyone I wish Adobe would update ExtendScript...

I've Polyfilled map and filter so far -- and run into the object.create issue with a few of the prototypes. Memory leaks are a problem I've run into as well.

I'm going to keep experimenting -- like you said, it makes sense. (My original goal was to minimize the side effects but the other benefits of FP can come in useful, within the limits of the DOM)

And thanks for the link -- downloading now. Looks like it might be very useful

Thanks again

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 19, 2017 Apr 19, 2017

Copy link to clipboard

Copied

LATEST

This might be useful too:

https://github.com/fabianmoronzirfas/extendscript.prototypes

HAven't had a chance to test them yet though

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines