Arc Forumnew | comments | leaders | submitlogin
Visualizing dataflow in contemporary languages
4 points by akkartik 3954 days ago | 6 comments
This isn't really about arc or lisp or programming languages, but I made something I wanted to show y'all.

I just came across an interesting article to syntax-highlight not keywords and other syntactic categories but variable names: https://medium.com/p/3a6db2743a1e

This idea has something in common with IDEs that highlight all occurrences of the word at the cursor. But it can certainly be valuable to see multiple words at once, or to see the dataflow without care for where the cursor is.

On the other hand, highlighting everything might be too noisy.

What to do? Think for a while, then see my solution: http://www.reddit.com/r/programming/comments/1w76um/coding_in_color/cezpios



2 points by rocketnia 3953 days ago | link

"This idea has something in common with IDEs that highlight all occurrences of the word at the cursor."

This is a feature I miss when I can't have it. I bet this highlighting would really help when reading printed-out code or code examples on a blog.

---

Your approach isn't semantic, in the sense that it doesn't discriminate between similarly named variables based on the language's actual scoping rules, but I wouldn't worry about that too much. When I name two variables the same thing, they usually are related in some way. Sometimes they all hold the same value most of the time, or sometimes they all have the same syntactic significance (e.g. CPS callbacks), or if all else fails... they have the same name. ^_- If it annoys me that they're highlighted the same way, it probably also annoys me that they have the same name.

---

You may also be interested to know that Nulan (well, the last stable version of Nulan) highlights variables differently depending on whether they're macros, locals, or non-macro globals.

-----

1 point by akkartik 3953 days ago | link

Yeah I've run into this already. In the screenshot for my original solution I highlighted a variable called test. Oops, poor name. Trouble is that this change now causes poor names in tightly localized contexts to bleed through the entire codebase :/

There's two directions to solve this:

a) Automatically detect variables with long lifetimes (measured in lines) to highlight. Perhaps this is a refinement of highlighting for

  *globals*
b) A way to attach metadata on a per-function or per-fragment basis. Highlight test in this function but not elsewhere, etc.

-----

1 point by akkartik 3953 days ago | link

Heh, I just thought of a name for the plugin that turns the bug into a feature: synaesthesia.vim :)

-----

2 points by rocketnia 3953 days ago | link

There was some interesting discussion on that in the Reddit thread. :)

-----

2 points by akkartik 3953 days ago | link

You got me, that's where I stole the idea from.

-----

2 points by thaddeus 3953 days ago | link

Very cool.

I would prefer sticking with the highlighting of syntactic categories, while being able keyboard toggle which category I want highlighted.

-----