What exactly does “closure” refer to in JavaScript?

From JavaScript Closures Two one-sentence summaries: A closure is the local variables for a function – kept alive after the function has returned, or A closure is a stack-frame which is not deallocated when the function returns. (as if a ‘stack-frame’ were malloc’ed instead of being on the stack!) A very good article on closures … Read more

Why can I define a variable twice in C?

Outside of any function, int x; is a tentative definition, and some compilers and linkers treat them as a sort of “cooperative definition,” where an identifier can be declared this way in multiple files and will result in defining only one object. C’s rules for external declarations (declarations outside of functions) are a bit complicated … Read more

What is an example of the Single Responsibility Principle? [closed]

The most effective way to break applications is to create GOD classes. Those are classes that keep track of a lot of information and have several responsibilities. One code change will most likely affect other parts of the class and therefore indirectly all other classes that use it. That in turn leads to an even … Read more

What is the meaning and reasoning behind the Open/Closed Principle?

It means that you should put new code in new classes/modules. Existing code should be modified only for bug fixing. New classes can reuse existing code via inheritance. Open/closed principle is intended to mitigate risk when introducing new functionality. Since you don’t modify existing code you can be assured that it wouldn’t be broken. It … Read more

In CUDA, what is memory coalescing, and how is it achieved?

It’s likely that this information applies only to compute capabality 1.x, or cuda 2.0. More recent architectures and cuda 3.0 have more sophisticated global memory access and in fact “coalesced global loads” are not even profiled for these chips. Also, this logic can be applied to shared memory to avoid bank conflicts. A coalesced memory … Read more

Why are redundant scope qualifications supported by the compiler, and is it legal?

Yes, it’s allowed (§9/2): The class-name is also inserted into the scope of the class itself; this is known as the injected-class-name. For purposes of access checking, the injected-class-name is treated as if it were a public member name. For information about the reasoning that lead to class name inject, you might want to read … Read more