There's "first-class", but is there "second-class"? "third-class"? "nth-class"? And if so, what are they?
"First and second class objects. In ALGOL, a real number may appear in an expression or be assigned to a variable, and either of them may appear as an actual parameter in a procedure call. A procedure, on the other hand, may only appear in another procedure call either as the operator (the most common case) or as one of the actual parameters. There are no other expressions involving procedures or whose results are procedures. Thus in a sense procedures in ALGOL are second class citizens—they always have to appear in person and can never be represented by a variable or expression (except in the case of a formal parameter)"
I do not understand most of that. I would prefer how @bh would explain it.
bruh. Basically first class means that it can be referenced through a variable, but some data in some languages can't be stored in a variable, and has to be physically present for it to be used. For example, in Scratch the code isn't 1st class because you can't store it in a variable and use the RUN block in Snap!. You actually need the code to be there.
There's more to first-classness:
- It must be able to be stored in a variable
- It must be able to be given as input to a procedure
- It must be able to be returned from a procedure
- It must be able to be put in a list or other data aggregate
- It must be able to be anonymous, AKA unnamed
The origin of the phrase "second class citizen" was to describe people who, while officially citizens of a country, did not in practice have the full rights of citizens, e.g., Black people in the US. (This is arguably still true, but it was very true before the passage of the Civil Rights Act of (iirc) 1974.) Since this is an unofficial designation, it's really just a yes-or-no question. (There's a sort of exception in India, where for a long time there was an official caste system with like half a dozen castes and a partial ordering. It's now officially gone but there's still a lot of prejudice against Dalit people.)
So, "first class citizen" is a backformation from that. The whole point is that there shouldn't be any second class citizens among people, and arguably shouldn't be any among data types either.
And Muslims in India.
I don't see a reason for things not to be first class. In using Snap! first class data has only been a useful tool for solving problems.
Until pretty recently, mainstream programming language developers just didn't know any better. All those people on stackoverflow going on about stack storage vs. heap storage of data are still totally missing the point, which is about usability rather than about implementation.
Having said that, sometimes making a data type first class has a huge efficiency cost, and even competent language designers might decide the marginal benefit isn't worth the cost. The prime example is environments (where names are bound to variables) in Scheme. It's not that creating environments on the fly is hard; the cost is that every variable name lookup has to search through all those environments; it means you can no longer compile out name references. (But even so, more recent versions of Scheme have dipped their toes in the water.)