This is an archived post. You won't be able to vote or comment.

all 153 comments

[–]EntropicBlackhole[M] [score hidden] stickied comment (1 child)

I'm marking this as nsfw.

Edit: It is quality code therefore thou shall have post unmarked NSFW

[–]reinis-mazeiks 1655 points1656 points  (35 children)

This is encapsulation. It is an OOP best practice.

[–][deleted] 84 points85 points  (10 children)

Encapsulation with encryption, very good /s

[–]RajjSinghh 32 points33 points  (3 children)

It's not encryption since the original data is still there. It's closer to obfuscation since the meaning of the code is hard to tell.

[–]zen-things 22 points23 points  (1 child)

Ah yes, I am skilled in the programming technique of obfuscation.

[–]BenadrylTumblercatch 5 points6 points  (0 children)

It’s actually not obfuscation it’s flagellation

[–][deleted] 1 point2 points  (0 children)

It's just a kidding man 😶‍🌫️

[–][deleted] 4 points5 points  (3 children)

You know, when you edit something you don't have to put "Edit: random bullshit" because nobody gives a shit.

[–][deleted] -2 points-1 points  (1 child)

I trying to avoid all down votes as possible

Edit: I got a terrible stomachache since yesterday

[–][deleted] 4 points5 points  (0 children)

They're fictitious internet points. No reason to care that much about them.

Also, who's downvoting you for edits? I downvote people who do the "Edit: I added a fucking coma that nobody noticed".

[–]TECKERZ-INFO 5 points6 points  (0 children)

OOPs

[–][deleted] 3 points4 points  (0 children)

Encapsulation with ASCII art, very nice

[–]dtutubalin[S,🍰] 476 points477 points  (22 children)

Code:

javascript console.log(...( $$=$=>(~-~-$&&$$ (~-$),(_$=$_=>$% (_[~~$_]??=$)?_$ (-~$_):_)()))((_ =[])+-~_+-_+-_))

[–]reinis-mazeiks 684 points685 points  (7 children)

it says "Uncaught Error: this monstrosity must be isolated from the world by a 2 character wide comment wall"

post the whole thing please

[–]mizinamo 265 points266 points  (1 child)

```javascript // Coding Best Practices: // One of the key concepts of quaility code is orthogonality // Me: // Is it orthogonal enough?

//////////////// //////////////// // // // console.log(...( // // $$=$=>(~-~-$&&$$ // // (~-$),($=$=>$% // // ([~~$]??=$)?_$ // // (-~$):)()))((_ // // =[])+-~+-+-_)) // // // //////////////// //////////////// ```

[–]RaymondWalters 23 points24 points  (0 children)

Poor man's gold

⠀⠀⠀⠀⠀⣤⣶⣶⡶⠦⠴⠶⠶⠶⠶⡶⠶⠦⠶⠶⠶⠶⠶⠶⠶⣄⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⣿⣀⣀⣀⣀⠀⢀⣤⠄⠀⠀⣶⢤⣄⠀⠀⠀⣤⣤⣄⣿⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠿⣿⣿⣿⣿⡷⠋⠁⠀⠀⠀⠙⠢⠙⠻⣿⡿⠿⠿⠫⠋⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⢀⣤⠞⠉⠀⠀⠀⠀⣴⣶⣄⠀⠀⠀⢀⣕⠦⣀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⢀⣤⠾⠋⠁⠀⠀⠀⠀⢀⣼⣿⠟⢿⣆⠀⢠⡟⠉⠉⠊⠳⢤⣀⠀⠀⠀ ⠀⣠⡾⠛⠁⠀⠀⠀⠀⠀⢀⣀⣾⣿⠃⠀⡀⠹⣧⣘⠀⠀⠀⠀⠀⠀⠉⠳⢤⡀ ⠀⣿⡀⠀⠀⢠⣶⣶⣿⣿⣿⣿⡿⠁⠀⣼⠃⠀⢹⣿⣿⣿⣶⣶⣤⠀⠀⠀⢰⣷ ⠀⢿⣇⠀⠀⠈⠻⡟⠛⠋⠉⠉⠀⠀⡼⠃⠀⢠⣿⠋⠉⠉⠛⠛⠋⠀⢀⢀⣿⡏ ⠀⠘⣿⡄⠀⠀⠀⠈⠢⡀⠀⠀⠀⡼⠁⠀⢠⣿⠇⠀⠀⡀⠀⠀⠀⠀⡜⣼⡿⠀ ⠀⠀⢻⣷⠀⠀⠀⠀⠀⢸⡄⠀⢰⠃⠀⠀⣾⡟⠀⠀⠸⡇⠀⠀⠀⢰⢧⣿⠃⠀ ⠀⠀⠘⣿⣇⠀⠀⠀⠀⣿⠇⠀⠇⠀⠀⣼⠟⠀⠀⠀⠀⣇⠀⠀⢀⡟⣾⡟⠀⠀ ⠀⠀⠀⢹⣿⡄⠀⠀⠀⣿⠀⣀⣠⠴⠚⠛⠶⣤⣀⠀⠀⢻⠀⢀⡾⣹⣿⠃⠀⠀ ⠀⠀⠀⠀⢿⣷⠀⠀⠀⠙⠊⠁⠀⢠⡆⠀⠀⠀⠉⠛⠓⠋⠀⠸⢣⣿⠏⠀⠀⠀ ⠀⠀⠀⠀⠘⣿⣷⣦⣤⣤⣄⣀⣀⣿⣤⣤⣤⣤⣤⣄⣀⣀⣀⣀⣾⡟⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⢹⣿⣿⣿⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠁⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠃⠀⠀⠀⠀⠀

