0

I´m trying to interpret source codes from big platforms like Facebook to learn how great programmers do their work, some of them have a type of programming that I have been never seen before. This loop is inside that type of programming:

for (var e; b.length && (e = b.shift()); ) b.length || void 0 === c ? d = d[e] ? d[e] : d[e] = {
}

This is the first time I see something like this, I finally thought that this slice of code was only created for distracting and scare possible malicious users

  1. The loop starts with an undefined variable called 'e'

for (var e;...

  1. And it has no condition to running it, it do nothing, no sense.

b.length && (e = b.shift());

This code means: number of elements inside b and e equals b without the first element

  1. the third loop statement is also empty, there is no increment.
  2. Now the hardcore part, there is no action for every recursion, not even Braces {}

b.length || void 0 === c ? d = d[e] ? d[e] : d[e] = { }

This code means: number of elements inside b or if undefined equals the content inside the variable c and if d equals the element number e inside d, then do nothing and if not then element number e inside d equals an empty braces {}

As you can see, this code has no sense, it has no reason to exist, but it does, so, Can an expert tell me if this is actually works for something or its just ascii symbols with no utility?

  • 2
    Be aware that when looking at code from sites like this, it's almost certainly been minified and isn't anything like what it was when it was actually written. – James Thorpe Jun 05 '18 at 15:24
  • *... great programmers ...* — mighty big assumption there :) – Pointy Jun 05 '18 at 15:24
  • 2
    `e` **is** defined, it is defined right there whenever `var e` was written. – zero298 Jun 05 '18 at 15:24
  • 2
    Obfuscated code can be difficult to deal with, and as @Pointy *pointed* out, "**mighty big assumption...**" – Alex Jun 05 '18 at 15:27
  • In addition to obfuscation, it's also increasingly common for the code you see to be the result of a code generation system (babel, typescript, elm, etc). – Pointy Jun 05 '18 at 15:29
  • "*learn how great programmers do their work*" - this code only shows usage of a minifier, not of great programming. This **not how you should write code**. – Bergi Jun 05 '18 at 15:30
  • Work can be done within the `()` of a for loop. You don't have to have anything in the `{}`. – zero298 Jun 05 '18 at 15:31
  • Here is a clarification request comment: where did you find the mentioned code? Did you find it on a GitHub repository? Did you find it while inspecting page source? Is this minified code? That would help with some of the other assumptions and questions in the comment chain. – zero298 Jun 05 '18 at 15:32
  • Possible duplicate of [A for loop without any {}](https://stackoverflow.com/questions/11008030/a-for-loop-without-any) – zero298 Jun 05 '18 at 15:33
  • Well, this that code was extracted from the first line of this file https://www.chess.com/bundles/app/js/vendor.client.b8d5efd4.js from chess.com – NOBODYINSIDE NOTHINGOUTSIDE Jun 05 '18 at 15:38
  • 1
    That is minified/uglified code. It isn't meant to be read or used by actual developers. Please read read up on this process here: [minification](https://blog.stackpath.com/glossary/minification/). Please don't look at this code and consider it "good practice". – zero298 Jun 05 '18 at 16:09
  • If that type of code can be executed without any problem and there is no programmer that can understand it even if this programmer is suposed to have a lot of experience, then its definetily a good practice. We want our applications to be safe and well programmed, right? The only reason that I pose to about why a person can say that this type of studyng is useless Is that simply that person is not able or enoughly trained to begin to understand the value of keeping an application fully safe and incomprehensible for malicious third persons. – NOBODYINSIDE NOTHINGOUTSIDE Jun 05 '18 at 20:38

0 Answers0