What is the rationale for not having static constructor in C++?

Using the static initialization order problem as an excuse to not introducing this feature to the language is and always has been a matter of status quo – it wasn’t introduced because it wasn’t introduced and people keep thinking that initialization order was a reason not to introduce it, even if the order problem has … Read more

How to declare a C# Record Type?

Update: C# 9 now contains record types. public record Person { public string LastName { get; } public string FirstName { get; } public Person(string first, string last) => (FirstName, LastName) = (first, last); } Old answer: Record types are not (yet) implemented in C#. See the proposal in the official GitHub repository: https://github.com/dotnet/csharplang/blob/master/proposals/records.md Discuss … Read more

What is the maximum length of a C#/CLI identifier?

In addition to the other answers, the maximum identifier length that is accepted by the Microsoft Visual C# compiler is 511 characters. This can be tested with the following code: class Program { private static void Main(string[] args) { int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = 5; } } The length of the variable name there is 511 characters. … Read more

What’s so great about Scala? [closed]

Here are some of the things that made me favour Scala (over, say, usual Java): a) Type inference. The Java way of doing it: Map<Something, List<SomethingElse>> list = new HashMap<Something, List<SomethingElse>>() .. is rather verbose compared to Scala. The compiler should be able to figure it out if you give one of these lists. b) … Read more

Is there, or is there ever going to be, a conditional operator in Delphi?

Such an operator isn’t part of the current Delphi version because it wasn’t part of the previous version, and demand wasn’t great enough to justify the cost of adding it. (You’ll find that explanation applies to lots of features you wish you had in lots of products.) Delphi provides a set of IfThen functions in … Read more

What’s the new way to iterate over a Java Map in Scala 2.8.0?

In 2.8, you import scala.collection.JavaConversions._ and use as a Scala map. Here’s an example (in 2.8.0.RC1): scala> val jmap:java.util.Map[String,String] = new java.util.HashMap[String,String] jmap: java.util.Map[String,String] = {} scala> jmap.put(“Hi”,”there”) res0: String = null scala> jmap.put(“So”,”long”) res1: String = null scala> jmap.put(“Never”,”mind”) res2: String = null scala> import scala.collection.JavaConversions._ import scala.collection.JavaConversions._ scala> jmap.foreach(kv => println(kv._1 + ” … Read more

Java’s switch equivalent in Clojure?

case is a good option as pointed out by Jan cond is also very useful in many related circumstances, particularly if you want to switch on the basis of evaluating a range of different conditional expressions, e.g. (defn account-message [balance] (cond (< balance 0) “Overdrawn!” (< balance 100) “Low balance” (> balance 1000000) “Rich as … Read more

Have you ever restricted yourself to using a subset of language features?

Douglas Crockford’s book JavaScript: The Good Parts is a prime example of this. He lists ‘features’ in JavaScript that should be avoided and provides alternatives that use the ‘good parts’ of the language. A few of the bad parts are: eval slower, harder to read, dangerously insecure == confusing and ambiguous with differently typed operands … Read more