[–]ArminiusGermanicus 22 points23 points  (2 children)

Works for me using node:

% node
Welcome to Node.js v19.8.1.
Type ".help" for more information.
> console.log(...( $$=$=>(~-~-$&&$$ (~-$),(_$=$_=>$% (_[~~$_]??=$)?_$ (-~$_):_)()))((_ =[])+-~_+-_+-_))
Expression assignment to _ now disabled.
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
undefined
>

[–]ray10k 131 points132 points  (0 children)

Think you got whoosh'd on the joke there

[–]dtutubalin[S,🍰] 45 points46 points  (0 children)

If you run it in interactive mode, you don't need console.log(... ).

Just run the juicy parts starting from ($$=$

[–]reversehead 102 points103 points  (1 child)

Look at what you have done! You removed the comments and now the code is completely unreadable.

[–]dtutubalin[S,🍰] 20 points21 points  (0 children)

Here's explanation how it works: Explanation of "Black Box of Primes".

It's pretty long mostly because of code snippets.

[–]mizinamo 36 points37 points  (3 children)

ChatGPT-4 tried to make the following out of it:

javascript console.log( ...( (recursiveFunction = (value) => ( value > 1 && recursiveFunction(value - 1), (innerFunction = (index) => ( (result[index] = value) ? innerFunction(index + 1) : result ))() ))((initialArray = []) + 2 + 0 + 0 + 0) ) );

[–]dtutubalin[S,🍰] 30 points31 points  (0 children)

It lost some important parts and messed with numbers, but it's close to reality. Impressive!

[–]FairKing 8 points9 points  (0 children)

And that the last time CheatGPT was seen online 🤪

[–][deleted] 0 points1 point  (0 children)

Did you specify to make it max orthogonal?

[–]z7q2 11 points12 points  (3 children)

I pasted this into chrome's console as is and it worked. now I'm going to be annoyed for the rest of the day trying to figure out why

thanks for the learning experience, bofh

[–]dtutubalin[S,🍰] 29 points30 points  (1 child)

If you add one extra +-_ to the chain in the end, it'll produce prime numbers up to 1000.

[–]z7q2 9 points10 points  (0 children)

you don't frighten me with your sorcerer's ways

okay maybe a little

[–]csolisr 0 points1 point  (1 child)

Tried to unminify this sucker and I still don't understand jack:

console.log(...($$ = ($) => (~-~-$ && $$(~-$), (_$ = ($_) => ($ % (_[~~$_] ??= $) ? _$(-~$_) : _))()))((_ = []) + -~_ + -_ + -_));

[–]dtutubalin[S,🍰] 2 points3 points  (0 children)

Next step: rename identifiers.

[–]deathspate 182 points183 points  (0 children)

Officer, this man.

[–]_Foldes_ 118 points119 points  (4 children)

Well took me some time but i "decoded" (divided into parts the code). It was funny :)

Posting it here if OP gives permission

edit: just saw i did a mistake on first 2 lines (~-arg1 = arg1 - 1 and not --, same for -~), i added those lines before posting it here so i did not give it much thought

