How does “this” keyword work within a function?

I just came across an interesting situation in JavaScript. I have a class with a method that defines several objects using object-literal notation. Inside those objects, the this pointer is being used. From the behavior of the program, I have deduced that the this pointer is referring to the class on which the method was … Read more

How to Correctly Use Lists in R?

Brief background: Many (most?) contemporary programming languages in widespread use have at least a handful of ADTs [abstract data types] in common, in particular, string (a sequence comprised of characters) list (an ordered collection of values), and map-based type (an unordered array that maps keys to values) In the R programming language, the first two … Read more

Are there legitimate uses for JavaScript’s “with” statement?

Alan Storm’s comments in response to my answer regarding the with statement got me thinking. I’ve seldom found a reason to use this particular language feature, and had never given much thought to how it might cause trouble. Now, I’m curious as to how I might make effective use of with, while avoiding its pitfalls. … Read more

Expression Versus Statement

I’m asking with regards to c#, but I assume its the same in most other languages. Does anyone have a good definition of expressions and statements and what the differences are? 21 Answers 21 Expression: Something which evaluates to a value. Example: 1+2/x Statement: A line of code which does something. Example: GOTO 100 In … Read more

What does the ‘static’ keyword do in a class?

To be specific, I was trying this code: package hello; public class Hello { Clock clock = new Clock(); public static void main(String args[]) { clock.sayTime(); } } But it gave the error Cannot access non-static field in static method main So I changed the declaration of clock to this: static Clock clock = new … Read more

Why Doesn’t C# Allow Static Methods to Implement an Interface?

Why was C# designed this way? As I understand it, an interface only describes behaviour, and serves the purpose of describing a contractual obligation for classes implementing the interface that certain behaviour is implemented. If classes wish to implement that behavour in a shared method, why shouldn’t they? Here is an example of what I … Read more