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

meik michalke meik.michalke at uni-duesseldorf.de
Sun Oct 25 16:23:51 UTC 2015


hi,

nice discussion, btw ;-)

Am Samstag, 24. Oktober 2015, 21:05:08 schrieb Thomas Friedrichsmeier:
> > 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...

there is highlighting, but it's for R, not JS. i mean, if you want the 
highlighting for JS, wouldn't it be much more straight forward to have the 
rkwarddev script in one window and the generated JS file next to it in another 
window, and not mix too much quoted JS syntax into the R code or quoted R 
calls in the JS code?

>   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.

i think of plugin2script() as only a tool to help a one-time transition from 
an existing non-rkwarddev plugin, to one that will be managed with the 
rkwarddev script from then on. naturally you are dealing with the several 
files of the original plugin at the beginning. but once the script is 
finished, you wouldn't use plugin2script() any more.

actually, what i originally intended to ask (with regards to the JS code in 
rk.Teaching) was not so much to optimize the rkwarddev script code, but to 
review the *existing* JS code of the plugins, *before* it will somehow™ be 
generated by the rkwarddev script.

> 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';
>   }
> ")

you *can* do that, there are just various reasons why i wouldn't *like* to do 
it this way.

for once, i'd have to think in JS syntax again (like, don't forget to close 
your statement with ";"). this might be the main difference in our views on 
this -- if i understand you correctly, you would like to get back closer to 
the actual JS code, whereas i would like to get as close to R (or as far away 
from JS) as possible. both directions don't mix so easy :-o

also, there wouldn't be any win here regarding the missing syntax 
highlighting, because the JS code would need to be quoted (see below).

then there's little things like "what was the getter function for this element 
again?" i tend to forget things like these all the time, and that's always 
slowing me down. i don't want to even have to think about whether i have to 
declare this variable or not, for my taste that's too far down on the JS 
level. i want to keep just to "if this box is checked, do that", so all i 
really have to care about is:

 ite(narm, "x += ', na.rm=TRUE'")

or quicker for checkboxes:

 tf(narm, opt="na.rm")

> > 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.

oh, why's that? ite() is purposely almost identical to R's ifelse(), except 
it's allowed to use NULL for its "else" value, which also is the default. it's 
rather one of my favourites, because it's so easy to use...

> (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).

yeah, that would be optimal. and i agree, it's most likely never going to be 
achieved. 

> 
> Why not write the above as:
> 
> rk.paste.JS ("
>   var x = getString ('", id (x), "');
>   if (x != '') echo (', select=c' + x + '));
> ")

well, at least for now this gives us

  var x = getString ('
  x
  ');
  if (x != '') echo (', select=c' + x + '));

instead of what rk.JS.scan() + ite() generate:

  var x = getString("x");
  if(x != "") {
    echo(", select=c(" + x + ")");
  }

what's more, the ite() example has proper syntax highlighting:
 http://reaktanz.de/stuff/R/JS_examples.jpeg
which would immediately warn you about that missing single quote in the echo() 
call that you easily miss in the fully quoted JS code.

just a vague idea: would it be possible to make the syntax highlighting scheme 
of RKWards R console *output* configurable? it's plain green by default, if 
you could (temporarily) set that to use one of kate's highlighting schemes 
(e.g., XML or JS), this would at least make debugging rk.JS.* statements on a 
console level easier -- you wouldn't have to wait for files to be written. no 
idea if this is simply a character stream that could easily be pumped through 
a highlighting filter before it's shown on screen.


viele grüße :: m.eik

-- 
  dipl. psych. meik michalke
  institut f"ur experimentelle psychologie
  abt. f"ur diagnostik und differentielle psychologie
  heinrich-heine-universit"at d-40204 d"usseldorf
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/rkward-devel/attachments/20151025/701d33b9/attachment.sig>


More information about the rkward-devel mailing list