Fork me on GitHub
#editors
<
2018-08-06
>
bozhidar06:08:55

@pez No, nothing special. We’ve been polishing the Elisp bencode code for quite a while and it’s pretty reliable at this point.

dominicm06:08:11

@pez just a quick theory, if your network callbacks aren't complete, then perhaps you're receiving chunks? e.g. di6e followed by i3ee

dominicm06:08:20

I've been wondering about whether this can happen.

dominicm06:08:39

I mean, it definitely can, that's just TCP.

dominicm06:08:58

@bozhidar does elisp bencode stream?

bozhidar07:08:26

I don’t remember at this point to be honest. Haven’t touched this code since the early days of the project.

bozhidar07:08:52

I just remember it was pretty buggy, we fixed some bugs and forgot about it. 😄

dominicm07:08:55

python-nrepl couldn't handle negative numbers or empty lists for a very long time.

dominicm07:08:30

Only a clojure programmer would have made the mistake, empty lists are falsey in python 😄

bozhidar07:08:06

I do remember that the Emacs bencode also didn’t handle negative numbers in the beginning.

dominicm07:08:48

I think it's a common mistake to overlook

dominicm07:08:20

https://github.com/clojure-emacs/cider/pull/616/files I see something here for handling incomplete streams. @pez

pez07:08:23

t seems that when the result is large it is chunked up, yes, but the chunks are not encoded correctly, by what I can see. That is probably my error, when adding stuff to the buffer. Hmmm… Thanks for that question, @dominicm!

dominicm07:08:35

I wrote a lot of C code as a teenager, I now have a bit of a sixth sense for network problems and race conditions. It's a little trigger happy, but I like it that way 😄

pez07:08:38

In fact I get decode errors for some non-large result values as well, but I haven’t looked at that yet, I do think empty lists and negative numbers are handled, though. 😃

dominicm07:08:10

@pez I found generative testing amazing for this. I can highly recommend pairing your encode/decode functions in a generative test.

dominicm07:08:28

It ironed out all of the problems in python-nrepl-client (from what I can tell, anyway)

pez07:08:22

I’ve never looked at generative testing. It seems to be time to open that box now.

pez07:08:34

(In case it isn’t obvious I am still very much a Clojure (and functional) noob. I can even admit to not having groked functional fully yet. Still waiting for that “click”… But that is why I am rewriting Calva in ClojureScript, eventually it has to happen!)

dominicm07:08:53

I had been waiting a very long time for a chance to use it 😄 It doesn't come up so often.

dominicm07:08:16

I suspect that's a function of the way the codebases I work on are written too though.

dominicm07:08:30

Most of it is side effecting, and very little of it is data pushing & business logic.

pez07:08:40

I am trying to factor the Calva code so that ClojureScript is doing almost only data pushing and business logic, and then keep the side effecting out in the TypeScript glue into VS Code.

dominicm07:08:20

that makes sense, that should be amenable to generative testing then 🙂

pez07:08:01

I am pretty sure it is. But I haven’t even looked at spec yet, so I have some learning to do. Guess I should be happy there is still so little of Calva ported to CLJS yet. 😃

pez07:08:25

BTW, I heard that @bozhidar hates spec and generative testing. 😃

dominicm07:08:20

spec and generative testing do pair, but test.check can be used without spec.

pez07:08:01

I must find a way to test this programmatically anyway, the manual way I am doing it now is driving me mad.

dominicm07:08:51

I've just been trying to wrap tests around pack (uberjarring command line tool I wrote). It's surprisingly hard. I wanted something that ran the CLI and tested that the jar behaved correctly. I've found so many bugs in shell-based harnesses. It's really hard to integration test non-http things. Vim does have some harnesses about, but I haven't tried writing tests for replant yet, in the fullness of time I suppose I should though 🙂

dominicm07:08:03

What does testing VSCode look like?

bozhidar07:08:11

> BTW, I heard that @bozhidar hates spec and generative testing. 😃

bozhidar07:08:14

Really? 😄

bozhidar07:08:01

I don’t like spec in its current form, that’s true, but I don’t hate idea in general. Although I do feel that it goes against the nature of dynamic programming languages to a large extent.

bozhidar07:08:45

I don’t have anything against gen testing, but in my experience the touted benefits are rarely strongly pronounced.

👍 4
dominicm07:08:31

It's either a great fit or a terrible fit

dominicm07:08:48

https://lispcast.com/testing-stateful-and-concurrent-systems-using-test-check/ That is a lot of effort for just k/v, I suspect the complexity here is exponential, so that's a lot of work for most systems.

pez08:08:44

I do hope that smiley did its work when I put words in your mouth, @bozhidar ❤️

pez09:08:45

@dominicm I haven’t looked much at testing in VS Code. For Calva Formatter (a separate extension) I have unit tests on the CLJS side, but I can’t leverage them fully because I have stubbornly stuck to keeping my tests together with the functions they are testing and cljs,test do not discover them. I might give up un that, but have so far now and then tried to figure out how to get the testrunner to see them… Sometimes I wish I was less stubborn about things.

pez09:08:12

I found Eric Normand’s talk about making composable abstractions very interesting, even though most of it flew over my head. He is specing his way forward in the process: https://youtu.be/jJIUoaIvD20