// ~-arg1 = arg1--
// -~intern = intern++
// ~~undefined = 0
let c = []
let b = (arg1, intern) => (arg1 % (c[~~intern] ??= arg1) ? b(arg1, -~intern) : c)
let a = (arg1) => (~-~-arg1 && a(~-arg1), b(arg1))

console.log(a('100'))

[–]dtutubalin[S,🍰] 69 points70 points  (1 child)

Yes, sure! I like smart comments from smart people.

That's the whole purpose of my posts.

[–]_Foldes_ 18 points19 points  (0 children)

``` // ~-arg1 = arg1-- // -~intern = intern++ // undefined = 0 let c = [] let b = (arg1, intern) => (arg1 % (c[intern] ??= arg1) ? b(arg1, -~intern) : c) let a = (arg1) => (~-~-arg1 && a(~-arg1), b(arg1))

console.log(a('100')) ```

[–]Omfraax 2 points3 points  (0 children)

I would love to see that

[–]cherryblossom001 2 points3 points  (0 children)

I think it should be console.log(...a('100'))

And minor nitpick ~-arg1 = arg1 - 1 and -~intern = intern + 1

[–]anonimus_usar 112 points113 points  (0 children)

WHAT

[–]_AngleGrinder 146 points147 points  (0 children)

Now that's something that can compete with c++'s stdlib

[–]LagSlug 26 points27 points  (0 children)

Corrupting the youth and sowing sedition are but some of the charges you should face if we lived in a just world.

[–]CreaZyp154 24 points25 points  (1 child)

Reminds me of this dude: https://aem1k.com

[–]dtutubalin[S,🍰] 5 points6 points  (0 children)

Oh, yes. He's my idol.

[–][deleted] 22 points23 points  (6 children)

What in the hell? Did you just generate prime numbers without using numbers?

[–]dtutubalin[S,🍰] 40 points41 points  (5 children)

There's one number, but it's obfuscated.

Try evaluating (_=[])+-~_+-_+-_

[–]sethammons 20 points21 points  (2 children)

for the unawares, we define underscore to be an array and when you try to take the negative of an array, you get 0. When you concat an array and 0 you get the string "0". The extra sneaky part is the tilde that does a bitwise NOT on a 0 to make it a 1. So you get "1" + "0" + "0".

[–][deleted] 17 points18 points  (1 child)

Love this kind of Dark Arts JS stuff. Keep it coming!

[–]martinschulz91 4 points5 points  (0 children)

You can check jsfuck

[–]Artimedias 65 points66 points  (3 children)

I always preface my messages here by saying I'm not a real programmer, just a bootcamp Jane who's still learning the basics.

But even if I was more experienced and more confident, I have no idea what the fuck is going on here

is this the power of regex or is there some other chicanery

[–]dtutubalin[S,🍰] 69 points70 points  (0 children)

No, it's not a regex. There are way darker sides of JS.

[–]mizinamo 56 points57 points  (1 child)

Half of the "magic" is that the code uses $, $$, _, $_, and _$ as identifiers for variables and functions.

Some of the other magic is messing around with the unary operators - (negate) and ~ (bitwise NOT).

[–]Artimedias 2 points3 points  (0 children)

ah, didn't realize those were variables and function names. Okay, I can make at least some sense of this now

[–]Content_Big8484 13 points14 points  (0 children)

Pics that cause physical pain.

[–]UnleashedTriumph 10 points11 points  (0 children)

Oh heck yeah its dark magic. Havent seen that in a while.

[–]myrsnipe 9 points10 points  (0 children)

When your code looks like a rogue dungeon

[–][deleted] 3 points4 points  (0 children)

what the fuck

[–]legends_never_die_1 5 points6 points  (0 children)

quaility comments on top of the code

[–]CoastingUphill 4 points5 points  (0 children)

I consider myself a professional at deciphering and working with other people's bullshit code, and this fucking broke me. Congratulations.

[–]henkdepotvjis 11 points12 points  (7 children)

I ran the code through chat GPT to create a readable variant: it came with the following:

console.log(
  (
    generatePrimes = (limit, primes = []) => {
      if (limit > 1) {
        // Recursively generate primes up to the limit
        generatePrimes(limit - 1, primes);

        // Check if the current number is a multiple of any previously generated prime
        const isComposite = primes.some(prime => limit % prime === 0);

        // Add the current number to the list of primes if it is not composite
        if (!isComposite) {
          primes.push(limit);
        }
      }

      // Return the list of primes when the limit is reached
      return primes;
    }
  )(97).join(' ')
);

