What is the difference between covariance and contra-variance in programming languages? [closed]

Covariance is pretty simple and best thought of from the perspective of some collection class List. We can parameterize the List class with some type parameter T. That is, our list contains elements of type T for some T. List would be covariant if S is a subtype of T iff List[S] is a subtype … Read more

What are the advantages that prototype based OO has over class based OO?

The advantage of prototypal inheritance is that it potentially allows fancy metaprogramming in a straightforward way because the prototype chain is easily manipulated. This is a rather academic advantage because metaprogramming is the wrong answer 99% of the time. As an example, you could have a Javascript Key-Value Observer style data manipulation layer with a … Read more

Equivalent of Class Loaders in .NET

The answer is yes, but the solution is a little tricky. The System.Reflection.Emit namespace defines types that allows assemblies to be generated dynamically. They also allow the generated assemblies to be defined incrementally. In other words it is possible to add types to the dynamic assembly, execute the generated code, and then latter add more … Read more

PHP Readonly Properties?

You can do it like this: class Example { private $__readOnly = ‘hello world’; function __get($name) { if($name === ‘readOnly’) return $this->__readOnly; user_error(“Invalid property: ” . __CLASS__ . “->$name”); } function __set($name, $value) { user_error(“Can’t set property: ” . __CLASS__ . “->$name”); } } Only use this when you really need it – it is … Read more

Why functional languages? [closed]

Functional languages use a different paradigm than imperative and object-oriented languages. They use side-effect-free functions as a basic building block in the language. This enables lots of things and makes a lot of things more difficult (or in most cases different from what people are used to). One of the biggest advantages with functional programming … Read more

How to pattern match into an uppercase variable?

The short answer is don’t. Syntax conventions make your code readable and understandable for others. Scala’s convention is that variables start with lower-case and constants and classes start with upper-case. By violating this, not only you get problems like pattern-matching issues, your code becomes less readable. (Believe me, if you ever have to read code … Read more

What is the ‘expression problem’?

Watch this lecture. The idea is that your program is a combination of a datatype and operations over it. The problem asks for an implementation that allows to add new cases of the type and new operations without the need for recompilation of the old modules and keeping static type safety(no casts or runtime type … Read more

Why are dates calculated from January 1st, 1970? [duplicate]

using date(January 1st, 1970) as default standard The Question makes two false assumptions: All time-tracking in computing is done as a count-since-1970. Such tracking is standard. Two Dozen Epochs Time in computing is not always tracked from the beginning of 1970 UTC. While that epoch reference is popular, various computing environments over the decades have … Read more