First-class citizen (programming): Difference between revisions

From Helpful
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 1: Line 1:


{{stub}}
{{programming}}





Revision as of 16:06, 14 July 2023

Some fragmented programming-related notes, not meant as introduction or tutorial

Data: Numbers in computers ·· Computer dates and times ·· Data structures

Wider abstractions: Programming language typology and glossary · Generics and templating ·· Some abstractions around programming · · Computational complexity theory notes · Synchronous, asynchronous · First-class citizen

Syntaxy abstractions: Constness · Memory aliasing · Binding, assignment, and such · Closures · Context manager · Garbage collection

Sharing stuff: Communicated state and calls · Locking, data versioning, concurrency, and larger-scale computing notes

Language specific: Python notes ·· C and C++ notes · Compiling and linking ·· Lua notes

Teams and products: Programming in teams, working on larger systems, keeping code healthy · Benchmarking, performance testing, load testing, stress testing, etc. · Maintainability

More applied notes: Optimized number crunching · File polling, event notification · Webdev · GUI toolkit notes

Mechanics of duct taping software together: Automation, remote management, configuration management · Build tool notes · Installers



(it is potentially confusing that 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