language-design

Writing a mini-language

I have an application that needs to allow users to write expressions similar to excel: (H1 + (D1 / C3)) * I8 and more complex things like If(H1 = 'True', D3 * .2, D3 * .5) I can only do so much with regular expressions. Any suggestions as to the right approach to doing this as well as any resources I can learn from would be much app...

What would it take for people to move away from C++?

Even most people who like C++ admit that it has tons of warts not related to its niche as a systems/performance programming language. These include its antiquated module management system (header files), requirement for forward declarations, syntax quirks that make its grammar undecidable (such as <> angle brackets for template declarati...

What lessons can be learned from the prototype model in javascript?

The question is from a language design perspective. I should explain a little about the situation. I am working on a javascript variant which does not support prototypes, however it is overdue a decent type system (most importantly support for instanceof). The ecmascript spec is not important, so i have the freedom to implement somethin...

Why can't Regular Expressions use keywords instead of characters?

Okay, I barely understand RegEx basics, but why couldn't they design it to use keywords (like SQL) instead of some cryptic wildcard characters and symbols? Is it for performance since the RegEx is interpreted/parsed at runtime? (not compiled) Or maybe for speed of writing? Considering that when you learn some "simple" character combina...

Why do optional class attributes in VB.NET have a weird syntax?

I'm just curious why class/property attributes in VB.NET have a weird optional syntax such as: <TestAttr("a", "abc", Optional1:="foo", Optional2:=3)> VB.NET allows you to set optional parameters like this to avoid order restrictions (which is lovely) but in this case it's forcing you to that. For example this is not possible: <TestA...

Is the foreach in VB.NET faster than in c#?

My co-worker said that in a previous interview, he learned that foreach is faster in VB.Net than c#'s foreach. He was told that this was because both have different CLR implementation. Coming from a C++ perspective, I'm curious on why this is and I was told that I need to read up on CLR first. Googling foreach and CLR doesn't help me un...

C#: Why is adding null to a string legal?

The MSDN article on String Basics shows this: string str = "hello"; string nullStr = null; string emptyStr = ""; string tempStr = str + nullStr; // tempStr = "hello" bool b = (emptyStr == nullStr);// b = false; string newStr = emptyStr + nullStr; // creates a new empty string int len = nullStr.Length; // throws NullReferenceException ...

What language features are needed for game scripting?

I am looking into designing a game scripting language and was wondering what people employed in the games industry considered essential items/properties for a good game scripting language. This includes things like: static vs dynamic types Who should it be aimed at: programmers or designers? syntax(must it look like C?) How high level...

What is the overall design philosophy of php?

I recently had my first encounter with PHP (5) through a Drupal application for a client. There was certainly nothing difficult about the experience (documentation is good for instance), but I never had a moment where I thought, "that's really clever!", or "wow this is fun to use!" Moreover, I couldn't accurately predict how functions we...

What is the difference between static and dynamic binding?

Binding times can be classified between two types: static and dynamic. What is the difference between static and dynamic binding? Could you give a quick example of each to further illustrate it? ...

What are the advantages and disadvantages of separating declaration and definition as in C++?

In C++, declaration and definition of functions, variables and constants can be separated like so: function someFunc(); function someFunc() { //Implementation. } In fact, in the definition of classes, this is often the case. A class is usually declared with it's members in a .h file, and these are then defined in a corresponding .C...

What are C macros useful for?

I have written a little bit of C, and I can read it well enough to get a general idea of what it is doing, but every time I have encountered a macro it has thrown me completely. I end up having to remember what the macro is a and substitute it in my head as I read. The ones that I have encountered that were intuitive and easy to understa...

Why no non-integral enums?

Why is it that non-integral enums cannot be created? I want to know if this is a language design decision, or if there are issues with implementing this in the compiler. In other words, is it feasible to implement non-integral enums into the language, but there just isn't a justifiable need? Or if it isn't feasible but is justifiable, ...

Region based memory management

I'm designing a high level language, and I want it to have the speed of C++ (it will use LLVM), but be safe and high level like C#. Garbage collection is slow, and new/delete is unsafe. I decided to try to use "region based memory management" (there are a few papers about it on the web, mostly for functional languages). The only "useful"...

Non-nullable reference types

I'm designing a language, and I'm wondering if it's reasonable to make reference types non-nullable by default, and use "?" for nullable value and reference types. Are there any problems with this? What would you do about this: class Foo { Bar? b; Bar b2; Foo() { b.DoSomething(); //valid, but will cause exception ...

Mutable or immutable closures

In an imperative, object orients language, would make more sense to have mutable or immutable closures? For example: int i=5; function() f={print(i);}; f(); i=6; f(); If the closure is mutable, this would print: 5 6 If it is immutable, it would print: 5 5 I realize that even with immutable closures, you could still do this: cl...

boolean true -- positive 1 or negative 1?

I'm designing a language, and trying to decide whether true should be 0x01 or 0xff. Obviously all non-zero values will be converted to true, but I'm trying to decide on the exact internal representation. What are the pros and cons for each choice? ...

Why are references not reseatable in C++

Hi, C++ references have two properties: They always point to the same object. They can not be 0. Pointers are the opposite: They can point to different objects. They can be 0. Why is there no "non-nullable, reseatable reference or pointer" in C++? I can't think of a good reason why references shouldn't be reseatable. Edit: The ...

Usefullness of the unary plus operator

Duplicate What does the unary plus operator do? Is there any good use for the unary plus operator? For numbers it does nothing. I suppose you could overload it for custom types, but that would be non-standard operator behaviour (bad). It also makes parsing code somewhat harder. So, are there any cases where it makes sense to overl...

Which is more readable/writable—code that uses keywords for declarations or code that uses typographical symbols?

I'm implementing a programming language and I'm considering the following syntax: @NamespaceX { +@ClassY <> : BaseTypeA { +@NestedClassW<> { } +@MethodZ() : ReturnTypeC { //".?" is a null-coallescing member access operator @varD : ClassY = predicateP ? objectQ.?PropertyS ...