Live data from Hacker News

Stages of denial in encountering K

nsl.com

411–420 of 432 posts

Re: Stages of denial in encountering K

#411
post #126

People are so quick to reject K and APL-style languages for superficial reasons that they never get to the deep and interesting reasons! I am mostly familiar with APL, but I think the things I appreciate and dislike are about the same in K. One interesting philosophical difference, at least among some APL programmers, is that building abstractions should be avoided. TFA has a hint of that philosophy, in its suggestio…

What is TFA?

> the use of "nested arrays" (not the same as multidimensional arrays) induces pointer structures that are difficult to do anything with

J doesn't allow nested arrays by default; if you want to create such a structure, you have to use boxes (and then unbox the values inside of them to get at them), which makes it explicit and reduces its usage. AFAIK, k doesn't have nested arrays at all.

Re: Stages of denial in encountering K

#412
post #404

Earlier quoted context omitted.

Counter is not in Python's prelude. Therefore you have to import it in order to use it. My comment about prelude was in response to you saying I was using Python's “language+plus-its-entire-ecosystem”. This is not true; Counter is part of the standard library that comes with the language. It is not from a third-party package. > If it takes that many keystrokes, you're definitely only going to use it once per year! Th…

> you saying I was using Python's “language+plus-its-entire-ecosystem”. This is not true; Counter is part of the standard library that comes with the language. It is not from a third-party package. I'm not sure I agree "third-party package" is a good/useful place to draw the line, but I don't think it's terribly important. Sorry. > you almost never care about the index of a value in a hash table (because it's ridicul…

I wouldn't want to use an index as a long-lived key like that, since it makes ops like deletion a footgun.

For temporary calculations I'd just `{u: Url(u) for u in url_strings}` for the table of URLs, and stick the `Url` objects in the table of events.

Re: Stages of denial in encountering K

#413
post #404

Earlier quoted context omitted.

> you saying I was using Python's “language+plus-its-entire-ecosystem”. This is not true; Counter is part of the standard library that comes with the language. It is not from a third-party package. I'm not sure I agree "third-party package" is a good/useful place to draw the line, but I don't think it's terribly important. Sorry. > you almost never care about the index of a value in a hash table (because it's ridicul…

I wouldn't want to use an index as a long-lived key like that, since it makes ops like deletion a footgun. For temporary calculations I'd just `{u: Url(u) for u in url_strings}` for the table of URLs, and stick the `Url` objects in the table of events.

I don’t understand any of this. I don’t know what footgun is. I have no idea what a “URL” object is or how you stick it in a table of events (on disk? in memory? in a remote process called a “database”). I’m don’t know what you mean by temporary calculations.

I have fifty billion of these events to handle every day, and I do this on one server (that is actually doing other things as well). It is not an option to “just” do anything at this scale if I want to keep costs under control.

Re: Stages of denial in encountering K

#414
post #347

Earlier quoted context omitted.

It shows no such thing. It shows that you have found something you think you can be productive in and that you like, not that the rest of us are on the wrong track.

I can't agree. (BTW, I don't like K, and I don't use it, but if I did I'd like to think I'd be productive in it.) This little system runs circles around entire sub-industries of other software. The fact that it exists and uses one or two orders of magnitude less time and code than other systems is significant. It's like axes vs. chainsaws. If the job is to log a forest the latter will be better than the former.

Less code is entirely irrelevant unless for some reason you're concerned about a few k of storage for your source, less time appears to be speculation.

If people can make working, maintainable software other ways, particularly if those other ways have large, established ecosystems of dependencies, then they are likely doing it right regardless of how much you like apl.

Re: Stages of denial in encountering K

#415
post #355

Earlier quoted context omitted.

> But it's an external database with its code and its optimizations. You're completely mistaken. It's not an "external database". That's a regular, ~600kb interpreter download from kx.com Those lines are all the lines typed into a q) prompt one at a time on my laptop (A 1.6ghz macbook air). > In this case it seemed that it was just doing a binary search, Yes. That's all okon does as well, they just do it over a B-tre…

> I can't honestly believe anyone that thinks spending twenty days on a problem is better than five minutes. Nobody thinks that and I didn't say that. I was talking about that specific file (although the rest of them are equally unapproachable). > If you can't get there, it's going to be really hard to talk about what's amazing in k! Well, the thing is that at this point the only amazing things that have been talked…

> Nobody thinks that and I didn't say that. I was talking about that specific file

I hope nobody thinks that, but unless you can come to terms with the fact that you're wrong, and that this is a completely fair comparison, you're going to be the guy who writes okon2 at some point instead of using a better tool.

> the only amazing things that have been talked about is that it's fast (in some specific use cases of data queries)

Those weasel words are preventing you from seeing what should be obvious:

The k program is faster, shorter, obviously correct, and it took less time to write.

That's the amazing thing. Who doesn't want that?

> What more reasons are there to use it?

This is the wrong way to think about things, because there's an infinity of such reasons. Instead, invert it: You should always use the best tool you can. If you don't know k, it can never be used even if it would otherwise be the best tool.

I don't recommend people use k (except when it works), but I recommend people learn k because it'll make them better programmers.

> which downsides does it come with?

The biggest downside is that you don't know it, and the only person who can fix that is you

Re: Stages of denial in encountering K

#416
post #413

Earlier quoted context omitted.

I wouldn't want to use an index as a long-lived key like that, since it makes ops like deletion a footgun. For temporary calculations I'd just `{u: Url(u) for u in url_strings}` for the table of URLs, and stick the `Url` objects in the table of events.

I don’t understand any of this. I don’t know what footgun is. I have no idea what a “URL” object is or how you stick it in a table of events (on disk? in memory? in a remote process called a “database”). I’m don’t know what you mean by temporary calculations. I have fifty billion of these events to handle every day, and I do this on one server (that is actually doing other things as well). It is not an option to “jus…

Sorry, it's a bit weird not sharing a lexicon. I get the impression Q is a whole different genealogy of programmers.

In Python, although you can just use shelve to store data on disk, in practice this is considered a bad idea beyond very simple cases. Valuable data wants the guarantees that real databases provide, like ACID. shelve doesn't provide this, and IIUC nor does kdb+.

So if you're handling 50 billion events a day, live, and you need these to persist, you'd use SQL or something similar. That would then ultimately determine how you add and manipulate records.

If you don't care that much if you lose the data on a crash, that's when we're talking about temporary calculations. In Python, rather than having two tables like (eg.)

URLs:

    url_id  url          count
       1    google.com    300
       2    python.org    400
       3    example.net   200
Requests:

    request_id   data   url_id
        1       'spam'     2
        2       'eggs'     2
       ...
       900       'ham'     1
you would make a custom type, aka. ‘Url’, containing ‘url’ and ‘count’ as object fields, and then store your requests as a list containing references to those ’Url’s.

    urls = {
        "google.com":  Url("google.com",  300),
        "python.org":  Url("python.org",  400),
        "example.net": Url("example.net", 200),
    }

    requests = [
        Request("spam", urls["python.org"]),
        Request("eggs", urls["python.org"]),
        ...,
        Request("ham",  urls["google.com"]),
    ]

Re: Stages of denial in encountering K

#417
post #413

Earlier quoted context omitted.

I don’t understand any of this. I don’t know what footgun is. I have no idea what a “URL” object is or how you stick it in a table of events (on disk? in memory? in a remote process called a “database”). I’m don’t know what you mean by temporary calculations. I have fifty billion of these events to handle every day, and I do this on one server (that is actually doing other things as well). It is not an option to “jus…

Sorry, it's a bit weird not sharing a lexicon. I get the impression Q is a whole different genealogy of programmers. In Python, although you can just use shelve to store data on disk, in practice this is considered a bad idea beyond very simple cases. Valuable data wants the guarantees that real databases provide, like ACID. shelve doesn't provide this, and IIUC nor does kdb+. So if you're handling 50 billion events…

> ... like ACID. shelve doesn't provide this, and IIUC nor does kdb+. So if you're handling 50 billion events a day, live, and you need these to persist, you'd use SQL or something similar. That would then ultimately determine how you add and manipulate records. …

ACID is overrated. You can get atomicity, consistency, isolation and durability easily with kdb as I'll illustrate. I appreciate you won't understand everything I am saying though, so I hope you'll be able to ask a few questions and get the gist.

First, I start write my program in g.q and start a logged process:

    q g -L
This process receives every event in a function like this:

    upd:{r[`u?y`url;y`metric]+:1}
There's my enumeration, saved in the variable "u". "r" is a keyed table where the keys are that enumeration, and the metric is whatever metric I'm tracking.

I checkpoint daily:

    eod:{.Q.dd[p:.Q.dd[`:.;.z.d];`r] set r;.Q.dd[p;`u] set u;r::0#r;system"l"}
This creates a directory structure where I have one directory per date, e.g. 2020.03.11 which has a file (u or r) referring to the snapshots I took. I truncate my keyed table (since it's a new day), and then I tell q the logfile can be truncated and processing continues! To look at an (emptyish) tree right after a forced checkpoint:

    total 24
    drwxr-xr-x  4 geocar  staff  128 11 Mar 16:59 2020.03.11
    -rw-r--r--  1 geocar  staff    8 11 Mar 16:59 g.log
    -rw-r--r--  1 geocar  staff  206 11 Mar 16:55 g.q
    -rw-r--r--  1 geocar  staff  130 11 Mar 16:59 g.qdb

    geocar@gcmba a % ls -l 2020.03.11 
    total 16
    -rw-r--r--  1 geocar  staff  120 11 Mar 16:59 r
    -rw-r--r--  1 geocar  staff   31 11 Mar 16:59 u
The g.q file is the source code we've been exploring, but the rest are binary files in q's "native format" (it's basically the same as in memory; that's why q can get this data with mmap).

If I've made a mistake and something crashes, I can edit g.q and restart it, the log replays, no data is lost. If I want to do some testing, I can copy g.log off the server, and load it into my local process running on my laptop. This can be really helpful!

I can kill the process, turn off the server, add more disks in it, turn it back on, and resume the process from the last checkpoint.

You can see some of these qualities are things only databases seem to have, and it's for that reason that kdb is marketed as a database. But that's just because management has a hard time thinking of SQL as a programming language (even though it's there in the name! I can't fault them, it is a pretty horrible language), and while nobody wants to write stored procedures in SQL, that's one way to think about how your entire application is built in q.

That's basically it. There's a little bit more code to load state from the checkpoint and set up the initial days' schema for r:

    u:@[get;.Q.dd[.Q.dd[`:.;last key `:.];`u];{0#`}];
    r:([url:`u$()]; req:0#0; imp:0#0; clk:0#0; vt:0#0);
but there's no material difference between "temporary calculations" or ones that will later become permanent: All of my input was in the event log, I just have to decide how to process it.

Re: Stages of denial in encountering K

#418
post #335

Earlier quoted context omitted.

Do you really think you could not, even after taking a few weeks to study and practice?

Probably not, no. I could easily see myself becoming dejected after printing out a few cheat sheets and buying some relevant books. I would have attempted some exercises and done whatever toy projects with an increasing feeling of dread that I was simply aping what was before me only to find what I thought I had learned had slipped away in a weekend. Should I get much further than that, I would then try to solve an a…

That's a pretty good set of things to visualize if you want to feel defeated before you even get started.

I write K for a living, and J for fun. J is WAY crazier, and I learned it specifically because it was so weird and crazy. I kinda wanted to remember what it was like to be a beginner again.

In all these languages, you can always fall back to doing things the "old way"... They all pretty much support structured and functional programming with loops and functions and whatnot. It's just there are lots and lots of shortcuts, and you get used to them over time.

(Also for what it's worth, the communities around vector languages do tend to be pretty friendly and welcoming...)

Re: Stages of denial in encountering K

#419
post #392

Some context often missing form these "code golf" showcases: Domain specific languages have syntax optimized towards specific tasks. This often means very compact symbolic expressions which looks completely inscrutable to outsiders but are highly efficient when you know the language. String processing in Perl, pointer arithmetic in C, selectors in jQuery. Nobody can guess what the code does by looking at it, you have…

I don't think he was actually arguing that K is domain-specific, he was just observing that it seems that way to outsiders.

If anything, the most successful applications seem to be with databases (not math), but it's also pretty great for interactive graphics:

https://github.com/JohnEarnest/ok/tree/gh-pages/ike

I work at the same company as the author, and we use K3 for all kinds of things -- system administration, network servers, interactive web apps.

It's a pretty general purpose language. And you can even do old-school loops if you want. It's just very concise.

Also, in K, there's a whole set of one-or-two-character symbols that allow you to express other uses of loops in traditional languages.

Re: Stages of denial in encountering K

#420
post #375

Earlier quoted context omitted.

> With most of the array languages, it is commercial, so I'd be cautious about building a business around it K/Kdb/q seems very happy with this state of affairs, which is really strange: if they O/S'd it I could see a lot of goodwill/mindshare going their way, but I think their Morgan Stanley roots view O/S as commie nonsense. Meanwhile, it's definitely viewed as legacy in the bulge-bracket banks that use it b/c it's…

K/Kdb/q seems very happy with this state of affairs, which is really strange: if they O/S'd it I could see a lot of goodwill/mindshare going their way It's not too hard to grok: if they freed it, they'd lose money. $200,000,000 in revenue last year from Kx alone. Goodwill compared to cash, executive picks cash every time. I have no idea what Shakti's doing, but they, too, are probably making a substantial amount of m…

> I have no idea what Shakti's doing, but they, too, are probably making a substantial amount of money.

I'd think AW would be more concerned about legacy and impact than just $$$ at this point -- tradetech has long stopped being a significant source of innovation in computer science as it's essentially iterating on the same problemset from the 00s.

OTOH I suppose having a small cult has its benefits, as opposed to actually giving something to the larger world, O/S isn't exactly a cakewalk.

Post reply on HN