I have seen many times statements like- "Please make this feature a first class citizen in so and so language/platform". For example, it is said about enums in C#/.net. So, when is a feature considered a "First class citizen" in a programming language/platform?
|
|
|||||||||||||
|
|
The notion of "first-class citizen" or "first-class element" in a programming language was introduced by British computer scientist Christopher Strachey in the 1960s in the context of first-class functions. The most famous formulation of this principle is probably in Structure and Interpretation of Computer Programs by Gerald Jay Sussman and Harry Abelson:
Basically, it means that you can do with this programming language element everything that you can do with all other elements in the programming language. It's all about "equal rights": you can do all of the above, with, say, integers, so why should any other thing be different? The definition above is a bit restrictive in the sense that it only really talks about the aspect of first-classness as related to being objects of the program. A more general definition would be that a thing is first-class if you can do everything with it you can also do with other things of similar kind. For example, Java operators and Java methods are of similar kind. You can define new methods, you can (somewhat) freely choose the names of your own methods, you can override methods, you can overload methods. James Gosling can do all of that with operators, too, but you and I can't. I mean, contrary to popular belief, Java does support operator overloading: for example, the |
|||||
|
|
Usually this refers to a construct that is passable as a parameter, can be defined as a return type from a function or can be assigned a value. Normally you need to be able to construct them at runtime. For example an instance of a class would be a first class citizen in c++ or java, but a function in C would not be. |
|||||||||||||||
|
|
I would say a feature is a first class citizen if it is implemented solely by the language. Example: In C/C++ I do not consider functions to be a first class citizen (others may). |
|||||||||||||
|
|
To add an example to the answers already provided: In WCF/C# you currently have to mark a class object with a service contract attribute to have it operate as a service. There is no such thing as:
A class is a first class citizen in c#, where a service is not. Hope this helps |
|||
|
|