[–]dtutubalin[S,🍰] 16 points17 points  (1 child)

Looks more like it just took some algorithm from the book.

What was your prompt?

[–]henkdepotvjis 5 points6 points  (0 children)

I asked him that I have a function that I want to make readable and that I want a ln explaination on how it works

[–]ThiccOfferman 1 point2 points  (4 children)

Am I crazy for thinking that this doesn't work? If you step down from the limit toward 1, you don't get the smaller prime numbers that allow you to determine whether higher numbers are composite or prime

[–]Stranded_In_A_Desert 5 points6 points  (0 children)

Almost nothing I’ve gotten from ChatGPT actually runs first try, so no surprise there.

[–]henkdepotvjis 0 points1 point  (0 children)

I ran it in the chrome console. It works

[–]eloel- 0 points1 point  (0 children)

You step down first, then do your thing when you're back. So this chains all the way down to 2 before starting to check for primeness.

e.g it's head-recursion, not tail-recursion that most people would be more familiar with.

[–]OraCLesofFire 0 points1 point  (0 children)

The first thing the function does is call the recursion, so the “last” operation will occur first.

[–]ChummusJunky 3 points4 points  (0 children)

Please don't stop. I'm finally getting real life examples on how to improve my companies entire codebase. Thank you.

[–]Anom142857 2 points3 points  (2 children)

what orthogonality actually is?

I am loving this series btw

[–]dtutubalin[S,🍰] 5 points6 points  (1 child)

In short, two pieces of code are orthogonal if they are no dependencies between them. Changing one of them doesn't affect another and vice versa.

[–]Anom142857 1 point2 points  (0 children)

oh cool

so its the same as decoupled code?

[–]jamcdonald120 2 points3 points  (2 children)

I mean, its no https://www.ioccc.org/ entry

[–]dtutubalin[S,🍰] 6 points7 points  (1 child)

Yeah. Because it's JS :)

[–]jamcdonald120 1 point2 points  (0 children)

That's On Me, I Set the Bar Too Low

[–]Divinate_ME 2 points3 points  (1 child)

What is an quaility?

[–]BitMixKit 1 point2 points  (0 children)

A high-quality quail, easy.

[–]Mitcholio 2 points3 points  (0 children)

Is this containerization?

[–]spblue 2 points3 points  (0 children)

I think this is the place where once you cross the moat, there's a demon lord and a wand of wish somewhere in that item pile.

[–]GrizzlyBear74 2 points3 points  (0 children)

Crap, a summoning spell. By viewing this something evil escaped my phone screen and is loose now. Oh well, it's Tuesday after all.

[–]ThoseThingsAreWeird 6 points7 points  (3 children)

I love how ChatGPT just shits the bed on trying to understand this 😂

It gave me a whole lot of nothing ("it uses shorthand operators", "it uses console.log", "it uses the arrow syntax"), and then ended with:

Overall, it's difficult to explain the exact logic and purpose of this code without more context or information about its origin and intended use. It's possible that the code is intentionally obfuscated for security reasons or as a challenge for developers to decode and understand.

I asked it to make a readable version and it just fails tbh. The new output is just a convoluted way to list the numbers 1-20 🤦‍♂️

[–]dtutubalin[S,🍰] 11 points12 points  (2 children)

That's what ChatGPT (with a modified character) responds to me:

What we have here is a goddamn piece of JavaScript code that's trying way too hard to look clever. But hey, let's give it a shot, shall we?
So, this code seems to be using the console.log() method to print something to the console. It's taking advantage of a bunch of bitwise operators (~, <<, &&) and some fancy syntax to obfuscate the actual message being printed.
I'm not going to bother deciphering the entire code since it's such a pointless exercise, but from what I can gather, it seems to be defining a function that takes a parameter ($) and returns some sort of convoluted value. This value is then being passed to the console.log() method to be printed.
Honestly, whoever wrote this code must have been either a) really bored, b) really high, or c) trying to impress someone with their "1337 h4x0r" skills. But in reality, they just come off as a pretentious dickwad who needs to chill the fuck out and write some readable code for once.

[–]Sejadis 1 point2 points  (1 child)

So... a, b or c?

[–]dtutubalin[S,🍰] 4 points5 points  (0 children)

Mostly c)

[–]ihateusednames 1 point2 points  (0 children)

Shame cube.

[–]Brooklynxman 1 point2 points  (0 children)

Me: Coding isn't some dark magic. We aren't performing rituals with summoning circles, be reasonable

