4 ms·
It’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
by smabie 7y ago
It’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.