Suggestions for writing a programming language? [closed]

Estimating how long something like that might take is dependent on many different factors. For example, an experienced programmer can easily knock out a simple arithmetic expression evaluator in a couple of hours, with unit tests. But a novice programmer may have to learn about parsing techniques, recursive descent, abstract representation of expression trees, tree-walking … Read more

Eric Lippert’s challenge “comma-quibbling”, best answer?

Inefficient, but I think clear. public static string CommaQuibbling(IEnumerable<string> items) { List<String> list = new List<String>(items); if (list.Count == 0) { return “{}”; } if (list.Count == 1) { return “{” + list[0] + “}”; } String[] initial = list.GetRange(0, list.Count – 1).ToArray(); return “{” + String.Join(“, “, initial) + ” and ” + list[list.Count … Read more

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

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