3 ms·
> Next time, I had learned the coding conventions and how scope worked in JavaScript. The time after that I finally understood closures. Is this normal in so
by RyanZAG 11y ago
> Next time, I had learned the coding conventions and how scope worked in JavaScript. The time after that I finally understood closures.
Is this normal in some companies? This seems to imply they shipped production javascript in which the author didn't understand scope or closures. I can't honestly wrap my head around this one.. how could you write functioning code without understanding scope and closure? Repeatedly moving code lines around until it doesn't give an error or something? Putting everything in a single function?
- manuelflara 11y agoMaybe he means actually understanding and not "well in JS you do things this way, dunno exactly why".
- jkaptur 11y agoYes, it is quite normal in companies with good code-review policies. I review code, not its author. As far as writing functioning code without understanding scope and closure, a lot of JavaScript is written in a way that just doesn't require deep knowledge of the language. For example, take [1]. It certainly requires some JS knowledge to understand its purpose, but, at the same time, I'd feel comfortable assigning a new-to-JS programmer a task like "give each callback a custom string that's printed out when it's called." and expecting him or her to complete it. [1] https://github.com/facebook/react/blob/master/src/shared/utils/CallbackQueue.js https://github.com/facebook/react/blob/master/src/shared/uti...
- jrgv 11y ago"I learned how scope worked" does not imply that the author was previously unaware of the concept or didn't understand it at all, it just means that there was some aspect that she didn't fully understand until it was pointed out in the code review. I don't find that hard to believe at all. How many developers have you met that never had any questions or misunderstandings about, for example, the scope of `this` in JavaScript?
- neogodless 11y agoThis seems quite normal in companies. Obviously the size, age and (development) leadership in companies would determine exactly how "excellent" released code could be. My career has mostly been as web (application) developer at small companies that had a priority other than "highly skilled developers." The priority was usually "a complete web site that functioned." Whatever ugly, un-reviewed code that made it into that released product was fine, as long as it "functioned." None of these places included code-review as part of the release process, so there's zero chance of preventing code being released that wasn't written with full understanding. Personally, I only came in contact with the term "closure" rather recently. Scope was something I intuitively understood since my early days as a coder, and read about. This is the good and bad of being completely self-taught in most respects. There was no linear escalation of education to hold my hand through each and every concept. I would try code that I felt would work. Usually it would. Was it elegant, self-contained, de-coupled? Nope, not at all. But it functioned.
- chriswarbo 11y agoWhilst it's probably impossible to write code without understanding anything about scope, you can actually get quite far without understanding lexical scope and closures. For example, I've worked on a load of JS projects where every function is first-order, named and written at the top level, except for a few clearly redundant anonymous callbacks like `function(x) { return foo(x); }`. Obviously that code has been written without understanding first-class functions, lexical scope, closures, etc. but it worked. I've also been in the reverse situation in code reviews: where I've made some use of lexical scope in my code, and had to explain what lexical scope and closures are to the other members of the team.
- TeMPOraL 11y agoI've been repeatedly told to be wary of using too much lambdas in Java because some of the cow-orkers have problems with while loops, so... well, my experience with professional programming so far is that most people barely know how to code and there's little incentive to change it, since modern professional programming is just plumbing - connecting libraries together with snippets from Stack Overflow. And I'm being only a little cynical. (And the whole argument about avoiding to use language features is ridiculous. In commercial space, people don't expect others to learn anything, as if programming wasn't a craft and as if people were born to do it. Imagine a boss telling construction workers not to use power tools because some of the young hires have never seen a powered drill in their life.)