7 ms·
I recently used Ink to build a small debugging CLI for a websocket-heavy project of mine. All it does is subscribe to a specific channel and print out the messa
by aloer 3y ago
I recently used Ink to build a small debugging CLI for a websocket-heavy project of mine. All it does is subscribe to a specific channel and print out the message or send dummy data when I press a specific button. The frontend websocket code could be reused easily so it was very fast to do.
Very convenient to run multiple terminals as multiple clients in parallel. Much nicer at least than something like Postman for Websocket tests.
Full screen took some time to get right and still flickers when using iterm 2. But it does work on the apple terminal and for now I am happy with that.
My only issue is that Ink does not support nested rendering / overlays, i.e. modals.
- latchkey 3y ago> I recently used Ink to build a small debugging CLI for a websocket-heavy project of mine. why not just write tests? i'm getting super down voted on this, but come on... why? this person built some buggy utility and those bugs can end up causing more problems than just writing tests in the first place. no wonder we end up with such buggy junk software... people... write tests!
- ajkjk 3y agothat's not what they wanted to do?
- aobdev 3y agoAutomated testing and debugging are not the same
- latchkey 3y agoI didn't say anything about automated. 99% of the time, I debug using tests. You write the expected output and then fill in the implementation. If you don't get what you expect, something is wrong with your code and it is easy to run it in the debugger to figure out what is wrong. At the end of that, you end up with a test and some code that works. Other people call this TDD.
- verdverm 3y agomost of the time, I write a small amount of code to work through or debug other's code. It's much easier to be consistent and capture more workflow in a script. Later this can be turned into tests or interfaces. Early on, the script offers much better visibility by typically having access to a debugger
- hitchdev 3y agoWhy not attach debugging tools to the tests?
- rickhanlonii 3y agoYeah we all know what you're talking about, you don't have to explain it. Testing is not the universally correct strategy for every case, and unless you take the time to understand their use case, you're really not in a position to understand the tradeoffs or make value statements about their work.
- latchkey 3y agoIf I had the choice of 'write a tool' or 'write a test'... I'd always pick write a test. Of course, that's me... which is why I asked the question in the first place. I was trying to understand their use case.
- mixedCase 3y agoAs you said it: Of course, that's you. But not everyone walks the same path towards robust coding, let alone coding.
- bastawhiz 3y ago> it is easy to run it in the debugger Yes. They made their own purpose-built debugger. It's a tool that makes it easier to see what the program is doing. Your debugger is no more or less valid than their debugger. It's a tool, and the best tool is the one that enables the programmer to accomplish their goal. And that's what they did.
- amne 3y agoI would argue that, based on my experience, most of the code I'm debugging is not my code so it really doesn't matter how many tests I write because the problem is I misunderstood how a library or someone else's code I'm using works or there's a bug I can't find just with tests.
- verdverm 3y agoYou're writing code against other's code, the UI seems like overhead over when you can just have a script that can effectively do the same thing. There is a term called "blackbox testing", which is more or less what we do for 3rd party code | services anyway.
- aloer 3y agoNot everything can or should be a codified test. There’s a reason postman is a billion dollar product. Just not as good for websockets Ink allowed me to quickly add a simple admin and debug UI
- vanviegen 3y ago> There’s a reason postman is a billion dollar product I guess so, but is it a good reason? It's a fancy ui for curl...!?
- anon223345 3y agoIf postman is just a fancy Ui for curl Now I’m wondering your thoughts on Burpsuite And wondering if you feel GitHub is just a fancy UI for git lol
- throwaway675309 3y agoBuilding a simple debugging tool to monitor your program for possible inconsistently reproducible bugs and having unit tests are not mutually exclusive concept. You're getting downvoted because you're making condescending assumptions about the developer.
- latchkey 3y agoI'm not being intentionally condescending. it is a valid question to ask that. i come from a strongly tdd background. i can't tell you how many times i've seen people write simple debugging tools only to have the tool be the source of the bug. ever written a println and output the wrong variable, then scratch your head why the results are wrong? websockets themselves are well debugged, similar to http. years ago, i stopped spinning up a http server just to test my endpoints. now i just call the functions directly. thus, it would be an issue with the OPs code that is sending/receiving. take websockets out of the equation and everything would work fine with tests.
- jasonm23 3y ago> Come from a strongly tdd background Friend, we need to be damned careful about how we view others code when they don't have tests or embrace TDD. When we work with TDD or even a well tested codebase, we do benefit enormously. We also risk becoming evangelical, and that almost always comes across as condescending and off-putting. TDD Tests do not capture every possible point of faillure. There's clear use cases for things like Postman, Debugging Proxys, or OPs _debugging_ tool. PSA - avoid being a hype monger or evangelist of anything, it's about the worst way to support practices or tools you believe in. Trust me, I'm not only a practitioner of TDD but also a Lisp advocate and Emacs user... All these things are the best ever thing that happened /s No, the whole world won't ever be a place where everyone is "doing it right" by your estimation, or mine, or anyone else's. Quite the opposite, so settle in and mellow your jets.
- latchkey 3y agogood response. i'm not being evangelical by asking a question. i'm also not trying to start a sermon. my response was to explain where i was coming from because i was being called condescending. i don't care about doing it right. i can ask why someone would write a tool, instead of using one of the existing ones... or writing tests. my jets are plenty mellow.
- nkrisc 3y agoThe test failed. Ok.... why?
- latchkey 3y agoExactly. Why? So you're first instinct is to write a tool to inspect websockets?
- nonethewiser 3y agoWhat role did Ink serve? I mean couldn’t you have just logged to console? I’m trying to figure out if Ink enabled you to do something at all, made it easier, or you just liked using it. All of which are fair. It seems like you just liked using it.
- alexeldeib 3y agoI think it’s rerendering the “UI” on data updates. Basically exactly the readme for ink. It’s a single log line of output, but it’s repainted in place, not appended to stdout. Sure you can do that other ways. Personally I’d love to build terminal tuis with react component!
- gkfasdfasdf 3y agoThanks I have never used react and this comment was very helpful, even after reading the project readme.
- nonethewiser 3y agothank you for clarifying. that makes sense and does sound nice to re-render the same line instead of logging a new line each time. I do think it would be simpler/faster (albeit maybe not nicer) to log a message w/ timestamp to accomplish the same thing, putting this in the "nice to have" category.
- twobitshifter 3y agoIf it’s just a single line using carriage return must be easier, right? I could see it being useful for something like a more complex tui dashboard.
- aloer 3y agowhat the other comment said, it replaces output and looks like a proper terminal UI. But it also adds features for hotkeys, progress bars, text input etc. I have it integrated into a bigger CLI project where only a few commands enter the UI. Most of them just render to stdout and are meant to be pipeable
- booi 3y agoWould this be suitable for building a terminal-themed react webpage where I’m essentially trying to simulate a terminal?
- throwaway413 3y agoCheck out https://github.com/intuit/devtools-ds https://github.com/intuit/devtools-ds
- farhanhubble 3y agoI'd be cool to use your approach to build a "frontend" for monitoring Python's TQDM output. Especially useful for multiprocess applications with scores of independent, long running processes like data ingestion pipelines. TQDM does support monitoring multiple processes but is not flexible enough for all use cases.