Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. I Hate Clever Javascript Programmers [modified]

I Hate Clever Javascript Programmers [modified]

Scheduled Pinned Locked Moved The Weird and The Wonderful
javascriptquestion
33 Posts 27 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    Like others have said ... that looks to me like Obfuscated code - emitted by a tool of some kind. If I had a developer working for me that wrote code like that I'd fire his ass. -Max

    E Offline
    E Offline
    Erion Pici
    wrote on last edited by
    #23

    I agree. Although inline IFs are useful, that code looks as bad as it would look in the more traditional IF { } block form. I'm not convinced it's been generated by an obfuscator though.

    1 Reply Last reply
    0
    • A Alexandru Lungu

      There is nothing clever here; the code was obfuscated with a tool; it was intended to be hard to understand; the original code is probably very readable.

      Challenge is Life!

      A Offline
      A Offline
      agolddog
      wrote on last edited by
      #24

      [quote] There is nothing clever here; the code was obfuscated withby a tool; it was intended to be hard to understand; the original code is probably very readable. [/quote] FTFY

      1 Reply Last reply
      0
      • R realJSOP

        I'm trying to decipher the inner workings of ShadowBox (a lightbox variant), and I found this (except when I found it, it was all on one line of code:

        return (aW == null) ? a0 === "!=" : a0 === "="
        ? a2 === aX : a0 === "*="
        ? a2.indexOf(aX) >= 0 : a0 === "~="
        ? (" " + a2 + " ").indexOf(aX) >= 0 : !aX
        ? a2 && aW !== false : a0 === "!="
        ? a2 !== aX : a0 === "^="
        ? a2.indexOf(aX) === 0 : a0 === "$="
        ? a2.substr(a2.length - aX.length) === aX : a0 === "|="
        ? a2 === aX || a2.substr(0, aX.length + 1) === aX + "-" : false;

        Before anyone else mentions it, I *know* what a ternary comparison is and I use them all the time (and was doing so before many of you were even born), but I don't nest them like this. THAT is the shameful nature of the code. So, please stop trying to educate me as to the ways of the force.

        ".45 ACP - because shooting twice is just silly" - JSOP, 2010
        -----
        You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
        -----
        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

        modified on Thursday, April 28, 2011 3:50 PM

        P Offline
        P Offline
        pg az
        wrote on last edited by
        #25

        Not being very much interested in web-stuff, yet I am proud of my new home-page, NOT ONE line of javascript - did you know that CSS can be used to achieve much of the "hover" functionality, which was all I ever wanted to customize, basically.

        pg--az

        1 Reply Last reply
        0
        • R realJSOP

          I'm trying to decipher the inner workings of ShadowBox (a lightbox variant), and I found this (except when I found it, it was all on one line of code:

          return (aW == null) ? a0 === "!=" : a0 === "="
          ? a2 === aX : a0 === "*="
          ? a2.indexOf(aX) >= 0 : a0 === "~="
          ? (" " + a2 + " ").indexOf(aX) >= 0 : !aX
          ? a2 && aW !== false : a0 === "!="
          ? a2 !== aX : a0 === "^="
          ? a2.indexOf(aX) === 0 : a0 === "$="
          ? a2.substr(a2.length - aX.length) === aX : a0 === "|="
          ? a2 === aX || a2.substr(0, aX.length + 1) === aX + "-" : false;

          Before anyone else mentions it, I *know* what a ternary comparison is and I use them all the time (and was doing so before many of you were even born), but I don't nest them like this. THAT is the shameful nature of the code. So, please stop trying to educate me as to the ways of the force.

          ".45 ACP - because shooting twice is just silly" - JSOP, 2010
          -----
          You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
          -----
          "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

          modified on Thursday, April 28, 2011 3:50 PM

          M Offline
          M Offline
          MattPenner
          wrote on last edited by
          #26

          As others have said there is nothing demented or intentionally spiteful about this at all. They simply used an optimization tool (minifier), which removes all white space and uses the minimum amount of characters for variables. It compresses JavaScript quite a bit for downloading. It is a highly common, and very recommended, practice. The actual source code with all comments and descriptive variable names is on the project site.

          1 Reply Last reply
          0
          • E Erion Pici

            If you work your head around inline IFs you'll find them really useful. I use them in C# all the time!!

            S Offline
            S Offline
            Sterling Camden independent consultant
            wrote on last edited by
            #27

            I agree -- they help promote a nice functional style. But this example is over the top.

            Contains coding, but not narcotic.

            1 Reply Last reply
            0
            • E Erion Pici

              If you work your head around inline IFs you'll find them really useful. I use them in C# all the time!!

              R Offline
              R Offline
              realJSOP
              wrote on last edited by
              #28

              I'm not saying I don't understand this code. I'm saying this code is ridiculous. And it's called a ternary comparison, not "nested if's".

              ".45 ACP - because shooting twice is just silly" - JSOP, 2010
              -----
              You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
              -----
              "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

              1 Reply Last reply
              0
              • R realJSOP

                I'm trying to decipher the inner workings of ShadowBox (a lightbox variant), and I found this (except when I found it, it was all on one line of code:

                return (aW == null) ? a0 === "!=" : a0 === "="
                ? a2 === aX : a0 === "*="
                ? a2.indexOf(aX) >= 0 : a0 === "~="
                ? (" " + a2 + " ").indexOf(aX) >= 0 : !aX
                ? a2 && aW !== false : a0 === "!="
                ? a2 !== aX : a0 === "^="
                ? a2.indexOf(aX) === 0 : a0 === "$="
                ? a2.substr(a2.length - aX.length) === aX : a0 === "|="
                ? a2 === aX || a2.substr(0, aX.length + 1) === aX + "-" : false;

                Before anyone else mentions it, I *know* what a ternary comparison is and I use them all the time (and was doing so before many of you were even born), but I don't nest them like this. THAT is the shameful nature of the code. So, please stop trying to educate me as to the ways of the force.

                ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                -----
                You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                -----
                "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

                modified on Thursday, April 28, 2011 3:50 PM

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #29

                Anytime I see variables like a0, a1, a2 etc. it's probably because the code has been run through a compression or obfuscation utility to make it smaller and less likely to be swiped. I'm guessing that's what's happened here. [edit: and if I'd read the responses so far I'd have seen that my reply was redundant]. Cheers, Drew.

                1 Reply Last reply
                0
                • R realJSOP

                  I'm trying to decipher the inner workings of ShadowBox (a lightbox variant), and I found this (except when I found it, it was all on one line of code:

                  return (aW == null) ? a0 === "!=" : a0 === "="
                  ? a2 === aX : a0 === "*="
                  ? a2.indexOf(aX) >= 0 : a0 === "~="
                  ? (" " + a2 + " ").indexOf(aX) >= 0 : !aX
                  ? a2 && aW !== false : a0 === "!="
                  ? a2 !== aX : a0 === "^="
                  ? a2.indexOf(aX) === 0 : a0 === "$="
                  ? a2.substr(a2.length - aX.length) === aX : a0 === "|="
                  ? a2 === aX || a2.substr(0, aX.length + 1) === aX + "-" : false;

                  Before anyone else mentions it, I *know* what a ternary comparison is and I use them all the time (and was doing so before many of you were even born), but I don't nest them like this. THAT is the shameful nature of the code. So, please stop trying to educate me as to the ways of the force.

                  ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                  -----
                  You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                  -----
                  "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

                  modified on Thursday, April 28, 2011 3:50 PM

                  E Offline
                  E Offline
                  ely_bob
                  wrote on last edited by
                  #30

                  Yes. my master. :suss:

                  I'd blame it on the Brain farts.. But let's be honest, it really is more like a Methane factory between my ears some days then it is anything else...
                  -----
                  "The conversations he was having with himself were becoming ominous."-.. On the radio...

                  1 Reply Last reply
                  0
                  • R realJSOP

                    I'm trying to decipher the inner workings of ShadowBox (a lightbox variant), and I found this (except when I found it, it was all on one line of code:

                    return (aW == null) ? a0 === "!=" : a0 === "="
                    ? a2 === aX : a0 === "*="
                    ? a2.indexOf(aX) >= 0 : a0 === "~="
                    ? (" " + a2 + " ").indexOf(aX) >= 0 : !aX
                    ? a2 && aW !== false : a0 === "!="
                    ? a2 !== aX : a0 === "^="
                    ? a2.indexOf(aX) === 0 : a0 === "$="
                    ? a2.substr(a2.length - aX.length) === aX : a0 === "|="
                    ? a2 === aX || a2.substr(0, aX.length + 1) === aX + "-" : false;

                    Before anyone else mentions it, I *know* what a ternary comparison is and I use them all the time (and was doing so before many of you were even born), but I don't nest them like this. THAT is the shameful nature of the code. So, please stop trying to educate me as to the ways of the force.

                    ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                    -----
                    You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                    -----
                    "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

                    modified on Thursday, April 28, 2011 3:50 PM

                    M Offline
                    M Offline
                    musefan
                    wrote on last edited by
                    #31

                    As no one else pointed it out I just wanted to say this would probably work better using the OR operator

                    I may or may not be responsible for my own actions

                    1 Reply Last reply
                    0
                    • R realJSOP

                      I'm trying to decipher the inner workings of ShadowBox (a lightbox variant), and I found this (except when I found it, it was all on one line of code:

                      return (aW == null) ? a0 === "!=" : a0 === "="
                      ? a2 === aX : a0 === "*="
                      ? a2.indexOf(aX) >= 0 : a0 === "~="
                      ? (" " + a2 + " ").indexOf(aX) >= 0 : !aX
                      ? a2 && aW !== false : a0 === "!="
                      ? a2 !== aX : a0 === "^="
                      ? a2.indexOf(aX) === 0 : a0 === "$="
                      ? a2.substr(a2.length - aX.length) === aX : a0 === "|="
                      ? a2 === aX || a2.substr(0, aX.length + 1) === aX + "-" : false;

                      Before anyone else mentions it, I *know* what a ternary comparison is and I use them all the time (and was doing so before many of you were even born), but I don't nest them like this. THAT is the shameful nature of the code. So, please stop trying to educate me as to the ways of the force.

                      ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                      -----
                      You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                      -----
                      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

                      modified on Thursday, April 28, 2011 3:50 PM

                      R Offline
                      R Offline
                      R Erasmus
                      wrote on last edited by
                      #32

                      I 100% agree with you. Good code is readable. Code that is difficult to read leaves space for difficulty to find bugs which cost the company money. Maybee its a form of insecurity these guys have. E.g. If I make my code impossible to read, they'll have to keep me employed.

                      "Program testing can be used to show the presence of bugs, but never to show their absence." << please vote!! >>

                      modified on Wednesday, May 11, 2011 6:54 AM

                      1 Reply Last reply
                      0
                      • R realJSOP

                        I'm trying to decipher the inner workings of ShadowBox (a lightbox variant), and I found this (except when I found it, it was all on one line of code:

                        return (aW == null) ? a0 === "!=" : a0 === "="
                        ? a2 === aX : a0 === "*="
                        ? a2.indexOf(aX) >= 0 : a0 === "~="
                        ? (" " + a2 + " ").indexOf(aX) >= 0 : !aX
                        ? a2 && aW !== false : a0 === "!="
                        ? a2 !== aX : a0 === "^="
                        ? a2.indexOf(aX) === 0 : a0 === "$="
                        ? a2.substr(a2.length - aX.length) === aX : a0 === "|="
                        ? a2 === aX || a2.substr(0, aX.length + 1) === aX + "-" : false;

                        Before anyone else mentions it, I *know* what a ternary comparison is and I use them all the time (and was doing so before many of you were even born), but I don't nest them like this. THAT is the shameful nature of the code. So, please stop trying to educate me as to the ways of the force.

                        ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                        -----
                        You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                        -----
                        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

                        modified on Thursday, April 28, 2011 3:50 PM

                        R Offline
                        R Offline
                        Ravi Sant
                        wrote on last edited by
                        #33

                        He has joined the 'anti-if' campaign.

                        // ♫ 99 little bugs in the code, // 99 bugs in the code // We fix a bug, compile it again // 101 little bugs in the code ♫

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups