5 ms·
The code is unreadable, formatted in the style of an IOCCC entry–and this looks intentional. I wonder why.
by saagarjha 7y ago
The code is unreadable, formatted in the style of an IOCCC entry–and this looks intentional. I wonder why.
- smabie 7y agoIt’s just a different style. After using kdb+/q for aoc2019, I quite like the no space one-line style. I find the code easier to read and remember. I think most people who have tried an APL derived language also agree. It’s important that many/most cultural norms are not optimal, they are arbitrary. So don’t immediately discount something for looking weird.
- saagarjha 7y agoI refuse to believe that the call to main here is a matter of style: https://bitbucket.org/ngn/k/src/master/m.c https://bitbucket.org/ngn/k/src/master/m.c.
- lifthrasiir 7y agoI was actually very amused when I found that even VimScript is written in this style (look at the first line): https://bitbucket.org/ngn/k/src/master/vim-k/syntax/k.vim https://bitbucket.org/ngn/k/src/master/vim-k/syntax/k.vim
- smabie 7y agoWhile I wouldn’t write C like that, that’s how Arthur Whitney and others write code. The entire kdb+/q codebase is structured like that. And considering the success and insane performance of the system, I believe there is something to it. The point of this style isn’t obfuscation, it’s clarity and compactness. The compactness boosts the signal to noise ratio and allows the programmer to retain more information in working memory. I haven’t programmed C like that and wouldn’t, but I definately understand and respect the theory behind it. I have on the other hand written q like that, at first skeptical of the style. But after a couple days, I wouldn’t have it any other way. Being able to fit your entire program on a single screen has pretty profound productivity benefits. It also makes IDEs unnecessary. For other code structured like this, check out Kona, J or kdb+/q. In general, I don’t think refusing to believe is a very useful attitude. See: Chesterton’s Fence.
- deleted 7y ago[deleted]
- DagAgren 7y agoYou have a massive selection bias going on here - you're not going to use APL if you do not already tolerate this kind of code.
- beagle3 7y agoI didn’t tolerate it before I started using APL and K. And now my C, while not entirely ArthurWhitnious, is closer to this kind of code. When I first saw examples of how terse K and APL code gets, my thought was “obviously, the language was designed to solve this specific example or it wouldn’t be this terse”. But after the 100th or so significantly different example, one can’t NOT admit that the problems are simple, and common practices are just incredibly bloated..... which leads some (me for example) to adopt a much terser style.
- smabie 7y agoLearning q has changed almost everything I believe about what good programming practice should be. Functional Haskell or Scala code that I used to consider to be highly elegant, I now think unnecessarily verbose. And don’t even get me started on Java or Python...
- tluyben2 7y agoAnd I find q verbose :) However my poor statically typed brain is keeps struggling on how to mix Haskell (...) with APL/k. Video on that topic is here[0]. [0] https://www.youtube.com/watch?v=z8MVKianh54 https://www.youtube.com/watch?v=z8MVKianh54
- RodgerTheGreat 7y agoIndeed. It is rather common to see K criticized as a "domain-specific language", but empirically it seems that K's domain is rather large. One of the reasons I wrote iKe was to demonstrate that the same primitives which are well-suited to constructing databases and financial models can be applied to computer graphics. With little more than bindings that supply appropriate IO capabilities, you can even write games in K: https://github.com/JohnEarnest/ok/blob/gh-pages/ike/examples/asteroids.k https://github.com/JohnEarnest/ok/blob/gh-pages/ike/examples... https://github.com/JohnEarnest/ok/blob/gh-pages/ike/examples/snake.k https://github.com/JohnEarnest/ok/blob/gh-pages/ike/examples...
- tgv 7y ago> I think most people who have tried an APL derived language also agree. That part I have some experience with, and I think that's not the case. I was taught APL (in a CS course) along with a hundred or so other students, and it was nearly universally disliked; IIRC, it only resonated with some of the EE people. The department's administration was even written in APL, and nobody wanted to touch it. After finishing my assignments, I've never wanted to look at it again. So I, for one, doubt the style is universally likable.
- tluyben2 7y ago> So I, for one, doubt the style is universally likable. I agree; it's definitely a niche thing. It takes quite a while to get into it. Even if you understand the basics; if you don't like 'puzzling with code', you won't be idiomatic. And most people don't like puzzling with code; they want to get things done. You need to do quite a lot with it to start recognising the idioms, but once you do it's a blast. And it makes both reading and writing quite easy. That's why I think doing something like the advent of code in one of these languages will help a lot; I had to quit this year because a project at up my time I reserved for aoc19. The exercises I did though where cool to solve in k.
- no-s 7y agoHah, this is ironically bittersweet for me. Sadly I disliked J and K because they didn't scan like APL to me. Programming after APL in so-called modern languages seems like wordy drudgery in comparison.
- lifthrasiir 7y agoThe Whitney style relies mostly on C macros, while IOCCC (and especially golfed) entries tend to exploit very forgiving operators. It is likely that you can actually understand the thing with only proper renaming. I can confidently say this because my IOCCC entry had won in the Best Short Program category ;-) I'm still not sure that this terse style in C improves reading. I agree that lots of concise idioms present in APL family of languages do improve reading (once you picked them up), and I do like lots of short functions more than a number of long functions (another contrast to IOCCC, where you don't see many functions). But those languages are tailor made to maximize this aspect. You for example don't think much about loop invariants in APL and friends because they are mostly implicit, and in turn you get very good refactorability. Would it improve other non-array languages? I doubt.
- saagarjha 7y ago> The Whitney style relies mostly on C macros, while IOCCC (and especially golfed) entries tend to exploit very forgiving operators. It did seem a little "off" to me, but I couldn't put my finger on it; thanks for describing what was wrong with it. > It is likely that you can actually understand the thing with only proper renaming. Fair point, but I usually like to keep my use of renaming to understand code for the decompiler :)
- kick 7y agoHow is it unreadable? I've spent a fair amount of time digging my teeth into it, and I find it fantastic. It's terse, but far from unreadable.
- saagarjha 7y ago> I've spent a fair amount of time digging my teeth into it I tend to label code that makes me do that "unreadable"; it's not that I literally can't read it (I routinely deal with worse) but it requires more effort than I consider reasonable for the medium it is presented in.
- kick 7y ago"digging my teeth into it" wasn't meant to imply difficulty in any way, it was meant to imply depth: it's easier to read than most C codebases.
- saagarjha 7y agoPlease point me at these C codebases so I can steer clear of them except for when I need inspiration while writing reversing CTF challenges.
- anonymoushn 7y agoYou might try nginx?
- saagarjha 7y agoSeems fairly reasonable to me?
- anonymoushn 7y agoit's totally full of unwritten assumptions and the same header is usually parsed in several places slightly differently. it's a spooky action at a distance playground.
- deleted 7y ago[deleted]
- bakul 7y agoI think this is what you really want to ask: “This style of programming is totally foreign to me. Clearly this is intentional — I am curious as to why you chose it. Can you explain?” :-) Understanding why someone else makes a difference choice can be illuminating. Given that the author of the original k has written at least 5 or 6 versions of the language interpreter from scratch every time in this style, he must be doing something right. Right?
- saagarjha 7y ago> Given that the author of the original k has written at least 5 or 6 versions of the language interpreter from scratch every time in this style, he must be doing something right. Right? Not necessarily, but others have pointed out reasons why one might write code this way.
- geocar 7y ago> The code is unreadable False. I can read it just fine. Ergo, it is readable. You cannot read it, and that is a different problem. > I wonder why Because there are benefits you do not understand. It is very strange to me that you assume someone who does something doesn't get anything out of it simply because you don't get anything out of it.
- saagarjha 7y ago> False. I can read it just fine. Ergo, it is readable. https://news.ycombinator.com/item?id=22009831 https://news.ycombinator.com/item?id=22009831 > It is very strange to me that you assume someone who does something doesn't get anything out of it simply because you don't get anything out of it. I don't believe I assumed that?
- geocar 7y agoYes. That is exactly what I mean: Reading this requires no special effort, but then I know how to read it. This is clearly your lack of ability here.
- saagarjha 7y agoCan I not call anything but random noise unreadable, then?
- geocar 7y agoThere are plenty of other programmers just like you who can't read this. Most of them spend their time "programming" with stackoverflow on one screen and sublimetext (or whatever else is cool these days) on another and copy and paste between them. They write things like left-pad and are celebrated in stars and followers. You and you alone can decide whether you want to be more like them, or more like something else. However, when I see someone doing something I cannot do, I want to learn more. That's how I get better. I think there are other people out there like that who might just need a little bit of encouragement, and that's why I reply: Not to convince you, but to convince them it's okay to learn something that few people understand (but those that do think is really cool!)