language-design

Is new-ing objects obsolete?

Ok, so here's the question... is the new keyword obsolete? Consider in C# (and java, I believe) there are strict rules for types. Classes are reference types and can only be created on the heap. POD types are created on the stack; if you want to allocate them on the heap you have to box them in an object type. In C#, structs are the ex...

Any BNF IDE with test features

I'm working on a new language and while writting the grammar I'd like to be able to test the grammar for completeness, conflicts and similar. I'm not really concern about the underlaying parser generator (but one for .NET would be preferrable) So feature list in short would be: text editor build functionality syntax/sematics error rep...

How to Correctly Use Lists in R?

Brief background: Many (most?) modern programming languages in widespread use have at least a handful of ADTs in common, in particular, string (a (sequence comprised of characters), list (an ordered collection of values), and a map-based type (an unordered key-value store). In the R, the first two are implemented as 'character' and 'vect...

F# parsing Abstract Syntax Trees

What is the best way to use F# to parse an AST to build an interpreter? There are plenty of F# examples for trivial syntax (basic arithmatical operations) but I can't seem to find anything for languages with much larger ranges of features. Discriminated unions look to be incrediably useful but how would you go about constructing one wit...

Why aren't there compiler-generated swap() methods in C++0x?

C++ compilers automatically generate copy constructors and copy-assignment operators. Why not swap too? These days the preferred method for implementing the copy-assignment operator is the copy-and-swap idiom: T& operator=(const T& other) { T copy(other); swap(copy); return *this; } (ignoring the copy-elision-friendly for...

Database tables with only one index ... bad idea?

If a programming language allowed the creation of database tables, but only allowed one field to be used as an index ... how limiting would that be? I am not a real database programmer, so I'm wondering if such a system could be used as the basis for serious databases, or would be only a toy. ...

Is Lua interesting, from a programming language design perspective?

Lua occupies a good place in the space of languages that can be embedded. Is this a result of interesting new ideas the implementors had, or is it a result of good execution of well-established ideas? Comparison of properties and features of Lua to other PLs are particularly appropriate. ...

What are the problems that would require creating a new programming language?

This might be a silly question, but still I am going ahead and asking it. Nowadays I see new dynamic languages like Groovy being developed for the JVM, and languages like Ruby gaining prominence. Each of these seems to be solving different shortcomings in the existing languages. Is there any one or set of problems that are not addresse...

Why can't I inherit from int in C++ ?

I'd love to be able to do this: class myInt : public int { }; Why can't I ? Why would I want to? Stronger typing. For example, I could define two classes intA and intB, which let me do intA+intA or intB+intB, but not intA+intB. "Ints aren't classes" so? "Ints don't have any member data" Yes they do, they have 32 bits, or whatever....

What is a good VM for developing a hobby language?

I'm thinking about writing my own little language. I found a few options, but feel free to suggest more. JVM Parrot OSA A lot of languages are using the JVM, but unless you write a Java-ish language, all the power the stdlib gives you is going to feel ugly; It's not very good at dynamic stuff either. Parrot seems a good VM for deve...

Polymorphism by function parameter

Ok - this may be a very stupid question, but it's been bothering me. Is there a language where class Animal; class Ape : public Animal {...} void doStuff(Animal* animalPtr) { cout << "doing animal stuff" << endl; } void doStuff(Ape* apePtr) { cout << "doing ape stuff" << endl; } Animal *ape = new Ape(); doStuff(ape); would...

C-like language without NULL?

Hi I was recently watching an old video about how null pointers were a billion dollar mistake. He points out both C# and java as they have run-time checks but don't completely eliminate it enough and this is somewhat understandable. He also points out the C at one point which he feels so sure of is a great problem. I get that null termin...

Parsing "off-side" (indentation-based) languages

An off-side language is the one where ...the scope of declarations (a block) in that language is expressed by their indentation. Examples of such languages are Python, Boo, Nemerle, YAML and several more. So my question is this: how do I actually parse these? How do I resolve tabs vs spaces problem (are two tabs or 8 spaces equiv...

When implementing an interpreter, is it a good or bad to piggyback off the host language's garbage collector?

Let's say you are implementing an interpreter for a GCed language in a language that is GCed. It seems to me you'd get garbage collection for free as long as you are reasonably careful about your design. Is this generally how it's done? Are there good reasons not to do this? ...

What's a good method for serving content in different languages using asp?

Hi, I'm trying to figure out which would be the best way to go about serving asp classic pages in different languages. Some of the content on the page is generated server-side and some is hard-coded html. I would like to create a drop-down to select between different languages so that the server-side generated html as well as the hard-co...

Designing a language with Checked Exceptions

I'm well aware of the whole argument over whether or not checked exceptions are a good idea and I fall on the side that they are...but that is not the point of this question. I'm in the process of designing a fairly simple compiled OOP language and I've decided to use checked exceptions basically as a way of returning errors without goin...

Why can't operators be overloaded inside a static class?

I have an extension class for System.Net.IPAddress and I was wanting to overload the binary operators >, <, == but the compiler is telling me that I can't overload those operators inside a static class, which I must have for my other extension methods. Is there a particular reason for this? Thanks. ...

String/Range comparison problem

This make sense for things like : irb(main):001:0> ["b", "aa", "d", "dd"].sort => ["aa", "b", "d", "dd"] But doesn't for : irb(main):002:0> ("B".."AA").each{ |x| print "#{x}," } => "B".."AA" should produce : B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,AA,=> "B".."AA" but "B" > "AA" => true Unlike "B".."BA" ("B" > "BA" => fa...

Why are regular expressions greedy by default?

It seems that this is a huge source of confusion for beginners writing regular expressions, can cause hidden performance problems, and it would seem that a typical use case would be non-greedy. Is this just for legacy reasons (it was how it was first done, and every implementation copies that), or is there a reason for it? ...

Unreachable code: error or warning?

This is a language design question: Do you think unreachable code (in programming languages in general) should raise a warning (i.e. "report problem and compile anyway") or an error ("refuse to compile")? Personally I strongly feel it should be an error: if the programmer writes a piece of code, it should always be with the intention o...