Building a Reactive Library from Scratch in Vim 9 Script

61 views
Skip to first unread message

Lifepillar

unread,
Dec 29, 2023, 12:58:51 PM12/29/23
to vim...@googlegroups.com
Today I was entertaining myself with articles about the "reactive
programming" paradigm so popular nowadays, such as this:

https://dev.to/ryansolid/building-a-reactive-library-from-scratch-1i0p

As I could not understand that code, I decided to port it to a sane
language:

https://gist.github.com/lifepillar/d44e6ca33f0b1f66a0b403e133413699

The task was pretty straightforward, I must say. The code still leaves
much to be desired (among the rest because I've tried to deviate from
the original as little as possible), but it works well.

Enjoy!
Life.

Steve Litt

unread,
Dec 30, 2023, 4:41:30 PM12/30/23
to vim...@googlegroups.com
Lifepillar said on Fri, 29 Dec 2023 17:58:32 -0000 (UTC)
Thanks Life!

I had a chuckle when you called Vimscript a "sane language". I'm more
of a Lua or Python or C guy myself. But looking at your code, it looks
like the Vim9 script language is a big improvement over that old viml
stuff.

Anyway, could you please summarize what you see as the benefits of
reactive programming? As a guy who has used a lot of callback routines
(C, Perl and Python) in his life, I kinda sorta maybe understand at a
gut level, but I don't really fully understand the benefits in a way I
could explain or use them.

Thanks again for this ultra-cool post!

SteveT

Steve Litt

Autumn 2023 featured book: Rapid Learning for the 21st Century
http://www.troubleshooters.com/rl21

Lifepillar

unread,
Dec 31, 2023, 9:45:40 AM12/31/23
to vim...@googlegroups.com
On 2023-12-30, Steve Litt <sl...@troubleshooters.com> wrote:
> I had a chuckle when you called Vimscript a "sane language". I'm more
> of a Lua or Python or C guy myself. But looking at your code, it looks
> like the Vim9 script language is a big improvement over that old viml
> stuff.

That was basically the sense of my post. I consider Vim 9 script the
last gift, and one of the most precious ones, Bram left us. My post
expresses my appreciation for the effort of the developers who are
building up on that gift: things are getting really really good! I was
pleasantly surprised that Vim did not crash or misbehave when fed with
some weird snippets such as that Russellian Subscribe() function :)

> Anyway, could you please summarize what you see as the benefits of
> reactive programming?

I can't really speak of the merits (or lack thereof) of reactive
programming. I have just started rewriting the style picker of my
Colortemplate plugin in Vim 9 script. There, the main problem is keeping
the attributes of a highlight group in sync with a bunch of UI widgets,
so it seemed to me like a good chance to explore some alternative
approaches.

From what I have seen so far, a reactive approach has some potential to
simplify my code both in terms of the amount needed and in terms of
correctness. The devil's in the details, of course, so maybe I will
eventually hit some wall and scratch everything. But I'm learning new
things and having fun, and that's what matters to me at the end of the
day.

Life.

BPJ

unread,
Jan 2, 2024, 6:13:57 AMJan 2
to vim_use
Whatever happened to "as effective as possible with as little code as possible"? ;-D

(Yeah I know. I don't either. Type checking library, anybody? No bonus points for guessing which language I'm using!)


Reply all
Reply to author
Forward
0 new messages