D
David Mark
Stefan said:Dmitry A. Soshnikov :
I think it is from another song. Ry Nohryb likes cute constructs that
minimise code lines. Most other contributors frown upon anything the
average programmer may fail to understand and maintain.
Count me in as an average programmer, then. In order to understand the
example, I had to rewrite it and rename the variables/arguments:
aQuery = (function () {
var list = [];
list.refresh= function () {
var set = document.body.getElementsByTagName('*'),
i = set.length;
list.length = 0;
while (i--) {
if (set.width === "100%") {
list[list.length] = set;
}
}
return list;
};
list.refresh();
return list;
})();
Unless I made a mistake during refactoring - which is entirely possible,
I didn't test it or spend a lot of time on it - aQuery is a sparse array
of all elements in the body with a "width" property of "100%". It also
has a refresh() method which will update the array and return the aQuery
object for method chaining.
The "width" property looks suspicious. Not necessarily a bug, and it
could be intentional, but I wonder how easy it is to find such problems
in a "compressed" piece of code?
Not very.
I enjoy playing around with terse and obfuscated code, too. For example,
this is a working Perl program, written entirely with keywords:
not exp log srand xor s qq qx xor
s x x length uc ord and print chr
ord for qw q join use sub tied qx
xor eval xor print qq q q xor int
eval lc q m cos and print chr ord
for qw y abs ne open tied hex exp
ref y m xor scalar srand print qq
q q xor int eval lc qq y sqrt cos
and print chr ord for qw x printf
each return local x y or print qq
s s and eval q s undef or oct xor
time xor ref print chr int ord lc
foreach qw y hex alarm chdir kill
exec return y s gt sin sort split
Dear God. PERL programmers drive me nuts.