Kchat: Persistent group chat in <50 lines using kdb+/k/q web sockets, JavaScript
github.com
github.com
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.
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.
I can actually query and understand tables in a very fast REPL in a way that would require 20-30 lines of SQL, nested subqueries, etc.
Even things like the way "left joins" work in KDB feels more natural than left joins in other SQL databases. https://code.kx.com/q/ref/lj/
B[A, on="x"] # A left join B
B[A] # same, assuming x is the key column on both, like K's lj [x;y]
A[B, on=.(x, y<=foo)] # right non-equi join // kdb+/q
t: ([] sym:`AAPL`IBM`GOOG; price: 139.09 124.23 948.82; vol: 123456 98765 54321)
# R
df <- data.frame(sym=c("AAPL", "IBM", "GOOG"), price=c(139.09, 124.23, 948.82), vol=c(123456, 98765, 54321))want an ip address as an integer?
.z.a
-1062731737i
what about TLS connection status? 0N!h".z.e";
`CIPHER`PROTOCOL!`AES128-GCM-SHA256`TLSV1.2
absolutely beautiful languageLol. Seriously though, that's how all of these kinds of $DO_SOPHISTICATED_THING in $ABSURDLY_FEW lines goes.
- 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
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.
Most federated system have one large server that has many users.
What bothers me the most about xmpp is that only the barebones stuff is in the main spec and everything else is in extensions which creates a complex maze of support by servers and clients alike.
I've used both but I like matrix the most. Its bridges also seem the most mature.
Understood but as a user I don't want core functionality like history to be hidden behind extensions which may or may not be supported or need additional components to client or server.
As a user (and home server operator) I found that Matrix+Element gives me a much better user experience with much less fuss (though I admit it was more than 5 years ago when I last ran ejabberd). And the bridges are amazing, just what I needed. Because Matrix is not very useful until everyone uses it, for the transition there are bridges.
I don't really care about the underlying architecture, I just want it to easily provide me a modern chat experience.
I won’t disagree with this. It could be a part of the main spec, but there’s some novelty knowing you could do a ‘complete’ server or client in a day. There are certainly different modern expectations than compared to IRC. Compared to the OP, barebones XMPP is much closer to a ‘simple chat’.
> bridges
XMPP + libpurple were trying to do similar things. For a hot minute everyone, even the like of Facebook Chat and whatever Google’s chat was named at the time, was using XMPP til they all decided to go for a proprietary option and users had the option to chat from anywhere with anyone. That doesn’t discount Matrix for doing something needed now. Proprietary chat lock-in runs in cycles. Here’s to hoping they don’t adopt & abandon Matrix.
Novelty sure but it's not really complete in terms of what a user expects. I still use IRC a lot too but with a client that provides all the mod cons I need. Also, nobody writes a protocol handler from scratch anymore. People writing a matrix client will simply use libmatrix.
There's just the reality that "simple chat" akin to ICQ in its early days, is just not what people want anymore. It's not a benefit anymore IMO.
I think the XMPP community is really too focused on architectural cleanliness than on offering the user what they want. Which is their prerogative, sure. But it's mine to choose the chat network that suits me best. This is how I moved to Matrix.
> XMPP + libpurple were trying to do similar things. For a hot minute everyone, even the like of Facebook Chat and whatever Google’s chat was named at the time, was using XMPP til they all decided to go for a proprietary option and users had the option to chat from anywhere with anyone. That doesn’t discount Matrix for doing something needed now. Proprietary chat lock-in runs in cycles. Here’s to hoping they don’t adopt & abandon Matrix.
Yeah I know, they killed federation, I guess mainly because of marketing. If google chat users can reach facebook chat users there's no need to sign up for facebook chat, thus less data mining for facebook, and lower numbers in their growth hacking charts. Keeping users in the walled garden is a goal, not a side-effect.
This is also why I dislike Signal so much, they even ban other versions of their supposedly open client. I'll never adopt that as a whatsapp replacement because it's simply no better in terms of lock-in. I don't want yet another walled garden. Signal solves one or 2 problems of whatsapp but for me to adopt something as the be-all-end-all chat app it will have to solve all or at least most of them.
It doesn't really matter if the third party apps adopt Matrix and stop federating. It won't be any worse than it is now. I'll just bridge where needed.
> resilience against servers going down
The matrix model and the XMPP model are different. They solve orthogonal problems. Even the matrix people say it. That's like saying emails are better than github for collaboration because they are resilient against servers going down: it's true, but it's a different model. Not suitable for everyone.
> resilience against malicious federation
Wait for matrix to be taken up by big tech companies, you'll see spam flooding. I don't welcome it, but it's all about economics
> Json instead of XML
This is both subjective and shows the lack of understanding that extensibility is, and how json only does 1/10 of what proper XML can do.
> unified specification
Not all XMPP usages are the same. If you want messaging, you use the compliance suites, which are specs: https://xmpp.org/extensions/inbox/cs-2022.html#im
> handling of E2EE with multiple devices and message history
Has been working for years already: https://xmpp.org/extensions/xep-0384.html
> not need to rely on other servers for media access
Part of the standard installation of prosody and ejabberd, arguably two of the most known servers, for years. A few lines in the conf.
Matrix solves problems and creates others. Your information is outdated by almost a decade, which probably explains why you think matrix solves these.
Can you elaborate on this a bit more? Specifically what can XML do that JSON can't?
I know the feature set is technically larger (eg namespaces, schemas, etc), but AFAIK all those features aren't necessary for transporting messages.
I even consider some things in XML (or at least in common implementations) to be nuisances, like collapsing elements into properties, or some accepting either or both without a schema, and I'm never sure what the precedence rules are. Also, due to being a simpler spec, JSON is more widely available, and generally faster to parse too.
Put XML inside XML, which is most useful for wrapping. Extensibility is built-in, so any parser knows it has to deal with namespaces; it doesn't depend on the flavor of the library.
> I know the feature set is technically larger (eg namespaces, schemas, etc), but AFAIK all those features aren't necessary for transporting messages.
It's not necessary for transporting messages, but both protocols go way beyond messaging. How do you send an invite for a party and a fallback if it isn't understood by the other side ? In XMPP you use namespaces; in JSON you have to define yet another schema that will only be used by your app and everyone else must copy it.
> Also, due to being a simpler spec, JSON is more widely available, and generally faster to parse too.
I'd like to see actual numbers of real software before believing the parsing speed even matters. A matrix server has to sync with dozens, sometimes hundreds of servers, some of them being extremely slow. I don't think the speed of parsing changes anything.
Plus, the spec is simpler indeed, but it is too simple. Namespaces solve a real problem, it's a mistake to not have them.
It was simple: UI/UX experience:
* each server supported different set of features * each client supported different set of features * some of them (like gateways to other chats) were "generic" enough that power users were needed to set them up, even if they worked extremely well * Most chats were "text-mostly" with shitty html subset, which was just worse for power and normal users alone compared to now-near-standard "markdown + reactions"
Will you get your chat history on given combination of client and server ? Who the fuck knows
Will you have direct data transfer work ? Who the fuck knows
Can you share file to a group chat ? Who the fuck knows
"Oh look markdown is popular, lets IMPLEMENT SOMETHING ELSE THAT'S SIMILAR BUT INCOMPATIBLE" https://xmpp.org/extensions/xep-0393.html and other great XEPs... I swear whoever is running that is smoking crack
And the XEPs. Millions of them. There is no version of protocol to target by client or server, there is not even "level of features" (lets say "text only", "text + voice", "text + video conferencing"), no, pick and choose, and on both server and client site.
XMPP is absolute mess and mountain of design by committee
Yes, there is. But your entire comment is based on years-old view of what XMPP was
482 of them. A XEP is how someone proposes a feature, and how the community collaborates around the protocol's development. Many XEPs never gain enough traction to be marked as "stable", and they get automatically deferred after a year.
This means out of the 482 XEPs, a much smaller number are actually required to implement working stuff in XMPP.
Hopefully this solves the common misconception, which you seem to have, that you have to implement every XEP. Some aren't even dealing with protocol changes, some are only informational, and some only pertain to client or server features.
> There is no version of protocol to target by client or server, there is not even "level of features" (lets say "text only", "text + voice", "text + video conferencing"), no, pick and choose, and on both server and client site.
False. We publish annual "compliance suites" which contains an array of features and two compliance levels for each ("core" and "advanced").
You can browse XMPP software by compliance levels here: https://xmpp.org/software/
You can find the 2022 compliance suite here: https://xmpp.org/extensions/xep-0459.html and the 2023 edition is due to be finalized soon.
> XMPP is absolute mess and mountain of design by committee
This is your subjective opinion. You're welcome to it, of course. But accept that I (and many others) do not necessarily share this opinion.
Perhaps the state of things are different. This was about a year and a half back.
The fact is that XMPP has been, and still is, happily deployed at scale in various scenarios. You're welcome to your opinions, but they are just that.
Disclaimer: I'm a full-time XMPP developer and executive director of the XMPP Standards Foundation.
And this argument, also, can be applied to almost any mature technology. Remember, there are nuclear reactors in use today that are running happily and safely on PDP-11s programmed in PDP-11 assembly.
Granted, the comment you replied to was not particularly constructive, but it does mirror my own experiences and difficulties with XMPP in the past. This kind of handwavy dismissal does not exactly inspire confidence the situation has improved.
My comment was not intended as an empty dismissal of all XMPP criticism. I'm happy to discuss and debate concrete criticisms of XMPP (contact info in my profile). But the parent post did not provide any such, only what sounds like a negative subjective experience whenever they last encountered XMPP. I don't think one person's opinion ought to decide if something should "die and stay dead", when there are so many projects and products built around it, and people using it daily to solve actual problems.
XMPP has evolved massively over the past 20 years. Is it perfect? No (show me something that is!). Do we continue to improve it? Constantly.
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.
Here's an open source implementation of 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.
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
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://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.
https://developer.apple.com/documentation/usernotifications/...
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)
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...
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...
Setup stress testing and worked flawlessly. Impressive work author.
For the former, because the developer wanted to use Javascript.
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.
POST to an iframe to keep the page from reloading on send.
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.
# cat > a.outTerminal #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.