4 ms·
I'd love to hear why that code doesn't embody brevity? As for obfuscation, it's rather straightforward -- it's just concise. A lack of instant understanding do
by sofuture 16y ago
I'd love to hear why that code doesn't embody brevity?
As for obfuscation, it's rather straightforward -- it's just concise. A lack of instant understanding doesn't indicate that a piece of code is without merit, or not honest and straightforward.
- kenjackson 16y agoTo be clear. If someone submitted this code to you for code review you'd say, "nice and concise -- approved"? Really? I get this person may have been working with constraints we don't know about, but its not straightforward. Give this to 10 working C devs and ask them to tell you what it does without running it. The standard cues of straightforward code aren't there -- well named variables, well named functions, comments, indentation, etc...
- ehsanul 16y agoI upvoted you, but as mentioned earlier in this thread by silentbicycle, this was written by one APLer to be read by another. I suppose even knowing APL makes it still difficult to follow, but only as difficult as APL itself is to follow right? :)
- silentbicycle 16y agoIf we were working in an APL dialect, I would expect code like that. I can tell you what every token in that code is for, by the way. If we were working in C, no. But if you're trying to get C programmers to grok APL style, it's a good start. The APL people are not fooling around, either - look at Kx's customers: http://kx.com/Customers/end-user-customers.php http://kx.com/Customers/end-user-customers.php . And then check how much a license for kdb+ costs per core. Oh, and "a standard purchase requires licensing at least 8 cores."
- kenjackson 16y agoHonestly, I think your superhuman then. For the most part I don't think ANY programming language is understandable without well named "tokens". I'm curious, do you think you could tell me what some arbitrary C code does that I give you, where I've changed all the variables to "a", "b", "c", etc...? I'd be hardpressed to believe anyone in the world could. Is APL structurally so expressive that huamns can easily extract meaning from structure? If so this is the single great accomplishment in the history of computer science. This dwarfs any contribution from Lisp, C, FORTRAN, theory of computation, etc... And the fact that I know some of the people that worked on the original versions of APL at IBM, yet they never mentioned this, makes me suspect.
- silentbicycle 16y ago> I'm curious, do you think you could tell me what some arbitrary C code does that I give you, where I've changed all the variables to "a", "b", "c", etc...? I'd be hardpressed to believe anyone in the world could. If you know the specific context ahead of time (a FSM for lexing, a hash table implementation, etc), then it really isn't that hard.* Are you honestly telling me that you wouldn't be able to figure out how a hash table implementation worked if all the types and variable names were changed to single letters? It would slow you down, sure, but it wouldn't be impossible. * Speaking as someone who has debugged code with variable names and comments in Swedish. That code was written with the context of, "Hey, we both know APL really well, here's a quick prototype for a new implementation of it, could you give it a look?" When somebody is showing a Scheme implementation to other Lispers, they don't need to spend time explaining what a cdr is. Context matters. Most of the functions in that take one or two arbitrarily-dimensioned arrays and loop simple operations over them. Everything takes (w) or (a, w) and returns z. i is a loop index (as usual). w->p is the array of values in w, ga allocates a new array. ("get array"? "generic allocate?") V1(iota){I n=*w->p;A z=ga(0,1,&n);DO(n,z->p[i]=i);R z;} iota (the term comes from APL; J uses "i.", K uses "!", Q uses "til") takes a number and returns a vector of integers from 0 to n. iota 5 -> 0 1 2 3 4. Most of the definitions are equally simple, there just isn't much whitespace. DO is a macro that abstracts out the common "for (i=0; i<n; i++) { ... }" loop, which is used all over the place.
- kenjackson 16y agoAre you honestly telling me that you wouldn't be able to figure out how a hash table implementation worked if all the types and variable names were changed to single letters? Yes, probably not. I've looked at code that I've personally written with variable names -- in the debugger and still scratched my head trying to figure out what I had done. And not trying to overstate my ability, but I tend to be someone who is generally pretty good at reading code. Here's some code you might run across in some DSP code. There are some globals, and hopefully I translated it correctly. But in any case, w/ good function variable naming I could understand the intent in a few seconds. Without it, I think I'd scratch my head for some time. How long does it take you to figure out what it does (or what it is intended to do)? ov f(){ xx b, hh, i, pp, j, jj = PL, k; xx D = NN>>2*b,d=n-2*zz; t *z[B]; t *p, m, n, q, oo; for (i=0; i<B; i++) z[i] = &X[ro[i]*jj]; for (b=0; b<D; b++) { f(b, hh, d); for (i=0; i<B; i++) { pp=ro[i]; k = (b << zz) + i; p = &YY[(hh<<zz) + (pp<<(n-zz))]; for (j=0; j<B; j+=SS) { m = z[j][k];n=z[j+1][k];q = z[j+2][k];oo = z[j+3][k]; p[j]=m;p[j+1]=n;p[j+2]= q;p[j+3]=oo;}}}}