• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: JSA -- now I believe this is a bug (JSA or AS)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: JSA -- now I believe this is a bug (JSA or AS)


  • Subject: Re: JSA -- now I believe this is a bug (JSA or AS)
  • From: has <email@hidden>
  • Date: Thu, 18 Dec 2014 21:54:02 +0000

Shane Stanley wrote:

> On 18 Dec 2014, at 3:58 pm, Deivy Petrescu <email@hidden> wrote:
>>
>> I wrote a script library to do a bunch of computations that are not there in Smile natively.
>
> So I had a look at _javascript_Core, and it looks like you can call it directly using ASObjC, and without WebKit. That should let you avoid using the buggy bridge business, and as a bonus, it looks like the overhead is lower -- your sample line runs 3-4 times faster.
>
> set theContext to current application's JSContext's alloc()'s init()
> set theJSValue to theContext's evaluateScript:"Math.tan((Math.PI)/3)"
> set k to theJSValue's toDouble()

Still heinously slow, and insanely complex for what it actually does. I dug out my old AppleMods Math library [1] and tried its vanilla tangent() handler. 25 times faster; plus it uses degrees, not radians, so is friendlier to an AppleScript audience too. Of course, it's not a three-line copy-n-paste, but isn't that why AppleScript includes a library loader itself now, so AppleScript users don't have to spend their lives scrabbling a subsistence in the virtual dirt?


More generally, I can't think of any good reason for calling into JXA from AppleScript, outside of the standard use case of wanting to run one already-written script from another. At least calling Python or Ruby via `do shell script` gives access those language's huge collections of standard and third-party libraries, which can make the hassle worthwhile. But JXA has no standard library and few built-in language features that aren't already available more directly to AppleScript via AppleScript-ObjC. Maybe it'd be useful for quick-n-dirty JSON parsing without having to install JSON Helper, but that's about it. Having to call all the way into JavaScript's Math functions just to calculate a piddly tangent is a giant red flag that You're Doing It Wrong.

Basic math functions are precisely the sort of functionality that should be part of AppleScript's standard library. Had the author (Chris Page?) of Mavericks AppleScript's new library loader spent a lot less time being clever and a little more time actually making it *useful* to users, such a standard library would already included in OS X and we wouldn't even be discussing this. (Seriously, what other language provides a library loader without any libraries to load???)

Instead of interminable faffing to see who can invent the least awful cut-n-paste bodge, why don't you all go demand the AppleScript team put together a real, competent AppleScript standard library for 10.11? (If they can't/won't/don't want to build it themselves, several of us users would happily develop, test, and document the whole damn thing for them completely for free.) Otherwise we'll just be having these same stupid discussions next year as well; same as last year, same as the year before that, and so on. [2]

Regards,

has

[1] <http://applemods.sourceforge.net> While I won't swear for the quality of the library code or its documentation, it should still be better than most of the slop that gets copy-pasted around. I'll happily turn the whole lot over to anyone that wants it, and it won't take more than an hour to strip out the old AppleMods Loader code and convert them to use AppleScript's built-in loader instead. Just drop us a mail off-list.

[2] I made precisely the same point a couple days ago over on a MacScripter thread regarding list sorting <http://macscripter.net/viewtopic.php?id=43442>. It is *embarrassing* what gets passed hand-to-foot-to-mouth as expertize in the AppleScript community. Application scripting? Finest brain trust in the whole world. Standard algorithms for replacing text and sorting lists? Dear gods, we make even the dumbest VB and PHP users look like Alan Turing. But don't blame the users, blame the leadership.

_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden


  • Prev by Date: Re: JSA -- now I believe this is a bug (JSA or AS)
  • Next by Date: Cannot make new Mail rule
  • Previous by thread: Re: JSA -- now I believe this is a bug (JSA or AS)
  • Next by thread: odd Numbers's behaviour
  • Index(es):
    • Date
    • Thread