First-class citizen (programming): Difference between revisions

From Helpful
Jump to navigation Jump to search
(Created page with "<!-- {{zzz|Confusingly, the class in first-class here refers not to OO classes but the sense of quality - first-rate, second-rate, etc.)}} In programming, '''First-class ci...")
 
mNo edit summary
Line 1: Line 1:
<!--


{{zzz|Confusingly, the class in first-class here refers not to OO classes but the sense of quality - first-rate, second-rate, etc.)}}
{{stub}}
 
 
{{comment|Confusingly, the class in first-class here refers not to OO classes but the sense of quality - first-rate, second-rate, etc.)}}




Line 43: Line 45:




-->





Revision as of 13:31, 10 July 2023

This article/section is a stub — some half-sorted notes, not necessarily checked, not necessarily correct. Feel free to ignore, or tell me about it.


Confusingly, the class in first-class here refers not to OO classes but the sense of quality - first-rate, second-rate, etc.)


In programming, First-class citizen has varied definitions, that vary in the details, because the most useful distinction depends on context.

For example, you can give a more useful definition when describing to a specific static language (e.g. C++), or a specific dynamic language (e.g. JS, Python), or a language that cheats usefully (e.g Java).


First-class citizen tends to refer to a language in which a particular thing is like any other, without any trickery.

The most common indications / things we care about are the ability to pass as an argument, returned from a function, and assigned to a variable.


First-class objects often refers to dynamic languages, constructing objects at runtime, refers to objects that you create at runtime that you can do that (and more).


A First-class type refers to a language


Sometimes that gets a little more abstract. For example,

For example, in Javascript and Python, functions are first-class objects: They are part of the language's typing system, you can construct them, you can pass them, and return them.

In C++ functions themselves are not first class objects - after compilation, they exist not as things you can hand around and inspect, only really as "if you put the right things on the stack and jump here, things will happen as expected". (...with footnotes, I know.)



Raphael Finkel splits things out a bit more:

  • first-class - An entity you can pass as a parameter, return, and assign to a variable
  • second-class - an entity you can passed as a parameter, cannot returned from a function, and cannot store into a variable
  • third-class - an enitity you cannot pass as a parameter, cannot returned from a function, and cannot store into a variable

(TODO: examples)





https://en.wikipedia.org/wiki/First-class_citizen