language-design

Why is The Iteration Variable in a C# foreach statement read-only?

As I understand it, C#'s foreach iteration variable is immutable. Which means I can't modify the iterator like this: foreach (Position Location in Map) { //We want to fudge the position to hide the exact coordinates Location = Location + Random(); //Compiler Error Plot(Location); } I can't modify the iterator vari...

Documentation on creating a programming language

Duplicate of Learning to write a compiler and What are the best resources on designing a new language? Can you point to what you think is the best documentation on creating a new programming language (--apart from the Dragon book, which I know of already). I am interested in both scripting language and general programming language desig...

Why did the language designers of C do type equivalance like this?

I'm learning C and I'm reading about type equivalence. I'm curious, does anyone have an opinion why they used structural equivalence for arrays and pointers but they used declaration equivalence for structs and unions? Why the disparity there? What is the benefit of doing declaration equivalence with structs/unions and structural equi...

Why doesn't ORACLE allow consecutive newline characters in commands?

I write: :CREATE TABLE Person ( :name CHAR(10), : :ssn INTEGER); and save it to a file "a.sql" (colon represents beginning of line, is not in actual code.) If I then run it by typing "@a" in the mysql command prompt, it will tell me that the line starting with "ssn" is not recognized as a command, and is ignored. From what I gathe...

Does C# have too many language features?

This is a discussion that pops a from time to time in our team. While a few quickly learned C# 3.0 features, other stick with classical techniques. Some never use Linq, think that lambda expressions are confusing and yield is "scary". Sometimes they can hardly understand code that is written by people using all the new features. We can ...

What is the best way to implement templates in a programming language?

I'm designing a high level, object oriented, garbage collected programming language, and I'm having a problem with how to do templates. I plan on creating a VM-type system, similar to .NET or JVM (but it will use LLVM under the hood). The problem is that I want to have powerful, C++-like templates, but with dynamic linking (so I could re...

How can I add a C-based language to GCC

If I wanted to modify or add my own extensions to C, and add them to the GCC C compiler, what would I need to do? I do not want to propose changes to the language, I want to know how the C compiler actually works. I've had a look at the source code to GCC and it looks as if Objective-C is implemented as a simple parser that generates co...

Why are empty expressions legal in C/C++?

int main() { int var = 0;; // Typo which compiles just fine } ...

Usual arithmetic conversion -- a better set of rules?

Consider the following code: void f(byte x) {print("byte");} void f(short x) {print("short");} void f(int x) {print("int");} void main() { byte b1, b2; short s1, s2; f(b1 + b2); // byte + byte = int f(s1 + s2); // short + short = int } In C++, C#, D, and Java, both function calls resolve to the "int" overloads... I a...

Why is there no ^^ operator in C/C++?

& has &&. | has ||. Why doesn't ^ have ^^? I understand that it wouldn't be short-circuiting, but it would have different semantics. In C, true is really any non-zero value. Bitwise XOR is not always the same thing as logical XOR: int a=strcmp(str1,str2);// evaluates to 1, which is "true" int b=strcmp(str1,str3);// evaluates to 2, whic...

C++ Iterators Considered Harmful?

At the Boost library conference today, Andrei Alexandrescu author of the book Modern C++ Design and the Loki C++ library, spoke about why iterators are bad, and he had a better solution. I tried to read the presentation slides, but could not get much out of them. I have these questions for the StackOverflow community: Are iterators ba...

Choosing a consistency model for a concurrent programming language

I am in the design phase of a programming language, currently thinking about the concurrency aspects. I need to figure out a consistency model, i.e. how data is handled by concurrent processes programmed in this language. There are two important criteria: I prefer ease-of-use over performance, as long as the consistency model allows g...

How should substring() work?

I do not understand why Java's String.substring() method is specified the way it is. I can't tell it to start at a numbered-position and return a specified number of characters; I have to compute the end position myself. And if I specify an end position beyond the end of the String, instead of just returning the rest of the String for ...

Natural Programming Language.... what would you like to see?

I am looking at writing a compiler and after I complete something in a "C" style I am looking at adapting it to other models. What are some syntactical constructs you would expect to see in a "natural" programming language? The target platform for this compiler will be the CLR and I am currently using Oslo+MGrammar for the lexer/pars...

Why do property setters and getters clash with get_X and set_X methods?

In .NET properties are supposed to be first class citizens however in the IL code property getters and setters are implemented as get_PropertyName and set_PropertyName. class Property { int Value { get { return 42; } } int get_Value() { return 6 * 9; } void set_Value(int i) { } // Error even though Value is a read only prope...

What is “mature” software?

Jeffery Palermo says 'Classic WebForms More Mature Than ASP.NET MVC': "Is Classic WebForms More Mature Than ASP.NET MVC?". It seems to be subjective, but what I want to know is, what exactly "mature" software is? ...

Using variable keys to access values in JSON objects

The code: function updateDashboardData() { $.getJSON("includes/system/ajaxDataInterface.php", {recordcount:1}, function(data) { $('.stationContainer').each(function(data) { var bsID = $(this).attr("id"); var bsStatus = $(this).children('.stationStatus'); alert(data[bsID][0].time); bsStatus.find('.bs_maxH...

In C/C++ why does the do while(expression); need a semi colon?

My guess is it just made parsing easier, but I can't see exactly why. So what does this have ... do { some stuff } while(test); more stuff that's better than ... do { some stuff } while(test) more stuff ...

What is the point of make_heap?

Can someone please tell me the point of the STL heap functions like make_heap? Why would anyone ever use them? Is there a practical use? ...

Foreach can throw an InvalidCastException??? Damn...

Imagine the following code: class foreach_convert { public static void method2() { List<IComparable> x = new List<IComparable>(); x.Add(5); foreach (string s in x) { //InvalidCastException in runtime } } } I wonder, why is this foreach behavior so... not C#-like? What ha...