News for hackers. Stuff that matters.
Re:A Dictionary of Single-Letter Variable Names by dvt on Sunday October 13, 2024 @05:05PM (#41831584)
I know this is mostly for Haskell, but I would add (used in various languages):

    e: event
    k: key in hash map, dictionary, etc.
    o: object or reflected object types
    v: value in hash map, dictionary, etc.
    t, u, v, w: vectors (borrowed from math)
Would be fun to think about this for a while and come up with a more serious dictionary with examples and links to code.
Re:A Dictionary of Single-Letter Variable Names by larodi on Sunday October 13, 2024 @05:11PM (#41831639)
How come are this specific for Haskell and not universal?

My errors are caught as ‘e’, files are ‘f’, apparently indices are i, j, k, for as long as people been writing C.

K/V are keys and values, and, well, ‘t’ is time. I’m sure you can guess all other…

I really don’t understand how is this a specific language’s thing.

Re:A Dictionary of Single-Letter Variable Names by _jackdk_ on Sunday October 13, 2024 @08:19PM (#41832943)
(Author here.)

I think the amount of polymorphic code Haskell enables means that single-letter variables are more common than in other languages (where they're usually confined to narrow scopes), and there's a lot less to say about them. Another HN commenter on this post mentioned IEnumerable<T>, which is very similar: you know nothing about T, but you need to call it _something_, and there's a common understanding in the community that you call such type variables <T>.

Haskell's typeclasses then mean you've got a lot of different concepts that could show up in a type signature, but they're still polymorphic and there's not much you _can_ say beyond "this is Foldable", or "this is a Monad". So an even broader convention has emerged.

Re:A Dictionary of Single-Letter Variable Names by Sebb767 on Monday October 14, 2024 @11:09AM (#41838262)
> Another HN commenter on this post mentioned IEnumerable<T>, which is very similar: you know nothing about T, but you need to call it _something_, and there's a common understanding in the community that you call such type variables <T>.

You know that it's the type you enumerate over. I'd agree that in this case, <T> is sufficiently common language that people understand the reference (similar to how i is understood to be the index counter in a for loop), but you could definitely use a more expressive type name [1]. This becomes important if your type has two or three generic parameters.

[1] You might argue that this is more typing overhead, but your tooling will easily auto-complete it for you or refactor it after you've written the code, but before committing it. And if you don't have that type of tooling, you're in need of expressive variable names.

Re:A Dictionary of Single-Letter Variable Names by larodi on Tuesday October 15, 2024 @03:51AM (#41845981)
Well apparently because T stands for template or type, but people also use K and P here, all capitals. And again - ‘T’ for type is not unique to C++.
Re:A Dictionary of Single-Letter Variable Names by dvt on Sunday October 13, 2024 @05:20PM (#41831716)
> How come are this specific for Haskell and not universal?

The author says as much. There's overlap for sure, but all the monad stuff, for one, is mostly Haskell-(or functional language rather)-specific.

Re:A Dictionary of Single-Letter Variable Names by PaulHoule on Sunday October 13, 2024 @05:32PM (#41831806)
People used I,J,K,L for integers in FORTRAN and BASIC for that matter, in fact early FORTRAN determined the type based on the first letter of the name.
Re:A Dictionary of Single-Letter Variable Names by kergonath on Sunday October 13, 2024 @06:23PM (#41832227)
GOD is REAL except if declared otherwise :)
Re:A Dictionary of Single-Letter Variable Names by runeblaze on Sunday October 13, 2024 @11:53PM (#41834028)
Half jokingly if `s, t, a, b` ever becomes universal then either we all ascended to purity heaven or a mass extinction on the scale of K-Pg extinction occurred and wiped out most of earth's programming languages.
Re:A Dictionary of Single-Letter Variable Names by jonathrg on Sunday October 13, 2024 @05:42PM (#41831894)
a is for array

b is for byte or buffer

c is for character

d is for destination

e is for event or error

f is for file

g is for graph

h is for handle

i is for index

j is also for index

k is for key

l is for length

m is for mode

n is for number-of

o is for object

p is for part

q is for queue or query

r is for reader

s is for source

t is for time

u is for user

v is for value

w is for word

x is for x component

y is for y component

z is for z component

Re:A Dictionary of Single-Letter Variable Names by RheingoldRiver on Sunday October 13, 2024 @06:33PM (#41832313)
A is for Array:

A is for array, some things in a list

B is for byte, how computers exist

C is for character, one letter in a word

D is for destination, where results are stored

E is for event, interaction in the DOM

F is for file, sometimes written to ROM

G is for graph, some edges and nodes

H is for handle, it references loads

I is for index, add 1 as time flies

J is for index, but different from i's

K is for key, in associative arrays

L is for length, as in how many j?

M is for mode, and not like ice cream

N is for count, like sheep in a dream

O is for object, some data and code

P is for part, to share out the load

Q is for queue, process one at a time

R is for reader, I can't think of a rhyme

S is for source, and you're doing great

T is for time, 429 makes you wait

U is for user, like you'll be one day

V is for value, associated to k

W is for word, collections of c

X is for x-component when doing 3D

Y is for y-component like x is again

Z is for z-component, we got to the end!

[note, i am not sure what is meant by P = part, and I know some of these are kind of lame and got worse as I got impatient to finish]

[i wrote this myself, it is not ai-written]

Re:A Dictionary of Single-Letter Variable Names by sitkack on Monday October 14, 2024 @12:37PM (#41839164)
NL is for not for long
Re:A Dictionary of Single-Letter Variable Names by _jackdk_ on Sunday October 13, 2024 @08:13PM (#41832914)
Good catch, I'd forgotten "reader" (as in `ReaderT`). Thanks.
Re:A Dictionary of Single-Letter Variable Names by rphln on Sunday October 13, 2024 @06:04PM (#41832092)
Would've been perfect had you said jndex.
Re:A Dictionary of Single-Letter Variable Names by jonathrg on Monday October 14, 2024 @03:14AM (#41835020)
I'm so sorry
Re:A Dictionary of Single-Letter Variable Names by sph on Tuesday October 15, 2024 @06:32AM (#41847086)
Also r: Reader and w: Writer, especially in languages with such generic interfaces (Rust, Go)