Skip to content
DevMeme
4681 of 7590
CodeQuality Post #5131 · source on Telegram

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

27
Anonymous ★ Top Pick 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°
  1. Anonymous ★ Top Pick

    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°

  2. Anonymous

    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

  3. Anonymous

    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

  4. Anonymous

    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

  5. Anonymous

    Orthogonality achieved: unary ops so independent, they negate any hope of readability

  6. Anonymous

    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

  7. @r1gor 3y

    ->[ ]-> black box explanation be like

  8. @callofvoid0 3y

    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

    1. @affirvega 3y

      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

      1. @callofvoid0 3y

        what about the other parts?

      2. @callofvoid0 3y

        I don't see a single number in this code

        1. @Mikle_Bond 3y

          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.

          1. @callofvoid0 3y

            Holy shit from now on I hate js too

            1. @Mikle_Bond 3y

              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...

      3. @callofvoid0 3y

        and what is that negative after and behind ~

        1. @affirvega 3y

          - just negates the number ~ makes a bitwise NOT

  9. @SamsonovAnton 3y

    IMHO, Perl was ultimately disregarded because of "best coding practices" just like this one, even though it allows to write perfectly readable code.

  10. @Mikle_Bond 3y

    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) )

    1. @torvadim 3y

      Why do you assume that function gen_check takes two arguments?

      1. @Mikle_Bond 3y

        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.

        1. @torvadim 3y

          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].

          1. @callofvoid0 3y

            it is not

          2. @callofvoid0 3y

            _ = []

  11. @callofvoid0 3y

    look at the last line

  12. @torvadim 3y

    oh shit

  13. @torvadim 3y

    now i get it

  14. @affirvega 3y

    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

Use J and K for navigation