bozhidar12:08:41

Btw, @pez, I think that probably you and other people who can work directly with JS or CS in their editor would probably benefit a lot from a native JSON/EDN transport in nREPL.

bozhidar12:08:12

That should be pretty simple to setup and would save you from bencode completely.

pez12:08:02

transit even?

bozhidar12:08:20

Well, we can have a transport in whatever format we want.

bozhidar12:08:42

Bencode was chosen for the default transport with the assumption it would be easy for many editors to support it.

pez12:08:49

My experience with JSON and ClojureScript is that it can be slow, but EDN makes total sense.

bozhidar12:08:11

I think that for the small messages that are typically encoded probably any format will do. 🙂

bozhidar12:08:27

But yeah - obviously the more efficient the format, the better.

pez12:08:52

Going from JSON to Transit sped up the initialization of SPA I am working with (for food) magnitudes.

pez12:08:39

And that was not huge amounts of data, even though larger than typical nREPL results.

pez12:08:24

Anyway, what would it entail? Updating nREPL?

bozhidar12:08:32

The problem is that ideally nREPL should not have 3rd party deps, as they can conflict with something in the project of the people using it.

pez12:08:21

Makes sense.

bozhidar12:08:46

But yeah, we just need a different transport function that uses say EDN and that’s it.

bozhidar12:08:15

The encoding/decoding will be trivial then.

pez12:08:26

Want me to pack a PR?

bozhidar12:08:59

Yeah, that’d be great is you’re willing to tackle this.

pez12:08:38

Seems like a Good First Issue ™️

bozhidar12:08:05

It’d be nice if we added some small tutorial on the subject.

pez12:08:36

Anything I need to know about how to hack on this project?

dominicm12:08:56

it would be quite neat if there was a cli-friendly way to inject a transport :thinking_face:

dominicm12:08:15

OTOH, using bencode everywhere is super beneficial as it means you can connect to any arbitrary nrepl server.

bozhidar12:08:34

@pez Just a normal Clojure project. Nothing special about it. There’s a section on hacking in the manual, but it’s pretty basic.

bozhidar12:08:34

@dominicm Well, if there were more bundled transports that wouldn’t really change anything. After all each transport defines it’s own protocol, so you can use all of them depending on your preference.

bozhidar12:08:46

(I might not understand your reservation, though)

dominicm12:08:37

@bozhidar as long as all are loaded, sure. But you end up with people saying "Oh, emacs uses bencode, I'll start that" and http/edn never gets loaded.

bozhidar12:08:43

As for the injection of transports - that shouldn’t be hard, but I think something like an json or edn transport should probably be built-in.

dominicm12:08:56

json without a dependency is very unlikely

bozhidar12:08:11

I think the JDK has something built-in.

dominicm12:08:51

huh, so there is

bozhidar12:08:20

I just remember that had something built-in for XML, so probably they caught on the json front as well. 😄

bozhidar12:08:00

> But you end up with people saying “Oh, emacs uses bencode, I’ll start that” and http/edn never gets loaded.

bozhidar12:08:35

Well, if the EDN parser for Emacs matures that might change. Time will tell. 🙂

dominicm12:08:56

Sure, but then vim hangs out on bencode and it's still true 😉

dominicm12:08:45

Choice is okay, except when you want to try and have a uniform interface. Then you get things like content negotiation. At that point we should use http 😄

bozhidar12:08:05

Yeah, of course.

bozhidar12:08:51

There’s another reason why more transports (json in particular) have been on the back of my mind - which such a transport it’d be easy to expand nREPL to an LSP implementation. 🙂

bozhidar12:08:04

(although you can obviously just proxy an LSP server to nREPL)

dominicm13:08:43

I'm waiting for the latter to happen before I consider the former.

bozhidar13:08:49

Yeah, baby steps.

dominicm13:08:07

Overall, bencode has been surprisingly good. It's got limited expressivity which sucks (transit over bencode anyone?) but writing a bencode decoder/encoder is difficult primarily because of handling streaming in the language, which is quite fundamental anyway, you'd have to do the same with JSON. I'm quite a simple programmer, and bencode is well within grasp for me to write a parser/encoder for. Json, not so much.

bozhidar13:08:15

No argument here. But there’s also the point it’s unlikely you’ll have to write a json parser yourself. 🙂 Anyways, Let’s bench the json idea for now and only focus on edn.

dominicm14:08:16

I'm just thinking out loud really. I wonder if an json streaming parser exists for most languages.

pez16:08:15

Hmmm, there is no write in clojure.edn, right?

pez16:08:12

My computer goes super hot and then becomes quite unresponsive working with the nREPL project. Seen something like that, @bozhidar?

bozhidar18:08:55

> Hmmm, there is no write in clojure.edn, right?

bozhidar18:08:09

I’ve never used it, so I can’t answer that one. 🙂

bozhidar18:08:17

> My computer goes super hot and then becomes quite unresponsive working with the nREPL project. Seen something like that, @bozhidar?

bozhidar18:08:23

First time I hear this. Did you notice anything in particular that triggered this? Sounds like some infinite loop or something, but who knows…