[rkward-devel] JS in rkwarddev [was: splitting repos?]

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Sat Oct 24 19:05:08 UTC 2015


On Sat, 24 Oct 2015 19:02 +0200
meik michalke <meik.michalke at uni-duesseldorf.de> wrote:
[long snip]
> changing this would mean really deep changes in the package with the
> risk of breaking it. i'm not so sure this is worth it.

Absolutely. My main point was actually: The exact naming of the JS-vars
won't matter too much in the first place. (And if there was an approach
that can't assign such names in the first place, I would not consider
that a show-stopper). If you really care about specific variables /
names, you can declare and "get" them, manually. If you don't, chances
are, you're always referring to the corresponding R/rkwarddev object,
anyway, and so you're never going to see the variable names at all.

> however, i have added some new options to plugin2script() that will
> allow you to use the first method: naming the R objects in the script
> code is much easier than trying to get the JS vars to match those
> objects at an uncertain later point.
> 
> > One new suggestion for a templating solution: Make it _look_ as if
> > it was JS-code all along:
> > 
> >   var my_thing = getValue (RKD(ID(my.R.object)));
> >   // optionally quoted, in case it may be needed, in some places
> >   var my_thing2 = getValue (RKD("ID(my.R.object2)"));
> >   // some common things like "getting" might have easy access:
> >   var my_thing3 = RKD.get(my.R.object3[, getter=...]);
> >   // keep in mind that often you don't really _have_ to use JS
> > variables // at all:
> >   if (RKD.get (my.R.checkbox.object)) {
> >     echo ("doSomethingFancy()\n");
> >   }
> >   // for some things there'd be less automatism, but that doesn't
> > mean // we can't integrate advanced stuff:
> >   RKD(rk.JS.save(my.R.saveobj));
> 
> all of this would mean some major changes in the workflow of the
> package, and i'm not convinced yet that this is the right way to go.
> it would also mean returning to editing several files for one plugin.

True. But actually, that was pretty much the starting point for my
thoughts, because
  a) yes, that syntax highlighting; I just can't seem to live without
  this anymore...
  b) as far as I understand, having several files is pretty much the
  current state-of-the-art for plugin2script from existing plugins such
  as rk.Teaching.
But in fact, there are possible middle-grounds between these: I believe
what bugs me most is the frequent and non-trivial context switches
between JS and R. But why not write JS-code like e.g.

rk.paste.JS ("
  var x = getString ('", id (x), "');
  if (getBoolean ('", id (narm), "') {
    x += ', na.rm=TRUE';
  }
")

inside an rkwarddev-script. That example is possible today, and I
imagine this might be less difficult to generate from existing JS than
the current "recommended practice". It also has at least one advantage:
Keeping _the logic_ mostly in one language.

Building on this, consider the following dummy code:

rk.paste.JS ("
  var x = ", rk.JS.get (x), ";
  if (", rk.JS.get (narm, logical()), ") {
    x += ', na.rm=TRUE';
  }
")

I.e. it should be possible to reduce the quoting madness a bit, without
moving the logic itself to R.
 
> to make reading the R script a bit more comfortable, i have just
> added a new function called jo() ("JavaScript operators") which at
> least makes writing if() conditions more straight forward.
> 
> old way (still works):
> 
>   ite(id(x, " != \"\""),
>     echo(", select=c(", x, ")")
>   )
> 
> new way:
> 
>   ite(jo(x != ""),
>     echo(", select=c(", x, ")")
>   )
> 
> that is, operators like !=, ==, > etc. are prevented from evaluation
> by jo() and pasted as-is to the JS code.

Neat hack! But not a path I'd like to go, personally. To be honest,
those ite()-statements just give me the shivers, in the first place.
It's simply a pradigm that helps spreading the logic between (literal)
JS and R (from which JS is to be generated), and I just fail to see the
actual benefit. (Ok, I would see the point, if you could actually move
_all_ logic from literal JS to R, but that does not seem to work out).

Why not write the above as:

rk.paste.JS ("
  var x = getString ('", id (x), "');
  if (x != '') echo (', select=c' + x + '));
")

Regards
Thomas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.kde.org/pipermail/rkward-devel/attachments/20151024/1a4cef36/attachment.sig>


More information about the rkward-devel mailing list