language-design

Programming language categories

What programming language categories are there? I know about object-oriented languages, functional languages, procedural languages.... what other 'paradigms' are there? What are the best languages in each class? In what situations would you choose one type of language over another? Are there any really obscure language types that may n...

Why is Javascript the "most misunderstood language" ?

Douglas Crockford himself says so ! http://www.crockford.com/javascript/javascript.html I have been working with JS only for the past few months, with jQuery and ExtJS. Soon will get to work on Secha Touch. I find Javascript to be highly enlightening.. What is your opinion ? Crockford himself says that the language is not without its...

How can I write like "x == either 1 or 2" in a programming language?

Possible Duplicate: Why do most programming languages only have binary equality comparison operators? I have had a simple question for a fairly long time--since I started learning programming languages. I'd like to write like "if x is either 1 or 2 => TRUE (otherwise FALSE)." But when I write it in a programming language, s...

How do statically-typed languages deal without generics?

I'm curious which statically-typed languages have no generics support (and to a lesser extent which languages historically did not have generics), and how they deal with it. Do users just cast all over the place? Is there some special sauce for basic collections, like lists and dictionaries, that allow those types to be generic? Why ...

Are the languages with a sound type system a sub set of strongly typed languages?

The title says all. ...

Confused by Boxing. Casting -1 to Int64 throws InvalidCastException

Ok I must be overlooking something extremely simple but I am lost. Given this object val = -1; var foo = (Int32)(val); var bar = (Int64)(val); The cast to Int64 throws and InvalidCastException. I recognize this is related to some strangeness with boxing but I don't understand the reasoning. From what I understand val is boxed as ...

What programming languages have the most easily-implemented interpreters?

I need to implement an interpreter for a programming language as part of a project I'm working on. I don't think the details of this project are too relevant, except that it requires me to implement an interpreter from scratch, I can't use an existing programming language (the requirements include supporting portable delimited continuat...

Fixed Object Id for System Objects and Small Integers in Ruby

Why do system objects like nil, true or false have a fixed object id in Ruby. Also I tried printing out the object ids of numbers, they are the same and follow an odd number sequence pattern. Any explanation for this? [nil,true,false].each { |o| print o.object_id, ' '} 4 2 0 => [nil, true, false] >> (0..50).each { |i| print i.object_id...

Why don't PHP attributes allow functions?

I'm pretty new to PHP, but I've been programming in similar languages for years. I was flummoxed by the following: class Foo { public $path = array( realpath(".") ); } It produced a syntax error: Parse error: syntax error, unexpected '(', expecting ')' in test.php on line 5 which is the realpath call. But this works ...

Why is -1 the result of coercing True to an integer in VB6?

In VB6, coercing True to an integer yields the value -1. Why is this so? What is the reasoning behind this? In most other programming languages (C/C++, Java, Perl, Python, etc.), true becomes 1 when coerced into an integer. In boolean algebra, the value 1 is used to represent true/on. Why does VB6 do it differently? I do see a certain...

Collection Initialization Syntax, what for?

We just can use function like public static List<T> New<T>(params T[] items) { return new List<T>(items); } and more important it's better var list = new List<int> {1,2,3}; var list = List.New(1,2,3); So, when we really need to use it? Dictionary public static Dictionary<T, K> New<T, K>(T key, K value) { return new Dictio...

Why dynamic call return dynamic result?

public string Foo(object obj) { return null; } public string Foo(string str) { return null; } var x = Foo((dynamic) "abc"); Why is x dynamic, compiler not smart enough or I miss something important? ...

Calling Java varargs method with single null argument?

If I have a vararg Java method foo(Object ...arg) and I call foo(null, null), I have both arg[0] and arg[1] as nulls. But if I call foo(null), arg itself is null. Why is this happening? ...

Design pattern as (missing) language feature

Sometimes people refer to design patterns as missing programming language features. To avoid the debate about what is a design pattern, let's say we only consider the original GoF patterns. For instance, the singleton pattern vanishes in Scala which supports singleton objects using the keyword object. There are few resources around abo...

Why are polymorphic messages so much more powerful in practice than the combination of unification and backtracking?

One way of looking at the history of programming language design is that there was a revolution with the introduction of the subroutine. Twenty or thirty years later, two refinements of the subroutine call were seriously considered: Polymorphic messages Unification and backtracking I've just been programming in Prolog after a 20 year...

How are classes implemented in compilers

I'd like to implement a class type for my own little language but what I thought at first wouldn't be too hard has got me stumped. I have the parser in place and it's the code generation side of things I'm having problems with. Can anyone shed any light on the best/correct way to go about this? Specifically I'd like to do this in LLVM so...

Why does java have no byte type suffix?

So java has a long type suffix for literals: (123L), a double type suffix (43.21D), a floating point suffix (1.234F). So ... why no byte type suffix? For example, when writing some testing code you MUST cast all your bytes when they are used as function parameters. ByteBuffer b = ByteBuffer.allocate(100); b.put((byte)3); // super an...