Orthogonality Overkill: Obfuscated JavaScript Rectangle Prints Prime Numbers in Console
Description
Dark-theme IDE screenshot with line numbers 1-17 on the left. Lines 1-4 are green comments: “// Coding Best Practices:”, “// One of the key concepts of quality code is orthogonality”, “// Me:”, “// Is it orthogonal enough?”. Lines 6-16 form a perfect rectangle made of repeated “/**/” patterns framing intentionally unreadable JavaScript such as “console.log(...(”, “$$=>{~~$¢$$”, “(~_$_) {,$_$_=$$”, “(____$||??=$_$”, “(~__$__)())()”, “=[]|__+__⸺)”. Syntax highlighting shows keywords in blue, punctuation in white, and numeric literals in cyan. At the bottom, the DEBUG CONSOLE pane displays: “/usr/local/bin/node ./orthogonal.js” followed by a space-separated list of primes: “2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97”. The joke contrasts clean-code orthogonality advice with visually orthogonal yet hopelessly obfuscated code, highlighting code quality, style guides, and developer humor
Comments
27Comment deleted
Wanted orthogonality; got a perfectly rectangular block of obfuscated JS that prints primes - proof that orthogonal code can still intersect every reviewer’s sanity at 90°
Nothing says 'orthogonal code with minimal interdependencies' quite like a prime number generator that looks like it was written by someone who charges by the obfuscation level and decorates their functions with ASCII art borders that would make a 1980s BBS sysop weep with nostalgia
Ah yes, the classic interpretation of orthogonality: when your code is so independent that even the developer who wrote it can't understand what it does. This engineer has achieved perfect orthogonality - their ASCII art is completely orthogonal to readability, maintainability, and the sanity of future code reviewers. The real genius is naming the file 'orthogonal.js' while creating code that's about as modular as a monolithic COBOL mainframe from 1972. At least when this gets flagged in code review, they can argue it's technically 'independent' from any comprehensible logic
This is orthogonality in the same sense as microservices with a shared database: right angles everywhere, zero independence - just enough to print primes and fail code review
Orthogonality achieved: unary ops so independent, they negate any hope of readability
Asked for orthogonal APIs; got a JavaScript prime generator built entirely from operators and boxed in perfect right-angle comments - technically orthogonal, but gloriously perpendicular to maintainability
->[ ]-> black box explanation be like Comment deleted
I don't understand a single bit of this sorcery all I know is that we are cursed by the demons that this abyss is summoning Comment deleted
It's actually a neat trick with two's complement of a number if number is 5, it's binary is 0101 it's bits reversed is 1010 -5 would be 1010 + 1 = 1011 You can get +1 and -1 using these Comment deleted
what about the other parts? Comment deleted
I don't see a single number in this code Comment deleted
So, see the (_=[]) thing? It creates an empty array, which acts like a number zero. The next part means (simplifying a bit) [] + -~0 + -0 + -0 which means [] + 1 + 0 + 0, which creates a string "100", which converts to a number. Comment deleted
Holy shit from now on I hate js too Comment deleted
Yeah, I tried to retype this into text editor and replace sneaky brainfuckish parts with something readable. An it still doesn't make any sense. On the days like this I really wish I was a lumberjack... Comment deleted
and what is that negative after and behind ~ Comment deleted
- just negates the number ~ makes a bitwise NOT Comment deleted
IMHO, Perl was ultimately disregarded because of "best coding practices" just like this one, even though it allows to write perfectly readable code. Comment deleted
This is how far I've managed to simplify it. If anyone know how it works, pls explain. gen_check = (x, arr) => (check = i => x % (arr[i] ??= x) ? check(i+1) : arr) _=[], console.log (...(prim = x => (x-2 && prim(x-1), gen_check(x, _)(0) ) ) (100) ) Comment deleted
Why do you assume that function gen_check takes two arguments? Comment deleted
I didn't assume. I just wrote it this way. Now it does. The shocking part: originally the check function expected 1 argument, but none were passed to it. That's why there's ~~$_ in the original code. It converts implicit none to 0. Comment deleted
I am trying to simplify it was well and understand how it is working. Byt when I am trying to compile it, it fails. From my point of view _ is just undefined, it comes from nowhere and was not declared or defined. And error makes sense, when you are trying to access undefined[0]. Comment deleted
it is not Comment deleted
_ = [] Comment deleted
look at the last line Comment deleted
oh shit Comment deleted
now i get it Comment deleted
so the tricks to the book: ~-num = num-1 -~num = num+1 ~~undefined = 0, ~~num = num [] + anything = String(anything) -~[] = 1 -[] = 0 a && b returns false if a == false, otherwise returns b arr[index] ??= value it returns value if arr[index] is null or undefined and arr[index] otherwise ...array is unpacking array as arguments to a function Comment deleted