Answering How Many with Software

How many? is a typical question that comes up when programming. I use a variety of software for projects and there are subtly different ways to answer that question depending on the context.

Here is an alphabetical list of ways I’ve recently answered that question. A more detailed comparison of programming languages can be found on Wikipedia.

Command Line

# How many rows are in this file?
wc -l < file

Golang

// How many elements are in this array?
len(array)

JavaScript

// How many elements are in this array?
array.length

// How many elements in this array are greater than 5?
d3.count(array, (d) => d > 5)

// How many rows are in this Apache Arrow table?
table.numRows

Liquid Tags in Jekyll

<!-- How many elements are in this array? -->
array | size

Python

# How many elements are in this list?
len(list)

# How many elements are in this pandas dataframe?
df.size # including missing values
df.count() # excluding missing values

# How many elements are in this numpy array?
ndarray.size

Ruby

# How many elements are in this array?
array.length
array.count
array.size

# How many rows are in this Active Record table?
table.count

SQL

-- How many elements are in this PostgreSQL array?
array_length(array, 1)

-- How many elements are in this DuckDB list?
len(list)

-- How many rows are in this table?
select count(*) from table

Terraform

# How many elements are in this list?
length(list)
 

May 31, 2024