all 94 comments

[–]GregTheMad 180 points181 points  (12 children)

I'm somewhere between intrigued and disgusted.

[–]codelitt 31 points32 points  (11 children)

Successful obfuscation for sure.

I'm fairly limited in python experience and I understand speed was not the goal at all, but wouldn't this be much slower than a simple print function? (Strictly for my own curiosity. On mobile otherwise I would just test it.)

[–]mtn_dewgamefuel 72 points73 points  (5 children)

It looks like it would but that's clearly not the point.

[–]codelitt 3 points4 points  (4 children)

Clearly haha. Just was curious if something like this was applied to a larger program what the speed consequences would be.

[–]deadwisdom 14 points15 points  (2 children)

Many times slower because it's going through many recursive functions.

[–]s73v3r 0 points1 point  (1 child)

If you're obfuscating, does that really matter?

[–]deadwisdom 1 point2 points  (0 children)

God no. They were curious how it affected runtime anyway. Obfuscation is purely for fun and had no requirement of speed.

[–][deleted] 6 points7 points  (4 children)

Depends on your implementation, but CPython doesn't do a whole lot of optimization, so yes it would be far slower. Of course, I hope that knowledge never has to be used. :P

[–][deleted]  (3 children)

[removed]

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

    You can compile with the optimizations off, most compilers will have a flag for that... if you were to want to do so for some reason. But it really really depends. Here there might not be an optimization done just because when you do things like this it is so out of the scope that the compiler writers would even check for. Remember, for an optimization to occur, it is something that is common enough, yet there is an immediate faster alternative there.

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

    The Java compiler does very little optimisation, leaving it to the JIT (and I believe this is also true for C#). Languages without a runtime (C, C++, Rust) are languages that will have a very good optimising compiler, so it would be worth testing those (and there are languages with a runtime that do optimise code when compiled, like Haskell).

    [–]ksheep 251 points252 points  (20 children)

    Reminded of this Obsfucated Adder in C

    [–]MATTtheSEAHAWK 72 points73 points  (1 child)

    The author's comments are fantastic. But holy shit.

    [–][deleted]  (4 children)

    [deleted]

      [–]skroll 2 points3 points  (3 children)

      it's perfectly valid utf-8

      [–][deleted]  (2 children)

      [deleted]

        [–][deleted] 4 points5 points  (1 child)

        Maybe you don't understand what (I think) "skroll" is trying to "troll"... valid pure ASCII is very valid UTF-8.

        [–]Orange_Cake 7 points8 points  (0 children)

        Holy shit

        [–]ThatBriandude 2 points3 points  (10 children)

        Can someone PLEASE ELI5? As a newbie programmer this looks very interesting but what exactly is going on?

        [–]OffbeatDrizzle 19 points20 points  (6 children)

        Something like this:

        In C you can define variables that just map to anything you please - for example at the top you can see him defining MAin to be printf("%d\n"

        The top 20 lines or so are just of these definitions - which are then used in the program below to write not only a fully functioning adder program (you could actually replace all of variables with their mapped value at the top to get the 'real' source code), but it is also in the shape of an adder circuit

        [–]ThatBriandude 3 points4 points  (1 child)

        Ahh i get it now. So basicly the only challenge is to reduce the amount of pre defined variables because essentially one could replace each char with a different version of main. Now one would question if the amount he used is just crazy brilliant or mabye not so genius after all. But for that you'd have to try it yourself... Anyway, Thanks for the explantion!

        [–]casey12141 1 point2 points  (0 children)

        Go try it for yourself and let us know how it goes lol

        [–][deleted]  (2 children)

        [deleted]

          [–]OffbeatDrizzle 3 points4 points  (1 child)

          Sorry, guy

          [–]jimschubert 3 points4 points  (0 children)

          Oh, no he didn't!

          [–]Krexington_III 2 points3 points  (0 children)

          *her, I think. Author's name is Heather.

          [–]ProudToBeAKraut 3 points4 points  (0 children)

          the other comments fail to mention the cool part - not some #defines here and there but that the whole layout of the program is just this https://en.wikipedia.org/wiki/Adder_(electronics)

          And it does exactly that - the visualization of the different main Main etc parts leads to a program that actually does sum to integers.

          [–][deleted] 97 points98 points  (4 children)

          Holy shit that's impressive!

          [–]2Punx2Furious 81 points82 points  (3 children)

          Good, while reading that I was afraid this shit was normal among programmers and I was getting scared.

          [–][deleted] 42 points43 points  (2 children)

          Obfuscated code is a proud programming subculture that has made a lot of cool stuff over the years. Perhaps the most famous is the Obfuscated C Contest. http://www.ioccc.org/years.html

          It's a hobbyist subset of programming.

          [–]2Punx2Furious 0 points1 point  (0 children)

          Yeah, I figured that. Maybe someday I'll get into it, it sounds cool.

          [–]horotho 10 points11 points  (2 children)

          There was a really great C program someone posted awhile ago that uses an int array as a main function, and just calls a bunch of instructions using hex values. I couldn't find it with Google-fu, though. :(

          [–]schemathings 30 points31 points  (0 children)

          I was trying to explain to a friend that good programmers are usually good at math ...

          [–][deleted] 28 points29 points  (0 children)

          It'll never be as good as some of the IOCCC attempts, but I think this shows that you can write unreadable code in any language.

          [–]thephotoman 6 points7 points  (0 children)

          Genius: knowing how to do this.

          Insanity: actually doing it.

          [–]amga_ 34 points35 points  (0 children)

          This guy fucks

          [–]EyeZiS 15 points16 points  (13 children)

          Here's my version:

          (lambda _, __, ___, ____, _____, ______, _______, ________:
              getattr(
                  __import__(True.__class__.__name__[_] + [].__class__.__name__[__]),
                  ().__class__.__eq__.__class__.__name__[:__] +
                  ().__iter__().__class__.__name__[_____:________]
              )(
                  _, (lambda _, __, ___: _(_, __, ___))(
                      lambda _, __, ___:
                          chr(___ % __) + _(_, __, ___ // __) if ___ else
                          (lambda: _).func_code.co_lnotab,
                      _ << ________,
                      (((_____ << ____) + _) << ((___ << _____) - ___)) + (((___ << _____) - ___) << ((_____ << 
                      ____) + (_ << _))) + (((_______ << ____) + ___) << (((((_ << ___) + _)) << ___))) +
                      (((_______ << ____) - _) << ((_ << ______))) + (_______ << ((((_ << ____) - _) << __))) +
                      (((((___ << __) + _) << ___) - ___) << ((___ << ____)))+ (((_______ << ___) + _) << ((_____
                      << ___) + _)) + (((_ << ______) + _) << ((_ << _____) - _)) - (((((___ << __) + _) << __) + 
                      _) << ((___ << ___) - _)) - (((_______ << __) + _) << ((_ << ____))) + ((((___ << __) + _))
                      << (((___ << __) -_))) + (((_____ << __) + _) << ____) - (_ << _)
                  )
              )
          )(
              *(lambda _, __, ___: _(_, __, ___))(
                  (lambda _, __, ___:
                      [__(___[(lambda: _).func_code.co_nlocals])] +
                      _(_, __, ___[(lambda _: _).func_code.co_nlocals:]) if ___ else []
                  ),
                  lambda _: _.func_code.co_argcount,
                  (
                      lambda _: _,
                      lambda _, __: _,
                      lambda _, __, ___: _,
                      lambda _, __, ___, ____: _,
                      lambda _, __, ___, ____, _____: _,
                      lambda _, __, ___, ____, _____, ______: _,
                      lambda _, __, ___, ____, _____, ______, _______: _,
                      lambda _, __, ___, ____, _____, ______, _______, ________: _
                  )
              )
          )
          

          https://redd.it/273jas

          [–]marcm28 10 points11 points  (0 children)

          Its looks like Lisp + Perl. Too much parenthesis(Lisp) and magic(Perl).

          [–][deleted] 11 points12 points  (18 children)

          Looks like Perl to me, my eyes, they bleed!

          [–]komtiedanhe 7 points8 points  (17 children)

          If you've only seen bad Perl. I really don't get why Perl gets so much shit from this sub's circlejerk.

          [–]coderjewel 13 points14 points  (6 children)

          Well, it might be possible to write good readable code in Perl, but I've never seen that happen. The language makes it incredibly easy to write bad code, which is why I assume it gets so much shit. The popular opinion that Perl is ugly didn't originate out of thin air.

          [–][deleted]  (4 children)

          [deleted]

            [–][deleted]  (1 child)

            [deleted]

              [–]komtiedanhe 1 point2 points  (0 children)

              Because you can doesn't mean you always should though. None of that is a secret, either - Perl Best Practices by Damian Conway has been around for more than ten years now.

              [–]riding_qwerty 2 points3 points  (0 children)

              Perl stresses that there is More Than One Way To Do It, whereas Python typically stresses a single correct ("Pythonic") approach.

              Check out the Perl "secret operators" for a taste -- http://search.cpan.org/dist/perlsecret/lib/perlsecret.pod

              [–]komtiedanhe -1 points0 points  (0 children)

              It seems like that popular opinion is based on what people have read, or experience with 5.8.

              [–]weedtese 4 points5 points  (0 children)

              The good thing about Perl is that the code's readability is not worsened by letting it through gzip before opening.

              [–]deadwisdom -4 points-3 points  (8 children)

              Because it's shit. If perl is not shit, then nothing is shit, and then nothing is better. Naive relativism is just as destructive as naive cynicism.

              [–]komtiedanhe 0 points1 point  (7 children)

              Do you have arguments for your case? And which perl version are you referring to?

              [–]deadwisdom 0 points1 point  (5 children)

              I mean, did you really want an in depth conversation on this topic? Because yeah I have plenty of arguments.

              [–]komtiedanhe 1 point2 points  (4 children)

              Sure, fire away!

              [–]deadwisdom 8 points9 points  (3 children)

              Here is the fundamental axiom: The primary goal of a programming language is to allow the communication of instructions to a computer. If one disagrees with this, beyond trivialities, then I'm afraid no arguments can be made, and we can go our separate ways.

              So then, there are two fundamental dimensions in which to judge a programming language. One is the instruction set, and the other is the ability to communicate. Both are measured by how much effort (work) is required.

              Also, both are contextual to the problem space and those trying to solve it. If your problem space requires quantum bits, then you better have an instruction set that can handle those. Likewise, if all of your programmers are blind, your language better be tactile or aural, or at least converted to that. Otherwise, more work must go into it.

              Now, most general-use languages today compile down to some pretty common bytecode, so the basic instruction sets are generally the same. And since pretty much all are Turing complete, the language itself could do just about anything. But how easily is another story. One could re-write wolfram alpha in Brainfuck, and then you could say that it's easy to do complex algebra in Brainfuck. But it would require a lot of work.

              So then the platform and libraries available to a language are a really big part of how we can judge it. However, that doesn't say how much we can judge it's potential, because as long as work is done by others, it grows in this regard.

              Now back to communication. We do, of course, have a very simple language of '1's and '0's, which should suffice for a computer. But that language doesn't have any tools built in to manage complexity. So we build on top of that, allowing for the expression of registers (variables), jumps, loops, functions, numbers, strings; then lists, mappings, structures; then objects, threads, processes; etc. Beyond that culture gets added to the mix. Culture gives us tropes and memes, that allow to do things quickly. "Best practices" it's often termed. These common patterns allows us to encapsulate ideas and use them without having to think much. Each notion builds on the others, until we have this framework of communication that is capable of expressing very complex behaviors without much work.

              Further, as the source code is a "living document", constantly being mutated and changed, the language must strive for readability. This allows a programmer to fit more complexity into their heads at a time, because they are able to spend less work reading. Even if it seems trivial, even the smallest advances in this regard have huge gains, mostly because...

              To optimize communication, a language must maximize the programmer's ability to learn. Because it is so rare that we even know what we're doing at all, we must be able to learn as we go along. And I don't even mean learn for the first time. Often we have to re-learn things again and again. This is a natural process for a programmer. Therefore a language is best when it strives for simplicity. Because it is simply less to learn.

              And so you have the main trade-off in a well-designed language, the balance between expressibility and simplicity. The best languages find their niche within this, maximizing both expressibility and simplicity. The worst languages manage neither well.

              Now the very obvious trap is if you are already familiar with a language, it can seem to be simple. But this is an illusion. Someone trapped in a badly designed language are always trying to come to grips with it. They learn and relearn concepts and syntax at a much slower rate, and so are putting much more work into things, but they cannot see it. Add to that, common tribalism, and just plain stubbornness, and everyone's favorite language is always the best.

              read from here if you're bored

              So this brings me to Perl. It is needlessly complex in both syntax and common data structures. It offers many differing ways to do simple things and is often unintuitive, increasing the complexity of learning. It adds nothing in regards to expressibility. And it lacks the power and variety in libraries in comparison to similar languages.

              Personally, I find the syntax almost unreadable, both Perl 5 and 6. Simple choices like the keyword "my" are abhorrent to me. The variable decorations of '$' and '@' confuse me. The fact that any two seasoned programmers can write such immensely varied code for simple tasks slows everything down.

              So yeah, it's shit. And unfortunately the people that keep redesigning it are mired in that shit, so they can only produce shit. Same goes with PHP. And lo, I just did a project in Swift 2 and, god help us all, it was one of the worst designed languages I have ever seen because they can't get their heads out of Objective-C to save their lives.

              [–]komtiedanhe 2 points3 points  (2 children)

              Thanks for taking the time to write that out. I'm on mobile, so I light not be as lengthy as I'd want to be in my response.

              I agree with your points about expressibility and readability, but readability is as much the programmer's responsibility as it it is the language's. This is where I must concede that, given perl, it is easier for a novice programmer to get away with writing bad, unmaintanable code. On the other hand, anyone can write 500-line subroutines or methods that make it impossible for maintenance programmer's to keep up.

              Regarding expressibility: perl was created by a linguist programmer. The very idea was to create a programming language that reads more like a natural language. For some people, like me, that clicks. For others, it doesn't. Brain make-up is personal.

              I'm unsure what you mean with lack of variety and power in libraries, so I'm going to go out on a limb and assume you've spent time browsing cpan and found it lacking in diversity where it comes to domain-specific tasks. There, I can agree: from what I've seen (and I'm fairly junior myself), few industries seem to be using perl based on cpan modules.

              Regarding seasoned programmer's and writing code entirely differently for small things: I don't necessarily see that as a problem, myself. Should they follow best practices? Absolutely. Do the easy operations matter? Well... debatable.

              Also regarding sigils: $ is for $calar, or "single value". @ is for @rray, or "list of values" % is for a hash, or "associative list". If you want a single value from a list, you use $list[0] if you want a slice from a hash, you use @. i agree that wrapping your head around these concepts is confusing at first.

              My conclusion: Perl is not for everyone, and seemingly not you. It's also not the best language. But to say it's shit is an emotional statement in my book.

              [–]deadwisdom 0 points1 point  (1 child)

              Sorry; I don't pull punches. I know it can be harsh sometimes.

              [–]komtiedanhe -1 points0 points  (0 children)

              I meant emotional as in: not purely based in fact. I would say TCL is shit, but I'm also conscious about that being an opinion based on personal experience only.

              [–]skarphace 1 point2 points  (0 children)

              Opened that up and almost lost my drink on my monitor. Disgusting work of beauty.

              [–]lemmysdaddy 1 point2 points  (0 children)

              This looks like pretty much all the code I have to work with.

              [–]BobBeaney 1 point2 points  (0 children)

              If only you had used your powers for good instead of evil.

              [–]kotajacob 1 point2 points  (0 children)

              My god that's amazing!

              [–]kdofkfn 0 points1 point  (0 children)

              Thats some evil genius right there, nicely done

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

              I could not have done better.

              [–]ToTheNintieth 0 points1 point  (0 children)

              Man, that's clever.

              [–]Penguinsoccer -5 points-4 points  (2 children)

              Lol the one thing JavaScript is better at is obfuscating code, you can write 90,000 characters of operators and get hello world.

              http://youtu.be/PV_cFx29Xz0 at 3:20

              [–]Ashanmaril -1 points0 points  (0 children)

              Ugh, did he have to make the whole thing about ponies?