8 ms·
A look at the J language: the fine line between genius and insanity (2012)
- mwexler 6y agoFunny, that phrase can also describe k itself... It's a mindset, or cult, depending on who you chat with about it. Very powerful, and somewhat obtuse, which often go together. Fwir, Kdb+ is written in k which is sorta APL, and then there's q for writing kdb+ programs which is easierish. But still an adventure.
- rscho 6y agoPeople always compare J, K and APL as if they were almost identical apart from the character set, but that's far from the truth. https://aplwiki.com/wiki/Array_model#:~:text=In%20APL%20it%20is%20the,multidimensional%20FORTRAN%20or%20C%20arrays https://aplwiki.com/wiki/Array_model#:~:text=In%20APL%20it%2....
- ggrrhh_ta 6y agoAPL and J are different between themselves (I started with APL but jumped into J) like FORTRAN and C are... What is your point?
- systems 6y agoBut do they implement the same programming paradigm, or is there any fundamental differences For example, C# and Java implement the same paradigm , they are different, many argue which provide a better set of feature, but I would not call the differences fundamental C#, F#, implement completely different paradigms F# and Clojure, same paradigm, but have fundamental differences, F# being static and come from the ML family , Clojure dynamic and come from the Lisp family So APL to J, is more like what to what, C# to Java, or F# to Clojure ??
- Jtsummers 6y agoIt's more like C# to Java. Setting aside the different character sets used, a lot of code written in one can be translated almost directly to the other. Whereas F# and Clojure, while using many similar idioms, have fundamentally different approaches to types which significantly alters your program structure and design approach. Both J and APL work on the same type of things (principally, arrays and nested arrays) with functions being applied over the arrays or across multiple arrays. And both languages encourage a point-free or tacit style of programming (though J, from my limited experience with both, seems to push this a bit further sometimes). For a functional paradigm example it's probably more like the difference between SML and Ocaml, or between two similar lisps like Common Lisp and Emacs Lisp. There are clear differences in focus in the two language designs, but much more in common (again, setting aside the choice of characters, you can find an equivalent for most APL symbols in J and vice versa without needing to create too many new definitions).
- rscho 6y agoAPL and J are similar but for a pretty fundamental difference: APL has nested array theory while J is flat array theory. In practice, this does not make them that different to the user, except APL's model is arguably more elegant since it's "turtles all the way down" (J array elements are not array themselves). K on the other hand, is really different! K doesn't have true multidimensional arrays, but lists of vectors. So it's ideal for its use case: finance (1d/2d numeric tables).
- ggrrhh_ta 6y agoI see now your point. And as you say it does not make a lot of difference to the user. I have never used K.
- ggrrhh_ta 6y agoThat is what I was meaning, to me C and FORTRAN are mostly "the same" except at a surface level, and FORTRAN has multidimensional arrays and regions (a slight abstraction that can help the compiler, in particular, for automatic parallelization of loops)
- WillDaSilva 6y agokdb+ is written in C, but q is (largely) written in k. One of the first things kdb+ does on startup is load the file `q.k`, which is a k file which defines the q language. The interpreter then switches from interpreting k to interpreting q. Interestingly enough you can fairly easily program your own language (written in q/k) on top of that, and set the interpreter to evaluate that language by default. Kx offers a Python integration layer called EmbedPy which (among other things) exposes a Python evaluator as the "p" language in kdb+.
- scottlocklin 6y agoThe TSDB is now called 'jd'[0] FWIIW. Funny, I've been using J on and off since then and I'm still not sure if it's genius or insane. It, along with the other APLs, is definitely its own thing, just as much as Lisp is (my previous favorite weird language was Yann LeCun and Leon Bottou's "Lush,"[1] which I continue to think is an amazing design). Once you get a little bit proficient at it, you finally realize what an actually high level programming language could be. I think it's an idea whose time has come in some ways: hardware is more array-like than ever. J has evolved a lot from 806 to the present 902 beta; lots of performance increases from moving away from the single core paradigm (where it excelled anyway). Lots more to unlock there as well, and some interesting J-based startups brewing[2]. I also think it's one of the best user communities I know of. Oh yeah, Art's new language Shakti[3] should probably be mentioned. Lots of people excited about this. [0]https://code.jsoftware.com/wiki/Jd/Overview https://code.jsoftware.com/wiki/Jd/Overview [1]http://lush.sourceforge.net/ http://lush.sourceforge.net/ [2] https://www.monument.ai/ https://www.monument.ai/ for example [3] https://shakti.com/ https://shakti.com/
- 7thaccount 6y agoI'm still waiting for Shakti to have more info on their site. As on now, it seems like it is more tailored for Art's traditional clients of banks and not the common engineer.
- jloveless 6y agoSee shakti.sh for downloads and some minimal .d (docs)
- smartmic 6y agoThe user community is really outstanding. Just have a look on https://stackoverflow.com/questions/tagged/j https://stackoverflow.com/questions/tagged/j Questions are answered in no time, the folks are very friendly and treat everyone on eye level. A great role model for any programming language / software communities!
- marmaduke 6y agoI started with Lush a long time ago before being obliged to switch to MATLAB and then C. Recently I have been trying to learn Futhark which is a ML like language generating parallel code (E.g. OpenCL or CUDA) from pure functional code with nested array structures. I find this exciting because when using the GPU with a thin layer like OpenCL directly, you have to write kernels from scratch without much abstraction possible. Higher level APIs like PyTorch or Jax give you easy ways to flexibly structure the computation but you just have to hope for kernel fusion. In Futhark this is in principle explicit and well handled. ISPC is another example of a C like language where SIMD style parallelism is unambiguous while staying relatively high level.
- djmetzle 6y agoI would see J solutions to Project Euler problems a lot, and they would often be the most terse and cryptic solutions. Good introduction. Its always nice to see a "community review".
- aloe_falsa 6y agoShameless plug: I'm currently working through Project Euler problems using J, and the language is obscenely well-suited to this kind of problems. The terseness has grown on me, as for the other thing - well, I guess code in any language can look like line noise, it's all up to the programmer. Please take a look at https://ciumei.ca/blog/2020-07-25/j.html https://ciumei.ca/blog/2020-07-25/j.html and do let me know if the code is at all cryptic.
- klysm 6y agoI found them surprisingly readable as someone with no prior J /APL/OtherBlackMagic experience :)
- Verdex 6y agoI've learned a bunch of different languages[1], but J (and its friends APL and K) has been both the one that I don't feel I have the patience to learn AND the one that I feel like I might fall in love with if I actually learned it. The incomprehensible programs just seem to hint that there is some sort of maximal information density where every keystroke provides maximal productivity. There's also something artistically appealing about starting at a program and making a deliberate one character change that makes all the difference ... although on the other hand, that's kind of scary too. Here's a video that really illustrates the power of this paradigm: https://www.youtube.com/watch?v=a9xAKttWgP4 https://www.youtube.com/watch?v=a9xAKttWgP4 [1] - I learned (in this approximate order): C, Java, Lua, C#, Ruby, Python, Lisp, Forth, Prolog, Clojure, OCaml, Haskell, Erlang, F#, R, Racket, and Rust. I also took a look at languages like: ATS, Cyclone, C++, Idris, Agda, D, and Perl 6. Of all those languages it really feels like APL/J/K are the strange ones.
- Cactus2018 6y ago> Here's a video that really illustrates the power of this paradigm: https://www.youtube.com/watch?v=a9xAKttWgP4 https://www.youtube.com/watch?v=a9xAKttWgP4 Amazing game of life code!
- Verdex 6y agoThe first time I watched the video my response was that he was literally doing magic or that it was some sort of joke. Over time the video has become more approachable and I have a pretty good idea of what is going on. However, if I was asked to approach game of life in APL myself then I think I would still be pretty lost.
- Cactus2018 6y agoA Sudoku Solver in APL https://www.youtube.com/watch?v=DmT80OseAGs https://www.youtube.com/watch?v=DmT80OseAGs
- dTal 6y agoIt's a kind of sleight of hand. It purports to be showing off the power of APL; what it's really showing off is the cleverness of someone who realized that the rules of Life could be expressed as a series of array operations. APL has a kind of mystique, but all it really is is a bunch of NumPy functions with a quirky DSL (of course, APL came first and heavily inspired NumPy). But we've quietly been doing the APL experiment in the background, by pressuring programmers to avoid pure Python in favor of NumPy functions for speed, and the results are in - you can indeed push the array paradigm very far. But not quite far enough to be general and efficient. The jury is still out on whether the quirky DSL is worth anything. My suspicion is that having names for array operators is very valuable indeed, but dedicated symbols for them much less so, and cryptic ASCII digraphs are barking completely up the wrong tree. But if you really want the weird syntax - well, it's not exactly a difficult language to parse, and Unicode is a thing now. If the notation is worthwhile, there's no real reason why any language couldn't have APL built-in as a DSL, just like regex.
- ethagnawl 6y agoSomeone who was _very competent_ with J gave a demo of it at one of the Recurse Center (ne Hackruiter) _Brain Dump_ meetups back in the day and broke the crowd's collective brain. It might as well have been Brainfuck to all of us, but the proof was in the ... STDOUT. I believe they were demonstrating the standard factorial, map/reduce, etc. sorts of solutions you'd expect, but I remember being shocked by the small amount of code required to achieve the desired outcome. To the point the article appears to make, this may or may not be a good thing in terms of team productivity and maintainability, but it was damn impressive.
- Archit3ch 6y agoThere's a very elegant Haskell quicksort implementation that misses out on performance because it's not in-place. It's frequently used as a demonstration. The performant version looks as bad as C. I'd be more interested in a J/K demonstration that plays to the language's strengths. How about live-commentating e-sports? * Player gets first blood. Commentator executes search query in J across DB. * "We've seen $PLAYER_NAME contribute to 65% of first blood situations across their last 10 matches."
- beagle3 6y agoIdiomatic K solutions (and from what I hear, J as well) tend to be faster than idiomatic C solutions to the same problems. It originally seemed like magic to me, but really - there is no magic. It is simpler in K and J to process more things, in more stages, but with completely predictable and very pipelineable operations. The J/K program often does 2 or 4 times as many operations, but has virtually everything prefetched to L1 before it’s needed so it runs as fast or even faster. CPUs are constantly converging towards the K model (GPUs were always there).
- smabie 6y agoIf there was a time for array languages, it would be now. I would argue that most programming nowadays is about manipulating arrays of data.
- 6y ago
- grimgrin 6y agoHere's the response they got asking their n00b question: http://jsoftware.2058.n7.nabble.com/Spatial-trees-td25879.html http://jsoftware.2058.n7.nabble.com/Spatial-trees-td25879.ht... Link in article was dead
- scottlocklin 6y agoThanks; updated
- JRaspass 6y agoShameless plug: https://code.golf https://code.golf supports J if you'd like to compete with cryptic line noise :-) I don't claim to understand J, I just added it to the site.
- Buttons840 6y agoJ seems like a language I should learn using flash cards. Make a flash card for each character, for each operation, and just learn all the operators, and then I will know J. Any truth to this? I suppose it might be like telling someone, "you know conditionals and loops, now you know how to program!"
- gmfawcett 6y agoIn my experience -- flash cards might help a little, but writing code is the only way to internalize it. Read the books/tutorials and follow along until your feet are a little wet. Keep in mind that it's not just about the verbs (operators) in isolation, it's also about sentence structure. While you can get quite far in the language without learning how to write a fork or a hook (two related ways of combining verbs), it will be near impossible to read someone else's code until you practice these forms yourself. Having said that, if you're anything like me you will have the NuVoc page [1] open basically all the time while writing or reading J. It's hard to keep them all straight, esp. the verbs that you don't use very often. [1] https://code.jsoftware.com/wiki/NuVoc https://code.jsoftware.com/wiki/NuVoc
- Jtsummers 6y agoI've been experimenting with flashcards that prompt me to write or solve some problem, versus the more common memorization usage. Not necessarily solving the same problem (write FizzBuzz in SomeLang) but maybe more complex (select a public web API with a JSON source, get the data, process it, and make a simple report). A way to reinforce understanding of different libraries or tools. I haven't figured out the scheduling on that in Anki yet, though. The same ratings can still be applied, even if it takes an hour to do it it's "how easy was that hour?" Did I have to pull open a lot of language and library references? Was I able to, without much effort, create the basic project template and start filling it out? Or did I have to look up the details on defpackage again? Then combine that with more explicit memorization/recall cards like I use for Spanish. "In Common Lisp what non-destructive function filters a sequence based on a predicate?" "remove-if". I think this should work well as a way to develop an understanding when paired with books/tutorials on the language and its libraries.
- RyanHamilton 6y agoSome of these languages are an excellent fit for specific problems. I still think an array based language is best for sql queries rather than set based. Any time you hear something like "select the first....", you don't want a set, you want an ordered list. Plug: I wrote an open source version of q/kdb that runs on the JVM: https://github.com/timestored/jq https://github.com/timestored/jq You can give it a try online in the browser here: http://www.timestored.com/jq/ http://www.timestored.com/jq/
- mdaniel 6y agoIt appears you forgot some references to your home directory in the code: https://github.com/timestored/jq/blob/1f4de6def8b7c12c6d6254296dcd24a2e7f1eca6/genie/src/main/java/com/timestored/jdb/codegen/Genie.java#L23 https://github.com/timestored/jq/blob/1f4de6def8b7c12c6d6254... Also, Java's "File" object is -- for the most part -- by its nature cross-platform, which is why the forward-slash version right below your change already worked as expected: https://github.com/timestored/jq/commit/4b94ce214452cf2b2fb8e915035dd6ea25f51904#diff-bb81c0f14ea5ae146dbb8f5feba4a4ccR67 https://github.com/timestored/jq/commit/4b94ce214452cf2b2fb8...
- dang 6y agoIf curious see also 2018 https://news.ycombinator.com/item?id=16393873 https://news.ycombinator.com/item?id=16393873 Discussed at the time: https://news.ycombinator.com/item?id=4543038 https://news.ycombinator.com/item?id=4543038
- andybp85 6y agoI stumbled across J years ago when I was messing with Supercollider[0]. I wish I had a use for J, it's very cool. Slight tangent, Supercollier is one of the best langs I've ever played with. Smalltalk + J. Totally blew my mind when I first wrapped my brain around it! [0] https://supercollider.github.io/ https://supercollider.github.io/
- haolez 6y agoMy intuition for array-based languages is that you can use the "obscure" code, which heavily uses the standard vocabulary, for the low-level details of the business logic, but that you would still maintain a set of high-level verbs (DSL?) to describe in more clear terms what the hell the code is doing. However, the few real world projects that I've seen in these languages won't use any kind of DSLs and the argument usually is "for array-based language programmers, this is actually very clear and concise". I need to improve my J to verify that :)
- smabie 6y agoIf someone is interested in array languages, I would start with learning q, then k, J, and finally APL. q and k are much more conventional and less complicated than J/APL. They also tend to be more practical, and less mathematical. They also don't have multi-dimensional arrays, so the code tends to be both less general and less confusing. Once you've gotten familiar with them, J and APL won't seem as weird. Moreover, it's entirely possible to write regular procedural code in q and k, so it's easier to transition to the array language mindset.
- sally1620 6y agoIs J fast enough for image processing? I have to do all of my experiments in C because every other language is just too slow.
- teleforce 6y agoPerhaps you should try Single Assignment C (SAC), it's a fast array based language with C/Algol syntax but it's proprietary though. http://www.sac-home.org/doku.php http://www.sac-home.org/doku.php