9 ms·
Kchat: Persistent group chat in <50 lines using kdb+/k/q web sockets, JavaScript
- 1vuio0pswjnm7 3y agoWhy use Javascript?
- revskill 3y agoIt's fast.
- tcfhgj 3y agoNot really
- sgtnoodle 3y agoReminds me of an interview I conducted years ago. I asked the candidate what they would do to make their code run faster. They suggested using the V8 JavaScript engine so that it would be JIT compiled. We were talking about code written in C++, intended to be run on an embedded microcontroller... Also reminds me of many years ago in college, when somebody gave a presentation claiming that java was unquestionably more efficient than C++. I had a lot of questions...
- lynx23 3y agoOnly tangentially related, but this reminds me of a MCSE training I once attended in the 90s, where the trainer claimed Microsoft Passwords are so secure that they can not be cracked in a reasonable amount of time. I couldn't hide my amusment. Since this got him fired up, he went as far as saying "If you believe otherwise, find my password!" to which I replied "No need for that, already done." Thanks l0phtCrack, you made my day.
- 1vuio0pswjnm7 3y agoI met many Microsoft lawyers over the years who behaved the same way. The enthusiasm is effective perhaps, even when it's grounded in ignorance. MS is like a cult.
- samwillis 3y ago> more efficient I was going to make a quip about efficiency being more than execution, with development efficiency also being important. But then with it being a comment about C++ vs Java I decide not to...
- kindawinda 3y agoWhy ask a question that will spawn a comment thread about language superiority without testing or acknowledge what the author provided? Setup stress testing and worked flawlessly. Impressive work author.
- croes 3y agoCritique or honest question? For the former, because the developer wanted to use Javascript.
- Sosh101 3y agoWhy use anything?
- vidarh 3y agoOn the server? As an example of equivalent (to the k and q versions) code. On the client? Because endlessly refreshing the page to refresh chat messages is an awful design that we had enough of already in the 90's.
- HotGarbage 3y agoCould be done with long polling or a never-closing HTTP response. POST to an iframe to keep the page from reloading on send.
- deleted 3y ago[deleted]
- vidarh 3y agoThat's true, and those options are also awful options we used in the 90's and promptly abandoned once better options became available, though they wouldn't make that much difference here. The alternatives are all brittle and limited in different ways.
- IshKebab 3y agoWell sort of. Server Sent Events is basically "official long polling" and it works very well. Way simpler than websockets in many cases. Websockets is obviously better here though.
- vidarh 3y agoThe point isn't that the way the data is sent from the server matters much, but that using javascript to handle the retrieval is beneficial. The first Javascript enabled chats still relied on the same methods of retrieval for a long time, but still significantly improved usability.
- holoduke 3y agoBecause its the most convenient language on the client there is.
- 1vuio0pswjnm7 3y agoThis submission would not have made the front page unless I jump started some discussion. Mine was the first comment. It worked. Front page. Years ago I had used k-based chat, with GUI, on Windows. Without Javascript. (Many years ago, k used to have a built-in GUI.) "Why use Javascript" was a genuine question.
- BozeWolf 3y agoFun! Combine it with ios notifications for web apps and rename the title of this post to “<60 lines”. https://developer.apple.com/documentation/usernotifications/sending_web_push_notifications_in_web_apps_safari_and_other_browsers https://developer.apple.com/documentation/usernotifications/...
- HotGarbage 3y agoIt's sadly more than 10 lines, server and client side. https://peter.hotgarba.ge https://peter.hotgarba.ge
- asim 3y agoSomething about the simplicity of the UI is so refreshing. Thanks for sharing.
- toastal 3y agoThis reminds me that XMPP needs to make a comeback. Its push-oriented nature is efficient, was largely built in a time when we didn’t expect users to have unlimited data, and the eXtensible part has allowed it to modernize with multi-device encryption, loading chat history, etc.
- srgpqt 3y agoMatrix is arguably the modern successor to XMPP.
- Jiejeing 3y agoIt is a bit weird to frame one of two competing protocols as the successor of the other, when the only data point for this assertion is that one is older.
- tcfhgj 3y agoMatrix basically solves problems of XMPP: - resilience against servers going down - resilience against malicious federation - Json instead of XML - unified specification - handling of E2EE with multiple devices and message history - not need to rely on other servers for media access Probably more, this was just off the top of my head
- toastal 3y agoMatrix has its de facto centralized server in Matrix.org where almost all rooms will have its data sent through because of accounts joining rooms. The servers have been too heavy/expensive for self-hosting that many end up relying on the big servers to use (maybe the Rust server will help, Dendrite?), but the “resilience” mentioned is a big cause for this expense (similar issues with Mastodon). JSON isn’t superior to XML--it can be in some cases but it’s not without drawbacks; experimental EXI could help with the size. XEPs are an ad hoc unified spec, and the buy-into-or-not nature has some advantages where it’s easier to experiment and fallbacks are common even with fragmentation. OMEMO isn’t perfect, but it does cover multi-device encryption and carbons work to get message history. I like Matrix. But I don’t think it’s the only or best solution despite all of the current hype; the XMPP solution should be looked at more often. XMPP offers additional flexibility as well not being limited to just a chat/communications platform where folks use it for presence, UnifiedPush, etc.
- ddoolin 3y agoI forget about k/q every time until it shows up here. It seems like something fun to learn but that I'd have no practical use for personally.
- leprechaun1066 3y agohttps://spacetraders.io/ https://spacetraders.io/ is API based. Considering that q is used for trading and analysis in the real world seems like it's a good way to go on an adventure.
- ddoolin 3y agoThis is pretty cool, thanks for sharing.
- huhtenberg 3y agoPfft, chat.k is still just way too verbose compared to the good old # cat > a.out
- nivertech 3y agoEach chat participant opens 2 bash terminals: Terminal #1 $ touch chat.txt $ tail -f chat.txt # or $ watch chat.txt Terminal #2 $ echo "${USER}: hello" >> chat.txt $ echo "${USER}: hello, again" >> chat.txt $ echo "${USER}: bye!" >> chat.txt Also there are builtin UNIX/Linux CLI commands to send messages to users.
- Kiro 3y agoWhat is kdb+/k/q? The link to kx.com didn't tell me much.
- jpfr 3y agok and q are array languages in the APL tradition. APL is one the "ur programming languges". https://madhadron.com/programming/seven_ur_languages.html https://madhadron.com/programming/seven_ur_languages.html Here's an open source implementation of k: https://codeberg.org/ngn/k/ https://codeberg.org/ngn/k/ kdb is a time-series database with deep integration to k. It is famously used in the financial industry.
- LukaD 3y agoCame here to ask the same. kx.com is just some marketing page. I still have no idea what kdb+/k/q is.
- duskwuff 3y agoIt's a somewhat esoteric, and extremely terse, language used by some financial modeling firms. Influenced heavily by APL, but (thankfully!) without the non-ASCII characters. https://en.wikipedia.org/wiki/K_(programming_language) https://en.wikipedia.org/wiki/K_(programming_language)
- curiousgal 3y agoIt's also used by every investment bank who's active in the algo/e-trading business.
- ssfrr 3y agok: super terse language inspired by APL and lisp q: slightly less-terse language written in k, with similar semantics. The vendor (kx) supports q, not k kdb+: column-oriented database bundled with q
- steveBK123 3y agoSkip all the marketing materials & go to the dev pages - https://code.kx.com/q/learn/install/ https://code.kx.com/q/learn/install/
- samwillis 3y agoPrevious thread from 2015: https://news.ycombinator.com/item?id=9120246 https://news.ycombinator.com/item?id=9120246
- vrglvrglvrgl 3y ago[dead]
- swyx 3y agoa more scalable and readable version of this today would prolly use something like a partykit.io
- Avshalom 3y agoN.B. https://code.kx.com/q/ref/dotz/ https://code.kx.com/q/ref/dotz/ is doing the heavy lifting here.
- bshimmin 3y agoThis is such a helpful comment - what looks, to the uninitiated, like line noise actually starts to make some sense now!
- Paul-Craft 3y agoLol, yes! That language looks like it was optimized for code golfing or something.
- Avshalom 3y agoIt was optimized for interactive use by people that already know it.
- TeMPOraL 3y agoWhich is a nice target to have. Makes me want to learn the language. Modern tech is so obsessed with high-turnover, sale-by-first-impression user growth toy software mindset, that it completely forgot about the idea of creating and optimizing tools for people who use those tools day in, day out.
- giraffe_lady 3y agoNo it didn't come on. Languages and libraries are still written by developers, who make tools based on their experiences and preferences using tools. A dense tersely named standard library is simply not pleasant to use for most people, and so most people won't develop one for themselves or others to use. Something that's easy to understand on a first impression is easy to understand on every subsequent impression as well. At least in terms of languages and libs no one is optimizing for that first impression, it's just a byproduct of making it easy to use in all cases.
- foul 3y agoSuch an incredible stack.
- brenns10 3y agoAs an alternative to web sockets and JavaScript, can I offer my alternative (ok, it's not persistent chat) implemented with character devices as a Linux kernel module? I don't know if it still works, but it has the same name :) https://github.com/brenns10/kchat https://github.com/brenns10/kchat
- austinjp 3y agoStrange set of comments in this thread. Personally, I'd not heard of k or kdb before so this was an interesting read. The code is from 9 years ago, and looks to me like a proof of concept. It's a kinda stepping stone between the 90s approaches * mentioned in sibling comments and the bloat of the modern web. * A truly amazing and dreadful time. The commercial (and artistic/indie) web pushed developers to twist immature technologies and create perverse superpowers. Never-closing responses in hidden iframes. Constantly exploiting JS engine bugs as features. Disgusting fun.
- paulgb 3y agoThis is a fun code golf challenge. 42 lines of JS with DriftDB[1]: https://codesandbox.io/s/distracted-wildflower-3jhtjq?file=/src/App.js https://codesandbox.io/s/distracted-wildflower-3jhtjq?file=/... Each time it opens generates a new room, but you can copy/paste the URL of that room to access the same room (for up to 24 hours) [1] https://github.com/drifting-in-space/driftdb https://github.com/drifting-in-space/driftdb
- mianos 3y agoAll good except the 50K a year license to run 'q'.
- plagiarist 3y agoOh, yikes. I was interested in following up reading about kdb and now I am not.
- steveBK123 3y agocost is for commercial license only free for personal use for 12 months, then you click some buttons to renew another 12 months, etc https://kx.com/kdb-personal-edition-download/ https://kx.com/kdb-personal-edition-download/
- shin_lao 3y agoPer core
- leprechaun1066 3y agoAzure has prices that vary: https://azuremarketplace.microsoft.com/en-us/marketplace/apps/firstderivativesplc1596469572732.kx-insights?tab=PlansAndPrice https://azuremarketplace.microsoft.com/en-us/marketplace/app... That's for commercial though. One can get a personal use license for hobbies as other commenters have pointed out.
- steveBK123 3y agoPeople paying $MM/year for SaaS that does less, but have prettier websites
- mianos 3y agoNo doubt, kdb/q is offers a of bang for buck in a commercial scenario. We use it and for some stuff it's good value, aside from staffing costs.
- prettyStandard 3y agoIs there a difference between .htm and .html? I never thought so, and noticing they chose .htm reenforces my belief.
- prettyStandard 3y agoFor the most part the same, but .htm hails from win 3.x days because of 3 character file extension limitations, while *nix did not. https://stackoverflow.com/a/138957 https://stackoverflow.com/a/138957
- whalesalad 3y agowow throwback chrome ui on windows 7 bringing a nice wave of nostalgia this morning