3 ms·
While I'm not going to go collect a bunch of APL programmers to confirm this (where would one even find them?), I highly doubt that claim. Knowing a language do
by overgard 4y ago
While I'm not going to go collect a bunch of APL programmers to confirm this (where would one even find them?), I highly doubt that claim. Knowing a language doesn't mean dense code is suddenly obvious.
This is a silly example, but years ago I wanted to prove that you could write a non-trivial program in python using a single expression (because python's lambda only allows you to use expressions, not statements). And I managed to do that. And it's hideous. Any python programmer could theoretically understand what this is doing, but I doubt they would. Bonus points if you can guess what it does without running it!
(lambda:
not globals().__setitem__('sys', __import__('sys'))
and not globals().__setitem__('this', sys.modules[globals()['__name__']])
and not globals().__setitem__('time', __import__('time'))
and
#program
[setattr(this, k, v) for k,v in {
'set_color': (lambda c: w(['*', ' '][c])),
'abs': (lambda t: (int(t) + (int(t) >> 31)) ^ (int(t) >> 31)),
'w': lambda x: sys.stdout.write(x) == 0,
'smash': (lambda t: -((t * -1) >> 31)),
'color': (lambda n,k: set_color(smash (k & (n - k)))),
'col': (lambda n, k: k <= n and not color(n,k) and col(n,k + 1)),
'row': (lambda n: (
not w(' ' * (40-abs(int(n/2))))
and (col(abs(n), 0) or True)
and not w("\n")
and (abs(n) < 63 or n < 0)
and not time.sleep(0.05)
and row(n+1))),
'triangle': lambda: row(-60)
}.items() ] and triangle() )()
- ParetoOptimal 4y agoThat example isn't like APL though because of it's verbosity. Also APL has more universal abstractions to express a lot of this kind of logic. That lack of verbosity makes it easier to pick out the intention revealing code, which isn't the case here.
- overgard 4y agoWell, of course that code was meant as a joke, and I did some things intentionally weird. I mention it just to point out that a metric like "it's only a single expression!" doesn't mean that something is actually simple.
- rak1507 4y agoYou don't need a bunch - you need 1. I am an APL programmer, and I can tell you 100% for certain that anyone who knows any APL would find that easy to read. (Want to find more though? Go to one of these: https://aplwiki.com/wiki/Chat_rooms_and_forums https://aplwiki.com/wiki/Chat_rooms_and_forums) Knowing a language absolutely does mean 'dense' code is obvious (fwiw that APL code is not at all dense, you can do go a lot shorter). It's comparable to chinese characters or something like that. It only looks dense/unreadable to someone who doesn't know it.