The upcoming revision of the C language standard (for now called C2y) is
about to feature a new operator that essentially is a standardization of
ages old sizeof arr / sizeof arr[0]
trick for getting number of elements
in an array. But as we all know, beside cache invalidation, and off-by-one
errors, the 2nd hard problem in Computer Science is naming things.
Initially it was supposed to be just a quick e-mail during the discussion with just few examples, but as I've gone into the rabbit hole, it somehow ended in a white paper format. You can read that version on the WG14 website as document N3402.
I'm fairly sure over 100 languages listed in the "official" document is good enough sample size of a prior art to decide upon good name for C language, thus to not spam the committee further, any updates and additions I'll list here, in this blogpost copy of the paper.
Enjoy!
Popular high-level computer languages #
- Ada
- ABAP
- ALGOL
- Apex
- APL
- AWK
- gawk
- BASIC
- Batch files
- C
- C#
- C++
- CHILL
- CLIPS
- CMake
- COBOL
- Cobra
- ColdFusion
- Crystal
- Curl
- D
- Dart
- ECMAScript
- ActionScript
- JavaScript
- CoffeeScript
- JScript
- TypeScript
- Elixir
- Elm
- Erlang
- Flutter
- Forth
- Fortran
- FoxPro
- GAMS
- GDScript
- GLSL
- Go
- Groovy
- Hack
- Haskell
- Icon
- Java
- Julia
- Kotlin
- LabVIEW
- Lisp
- Clojure
- Common Lisp
- Emacs Lisp
- Racket
- Scheme
- Logo
- Lua
- Makefile
- GNU Make
- Maple
- MATLAB
- Modula-2
- Mojo
- ML
- F#
- OCaml
- Standard ML
- MQL5
- Nim
- occam 2
- Objective-C
- Odin
- Pascal
- Delphi
- Object Pascal
- Perl
- PHP
- PL/I
- PostScript
- PowerShell
- Prolog
- Python
- R
- Raku
- Ring
- RPG
- Ruby
- Rust
- SAS
- Scala
- Shell script
- Bash
- Korn Shell
- Simula
- Simulink
- Smalltalk
- Solidity
- SPARK
- SQL
- PL/SQL
- PostgreSQL
- Snowflake
- Swift
- SystemVerilog
- TeX
- LaTeX
- Tcl
- V
- Vala
- VBA
- VBScript
- VHDL
- Vim script
- Visual Basic
- Wolfram Language
- X++
- Zig
[so2024] [tiobe] [ieee] [github] [godbolt] [so-tags]
Getting length of array-like objects #
Languages using "size" #
- ALGOL [algol] (for ClearPath MCP Software by Unisys)
SIZE(myArray)
- Apex [apex]
myArray.size()
- C++ [cpp1] [cpp2] [cpp3]
std::size(myArray) myVector.size() myStdArray.size() // `myStdArray` being of type std::array
- CHILL [chill]
SIZE(myArray)
- Common Lisp [common-lisp-1]
(size myArray)
- Crystal [crystal]
myArray.size
- Curl [curl]
size(myArray)
- GDScript [gdscript]
myArray.size()
- Erlang [erlang1]
array:size(myArray)
- Fortran [fortran1] [fortran2]
SIZE(myArray)
- Groovy [groovy1] [groovy2]
myArray.size()
- Java [java2]
ArrayList.size()
- Julia [julia1] [julia2]
size(myArray)[1] size(myArray, 1)
- Kotlin [kotlin1] [kotlin2]
myArray.size
-
LabVIEW [labview]
Array Size function
- Maple [maple]
Size(myArray)
- MATLAB [matlab]
size(myArray)
- MQL5 [mql5]
ArraySize(myArray)
- occam 2 [occam]
SIZE myArray
- PHP [php2] (alias for
count()
)sizeof($myArray)
- Ruby [ruby2] [ruby4] (alias for
.length
)myArray.size
- Smalltalk [smalltalk]
myArray size.
- Snowflake [snowflake]
SELECT ARRAY_SIZE(ARRAY_CONSTRUCT(1, 2, 3)) AS SIZE;
- SPARK [spark]
size($"myArray")
- SystemVerilog [verilog]
myArray.size $size(myArray)
- Tcl [tcl]
array size myArray
Languages using "length" #
- ActionScript [actionscript]
myArray.length
- Ada [ada1] [ada2] [ada3]
myArray'Length
- C# [csharp1] [csharp2]
myArray.Length myArray.GetLength()
- CLIPS [clips1] [clips2]
(length$ ?myArray)
- Clojure [clojure1] [clojure2]
(alength myArray)
- CMake [cmake]
list(LENGTH myList n)
- Cobra [cobra1]
myArray.length
- ColdFusion [cfml]
ArrayLen(myArray)
- D [dlang]
myArray.length
- Dart [dart]
myList.length
- Emacs Lisp [emacs]
(length mySeq)
- Elixir [elixir]
length(myList)
- Elm [elm]
length(myArray)
- Erlang [erlang2]
length(myList)
- F# [fsharp]
myArray |> Array.Length myArray |> Array.length
- Flutter [flutter]
myList.length
- FoxPro [foxpro1] [foxpro2] [foxpro3]
ALEN(myArray)
- gawk [gawk]
length(myArray)
- GLSL [glsl]
myArray.length()
- Go [go]
len(myArray)
- Haskell [haskell]
length myList
- Java [java1] [java2]
myArray.length
- JavaScript / TypeScript / CoffeeScript / JScript [js]
myArray.length
- Julia [julia1] [julia2]
length(myArray)
- Mojo [mojo]
len(myList)
- Nim [nim1] [nim2]
len(myArray) myArray.len
- OCaml [ocaml1] [ocaml2]
Array.length myArray
- Odin [odin]
len(myArray)
- Pascal / Object Pascal / Delphi [pascal1] [pascal2]
Length(myArray)
- PostgreSQL [postgresql]
SELECT array_length(myArray, 1) FROM table;
- PostScript [postscript1] [postscript2] [postscript3]
myArray length
- PowerShell [ps1] [ps2]
$myArray.Length
- Prolog [prolog1] [prolog2]
length(myList, L)
- Python [python]
len(myList)
- R [r1] [r2] [r3]
length(myArray)
- Racket [racket]
(array-length myArray)
- Ring [ring]
Len(myList)
- Ruby [ruby1] [ruby4]
myArray.length
- Rust [rust]
myArray.len()
- Scala [scala]
myArray.length
- Scheme [scheme1] [scheme2]
(length myList) (vector-length myVector)
- Solidity [solidity1] [solidity2]
myArray.length
- Standard ML [std-ml]
Array.length myArray
- V [vlang]
myArray.len
- Vala [vala]
myArray.length[0]
- VHDL [vhdl1] [vhdl2]
myArray'LENGTH
- Vim script [vim]
len(myList) myList->len()
- Visual Basic [vb]
myArray.Length myArray.GetLength()
- Wolfram Language [wolfram]
Length[myArray]
- Zig [zig1] [zig2]
myArray.len
Languages using "count" #
- Clojure [clojure3]
(count myCollection)
- Cobra [cobra2]
myList.count
- Eiffel [eiffel]
myArray.count
- Hack [hack]
C\count($myArray)
- Logo [logo]
count :myArray
- PHP [php1]
count($myArray)
- PL/SQL [plsql1]
myTable.COUNT
- PowerShell [ps1]
$myArray.Count
- Ruby [ruby3] [ruby4]
myArray.count
- SQL [sql1] [sql2]
SELECT COUNT(*) FROM table;
- Swift [swift]
myArray.count
Languages using other words #
- ABAP [abap1] [abap2]
LINES(myTable)
- C++ [cpp4] [cpp5] [cpp6]
myVector.capacity() std::extent<decltype(myArray)>::value std::extent_v<decltype(myArray)>
- Common Lisp [common-lisp-2]
(array-dimension myArray 0)
- GAMS [gams1] [gams2]
card(mySet)
- GNU Make [gmake]
$(words $(myList))
- Lua [lua]
table.getn(myArray)
- Modula-2 [modula]
HIGH(myArray)+1
- PL/I [pli1] [pli2]
DIM(myArray,1)
- PL/SQL [plsql2]
CARDINALITY(myTab)
- Raku [raku]
@myArray.elems
- RPG [rpg]
%ELEM(myArray)
-
Simulink [simulink1] [simulink2]
Width block
- SAS [sas]
dim(myArray)
- X++ [xpp]
dimOf(myArray)
Languages using symbols #
- APL [apl]
⍴ myArray ≢ myArray
- Bash [bash]
${#myArray[@]}
- Icon [icon]
*myArray
- Korn Shell [korn1] [korn2]
${#myArray[*]} ${#myArray[@]}
- Perl [perl]
@myArray
- Shell script [sh]
$#
Languages where length is computed #
- AWK
n = 0; for (a in myArray) n++
- BASIC
n = 0 FOR i = 0 TO N ' assuming N as an upper limit for all arrays ON ERROR GOTO FoundLength temp = myArray(i) n = length + 1 NEXT i FoundLength:
- Batch files [batch]
set n=0 :Loop if define myArray[%n%] ( set /a n += 1 goto :Loop )
- C / C++ / Objective-C [n3369]
sizeof myArray / sizeof myArray[0]
- COBOL [cobol1] [cobol2] [cobol3]
COMPUTE n = LENGTH OF myArray / LENGTH OF myArray-element
- Makefile
N := `echo $(myList) | wc -w`
- Simula [simula]
upperbound(myArray,1) - lowerbound(myArray,1) + 1
- VBA / VBScript [vba] [vbscript]
UBound(myArray) - LBound(myArray) + 1
Languages where arrays are implemented by users #
- Forth
- TeX / LaTeX
Observations #
-
Some of the listed languages provide multiple ways of retrieving number of elements. Sometimes the ways are equivalent, but usually the underlying mechanism is different.
- e.g. Ruby has
.length
, but.count
without condition also gives the number of elements; - e.g. C++ allows to calculate array length via
sizeof arr / sizeof arr[0]
, by usingstd::size()
function, by passing the type tostd::extent_v<T>
trait template, and couple other ways.
If such additional method was not a primary or prominent way, or at least from the focus group, it might be missing from the list.
- e.g. Ruby has
-
The vast majority of languages use derivatives of either "length" or "size", with "length" being the dominat base.
-
"Length" and "size" are also often used for other linear data structures beside arrays, like strings, linked lists, queues, etc.
-
Documentations, specifications and communities use terms "length" and "size" quite freely and interchangeably in the meaning of "the number of elements in data structure". Sometimes languages make them alias one another.
- Other words also sometimes are seen as synonyms, although rarely and/or in specific contexts (e.g. "dimension" or "extent" would primarily be present when generalizing to multi-dimensional arrays).
-
"Count" is 3rd most popular choice, albeit significantly lesser number of languages represent this category. Sometimes it is a side effect of more versatile feature (e.g. in meaning "count of X in Y", where Y might contain more than just Xs).
-
4th most common word is "dimension"; 5th are ex aequo "elements" and "cardinality". Including methods of calculating number of elements puts "bounds" in top 5 too.
##