language-design

Fine-grained sandboxing

Scenario: a program running in a byte code virtual machine like Java or Python, wants to evaluate (by compiling on the fly to byte code and then running) a function whose code was automatically generated or supplied from outside. The tricky bit is that the function's code is not trusted -- it may have been generated by a stochastic meth...

Are there good reasons for 'private' to work the way it does in Ruby?

It took me a while to understand how private methods work in Ruby, and it really strikes me as being very awkward. Does anyone know if there are good reasons for private methods to be handled the way they are? Is it just historic reasons? Or implementation reasons? Or are there good solid logical reasons (ie. semantic)? For example: c...

Are design patterns really language weaknesses?

Should today's patterns be seen as defects or missing features in Java and C++? Subroutine was a design pattern for machine language in the 50s and 60s. Object-Oriented Class was a design pattern for C in the 70s. Visitors, Abstract Factories, Decorators, and Façades are design patterns for Java and C++ today. What will tomorrow's l...

create a object : A.new or new A?

Hi, Just out of curiosity: Why C++ choose a = new A instead of a = A.new as the way to instantiate an object? Doesn't latter seems more like more object-oriented? ...

Convergence of Mathematics and Programming Languages

It seems that there is a strong movement for the convergence of mathematics and computer programming languages, this is notably evidenced by the influence of the lambda calculus on modern languages. Most of the time I do not think with mathematics, I think with logic. It seems to me that many of the phenomenon that can be modeled mathema...

Why dont languages allow overloading of methods by return value?

c, java and many other languages do not pay attention to return values. int i = func() float f = func() int func() { return 5 } float func() { return 1.3} Why isnt the above legal? Does it make it more difficult to program int i = func(func(func(func2(func3())))) //you dont know what you are getting Is it hard to write a compi...

Mathematica: Unevaluated vs Defer vs Hold vs HoldForm vs HoldAllComplete vs etc etc

I'm bewildered by all the built-in Mathematica functions that purport to prevent evaluation in some way: Unevaluated, Defer, Hold, and over half a dozen of the form Hold*. The Mathematica documentation just explains each function in isolation without explaining why you would choose one or the other. Can anyone offer a coherent explanat...

Choosing a syntax for list generating expressions

C# has generator functions which have syntax like: IEnumerable<int> GetNats(int max) { for (int i=0; i < max; ++i) yield return i; } A feature I am interested in for my programming language (a simple object-oriented programming similar to Java, Scala, ActionScript, and C#) are generator expressions. These are essentially syn...

What should happen when a generator function is assigned?

If I have a programming language with first class functions. What should the semantics be when a generator function is shared? For example: var f = function() { foreach (i in 0..42) yield i; } int a = f(); // 0 int b = f(); // 1 // Assigning the generator function var g = f; int c = g(); // ?? int d = f(); // ?? I can i...

Which regular expression api would you emulate?

Most programming languages have apis for regular expression searching and replacing. In my experience the apis can be quite clunky, probably due to the number of actions available and efficiency considerations. If you were going to implement an api, which one would you emulate? Of particular interest is the methods and objects of the a...

what exactly is a "register machine" ?

From http://code.google.com/p/unladen-swallow/wiki/ProjectPlan I quote: "Using a JIT will also allow us to move Python from a stack-based machine to a register machine, which has been shown to improve performance in other similar languages (Ierusalimschy et al, 2005; Shi et al, 2005)." In college I built a simple compiler for a languag...

Parallel Map (Generator) Operator

I am interested in defining a parallel map operator for my language. It transforms a list into a new list given an expression. It would have a syntax similar to a generator. Unlike generators in C# and Python, it would potentially be evaluated in parallel, if the compiler desires (e.g. there is an idle core, and the list is really big). ...

Is there a programming language that allows variable declaration at call site?

Update 2: examples removed, because they were misleading. The ones below are more relevant. My question: Is there a programming language with such a construct? Update: Now when I think about it, Prolog has something similar. I even allows defining operations at definition line. (forget about backtracking and relations - think about ...

The advantages of having static function like len(), max(), and min() over inherited method calls

Hi! i am a python newbie, and i am not sure why python implemented len(obj), max(obj), and min(obj) as a static like functions (i am from the java language) over obj.len(), obj.max(), and obj.min() what are the advantages and disadvantages (other than obvious inconsistency) of having len()... over the method calls? why guido chose thi...

When someone writes a new programming language, what do they write it IN?

Please excuse my ignorance. I'm dabbling in PHP and getting my feet wet browsing SO, and feel compelled to ask a question that I've been wondering about for years: When you write an entirely new programming language, what do you write it in? This probably sounds really silly to all you programmers, for whom I have tremendous respect, b...

Why are default arguments evaluated at definition time in Python?

I had a very difficult time with understanding the root cause of a problem in an algorithm. Then, by simplifying the functions step by step I found out that evaluation of default arguments in Python doesn't behave as I expected. The code is as follows: class Node(object): def __init__(self, children = []): self.children = c...

BNF grammar for sequence of statements

If I am making a grammar for a c-like language that has a sequence of statements, what is the most standard way for defining the grammar? My thought is to do something like this: <program> ::= <statement> <statement> ::= <statement-head><statement-tail> <statement-head> ::= <if-statement> | <var-declaration> | <assignment> | <whatever>...

Why does COBOL have both `SECTION` and `PARAGRAPH`?

Why does COBOL have both SECTION and PARAGRAPH? Can anybody explain why the designers of COBOL created both SECTIONs and PARAGRAPHs? These have been around since the initial release of COBOL so I suspect the real reason for their existence has long since gone away (similar to things like NEXT SENTENCE which are still in the language spe...

Variable name taken by keyword -- your examples?

Have there been any cases where you wanted to use a word as a variable/function name, but couldn't because it was a reserved word in your language? The ones that crop up over and over again for me are in and out in C#... Those would be great names for streams, but I'm always forced to use inn and outt instead. EDIT: I'm not asking ab...

Why do a lot of programming languages put the type *after* the variable name?

I just came across this question in the Go FAQ, and it reminded me of something that's been bugging me for a while. Unfortunately, I don't really see what the answer is getting at. It seems like almost every non C-like language puts the type after the variable name, like so: var : int Just out of sheer curiosity, why is this? Are t...