61 points · by Tomte · 5y ago · 43 comments
Then the function definitions begin. ma allocates an array of n integers (this code is hardcoded for a 32-bit system), mv is basically memcpy, tr (Total Rank?) is used to compute the total number of elements, and ga (Get/Generate Array) allocates an array.
This is followed by the definitions of all the primitive operations (interestingly, find is empty), a few more globals, and then the main evaluator body. Lastly, main contains the REPL.
While I don't think this style is suitable for most programmers, it's unfortunate that the industry seems to have gone towards the other extreme.
It takes some time getting used to it, but, once you get the hang of it, going back to e.g. Python/Pandas is painful.
- https://github.com/handsonscala/handsonscala/blob/v1/example...
From the top down, that snippet contains an AST definition, a parser, an object model, an evaluator, and an output serializer. This 67-line programming language interpreter is one of the projects in my book https://www.handsonscala.com/ (chapter 20), and while this example is minimal the same techniques were used for my production-ready Sjsonnet interpreter
I would say the structurally this extremely easy to read considering there is zero comments and the way it is presented. One can make this readability obvious by just expand the macros, change indentations and add line breaks, or, you can just spend several days to "get used" to it like Roger Hui (and Arthur who just use this kind of style for life).
People who can read this find it readable.
I think it's a mistake to think that because you can't read the code, that it is the code that is somehow unreadable, instead of a language you simply haven't learned to read.
> I don’t know how a project is managed like this.
It's not dissimilar to working with any proprietary programming language: You have to learn how to read and write this language.
The fact that we can use an existing language's compiler can be confusing to people who don't know that language very well, but if you approach it from the perspective of a new (proprietary) language, using an existing language's compiler can be a great way to leverage the benefits of that existing language.
This argument is significantly weakened when simply removing the meaningless macros and adding whitespace improves readability.
It's not like it is complicated because it is written in a structurally different language, nor will you actually leverage any benefit from learning this language. It's just obfuscated under the guise of abbreviation.
I disagree wholeheartedly. Whitespace tends to move code further away from the code that uses it; scrolling and tab-flipping requires the developer hold that code in their head where it is most likely to degrade. It is much much better to make them remember as little as possible.
It also helps reuse: If you don't scroll, you can see more code, so you can see if something is a good candidate for abstracting, just because you can see them doing the same thing.
Macros like this help with that, and so they aren't "meaningless". Less whitespace helps with that, and so it actually improves readability (to those who have to read it!).
The trade-off is that you can't hire someone with "C" on their CV and expect them to be productive on their first day, but in a complex codebase, this might not be possible for other reasons.
Yes, but for this case adding whitespace actually decreases readability. At least if you know Whitney's hate of scrolling.
> I think it's a mistake to think that because you can't read the code, that it is the code that is somehow unreadable, instead of a language you simply haven't learned to read.
The same could be said about Brainfuck. With enough effort people can learn to read almost anything; that doesn’t mean that everything is equally readable.
The ngn/k implementation of the k language [1] is even more terse.
Once you get used to it, it's really a breeze and far easier to modify than 500+ sloc R scripts.
Of course, that does not work for everyone, and especially not for big teams, but still!
Do you find it faster?
I have good experiences with J due to its terseness, but I'm curious why scientists still use R/Python - is it just inertia? Libraries/FFI?
As for R/Python it's mostly familiarity with the notation (especially for python) and established popularity, with a large ecosystem as a consequence.
I mean, as a beginner in Python it just works (slowly). As a beginner in J, you cry... The interesting distinction is that Python/R APIs can be quite convoluted and the rug may be pulled from under you without warning, while in J you learn the primitives and you're off to the races. Also, J is much faster for its use case and avoids the need to write C in most cases where using it is relevant.
https://c9x.me/qscm/data/qscm.c
via this page which was recently linked on HN:
2017 https://news.ycombinator.com/item?id=14463874
2016 (one comment): https://news.ycombinator.com/item?id=12654054
2014 https://news.ycombinator.com/item?id=8533843
Related from last year: https://news.ycombinator.com/item?id=22831931
I'm pretty sure there have been other threads about this, probably via different articles.
I do see it's using the `implicit int` rule though.
`pr` is on the last line before the only line break.
It's a pretty dense program to walk through, but not as completely impenetrable as I first thought after taking some time and making notes as I went.
What do you mean by "Lisp interpretation on J language"?
There's an APL in Common Lisp called April. Otherwise, there's an unfinished J interpreter on the Racket package manager.
https://code.jsoftware.com/wiki/Scripts/Scheme
http://tangentstorm.github.io/apljk/bjonas-scheme.ijs.html
However, in my understanding this code is clear but is just an exercise to use J. A real Scheme parser in J would go through the use of ;: which is a primitive defining a state machine. Given the appropriate state table, it would yield a Scheme tokenizer (with the whole thing amounting to state_table ;: string). Here be dragons, though! You can find a J parser in J (not up to date with current J) using it here:
Seriously though, this must have been a deliberate design decision? Arthur Whitney is no amateur.