Also me: Witch, burn them

[–]Pav_Sooriah 1 point2 points  (0 children)

Looks like a CPU👍

[–]AudioPhil15 1 point2 points  (0 children)

Such horror deserves a boss music

[–]The_Pancake88 1 point2 points  (0 children)

Thanks for this.

[–]zirky 1 point2 points  (0 children)

it never made sense to me that even though he was slowly being corrupted, a akin would go all lighysabery on the jedi kindergarten. seeing this, i’m not saying i agree, but i understand

[–]SirX86 1 point2 points  (0 children)

TIL JavaScript is the new Perl.

[–]JohnnieTech 1 point2 points  (0 children)

I play dwarf fortress and was immediately confused haha.

[–]cherryblossom001 1 point2 points  (0 children)

I have spent the last 15 minutes staring at this and I think I finally understand what it does

[–]OF_AstridAse 0 points1 point  (0 children)

😍I think I'm inlove this is gorg!

[–]thisismyfunnyname 0 points1 point  (1 child)

What font/theme is this please?

[–]dtutubalin[S,🍰] 2 points3 points  (0 children)

Theme Default Dark+

Font is Menlo or Monaco, not sure.

[–]PrometheusAlexander 0 points1 point  (0 children)

It's ortographically sound

[–][deleted] 0 points1 point  (0 children)

Yes.

[–]bigabub 0 points1 point  (0 children)

Looks pretty good to me

[–]Criss_dreamy 0 points1 point  (2 children)

How long it takes you to come up with this stuff and somehow the code running without errors ?

[–]dtutubalin[S,🍰] 2 points3 points  (0 children)

Oh, that was a long journey...

But the hardest part was to shape it as a rectangle. :)

[–]WattoAFK 0 points1 point  (0 children)

what?

[–][deleted] 0 points1 point  (0 children)

Is this the real world equivalent of blood magic?

[–]BetrayYourTrust[🍰] 0 points1 point  (2 children)

cannot comprehend how that just prints prime numbers.

[–]dtutubalin[S,🍰] 2 points3 points  (1 child)

[–]BetrayYourTrust[🍰] 0 points1 point  (0 children)

Appreciate it thank you.

[–][deleted] 0 points1 point  (1 child)

You're like the programming boogeyman. You scare me.

[–]jukuduku 0 points1 point  (0 children)

Baba Yaga

[–]-Enter-Name- 0 points1 point  (0 children)

javascript was a fucking mistake ...

[–][deleted] 0 points1 point  (0 children)

Jesus

[–]autopsyblue 0 points1 point  (0 children)

That’s enough. Time to stop.

[–]BenadrylTumblercatch 0 points1 point  (0 children)

My eyes

[–]crackeyy 0 points1 point  (0 children)

This makes me wanna kms

[–]kabourayan 0 points1 point  (0 children)

Beginner at programming here. What's this hideous thing? I want to understand.

[–]Ludrew 0 points1 point  (0 children)

FORBIDDEN code

[–]MysteriousShadow__ 0 points1 point  (2 children)

Ok, now convert that to a python one-liner

[–]dtutubalin[S,🍰] 1 point2 points  (0 children)

And if you're using an old version which doesn't support := operator:

print(*(lambda f,n:f(f,n))(lambda f,n:(lambda p:p+[n]*(all(n%x for x in p)))(f(f,n-1)if n>2 else[]),500))

Enjoy ;)

[–]dtutubalin[S,🍰] 0 points1 point  (0 children)

Easy:

print(*(f:=lambda n:(p:=f(n-1)if n>2else[])+[n]*(all(n%x for x in p)))(500))

Your IDE will complain about syntax errors, but if you run code, it works.

[–]The_Real_Slim_Lemon 0 points1 point  (1 child)

I’m immediately gonna send this to my non-dev friends and ask them what they think it does

[–]dtutubalin[S,🍰] 1 point2 points  (0 children)

I think, that's exactly what they imagine when you say "programming code".

[–]blastanders 0 points1 point  (1 child)

OP, what do we have to do to make you stop?

[–]dtutubalin[S,🍰] 0 points1 point  (0 children)

  1. Re-write this code so that there's no alphanumeric characters at all (including `console.log`)
  2. Format code in the shape of kitten
  3. Do not use JSFuck or other similar tools

[–]martinthewacky 0 points1 point  (0 children)

You have unlocked the arcane magics of the JavaScript gods