News for hackers. Stuff that matters.
Re:Go 1.27 Interactive Tour by adrianmsmith on Sunday August 02, 2026 @03:33AM (#49142010)
I never understood the convention of using single letter names for generic parameters. I guess this started in C++ and every language has copied that convention.

I think that code would be a lot easier to read if the types were called IN and OUT or In and Out or TIn and TOut or something like that.

Re:Go 1.27 Interactive Tour by spockz on Sunday August 02, 2026 @04:04AM (#49142159)
Completely agree and I personally name generic type parameters as I would name types and parameters. It helps a lot.
Re:Go 1.27 Interactive Tour by jiehong on Sunday August 02, 2026 @03:52AM (#49142109)
We all know letters are expensive ^^
Re:Go 1.27 Interactive Tour by phplovesong on Sunday August 02, 2026 @04:02AM (#49142155)
Im pretty sure it came from the MLs, where you usually have a/b/c instrad of the T,U etc combo.

I dont find it confusing, as its pretty clear that it only an placeholder.

In generics the name usually does not matter or is REALLY hard to name so that it makes sense.

More specifically in Go where you have interfaces, concrete types and generics.

Re:Go 1.27 Interactive Tour by asQuirreL on Sunday August 02, 2026 @04:36AM (#49142359)
Fairly sure it would predate even that, and go all the way to lambda calculus, and predicate logic before that, and that's where my knowledge stops and somebody else can tell us where the current conventions around variables in logic and mathematics come from.
Re:Go 1.27 Interactive Tour by teh64 on Sunday August 02, 2026 @06:37AM (#49143120)
In ocaml (and I assume SML) it helps that the generic types have a `'` before them, so

    val map : ('a Box) -> ('a -> 'b) -> 'b Box
Re:Go 1.27 Interactive Tour by Someone on Sunday August 02, 2026 @04:46AM (#49142444)
For maps, a convention is to use K and V for key, respectively Value.

I think that’s best as you’ll soon learn the “single-character capital letter ⇒ generic parameter” convention

Re:Go 1.27 Interactive Tour by Laurel1234 on Sunday August 02, 2026 @05:15AM (#49142620)
In C# this is the convention.
Re:Go 1.27 Interactive Tour by eterm on Sunday August 02, 2026 @09:33AM (#49144560)
It's a mix, because some stuff tends to just use `T`, but there's better descriptors elsewhere.

There's IList<T> but Task<TResult>

There's Action<T1, T2, T3, T4, T5, T6> but also Dictionary<TKey, TValue> and Map<TIn, TOut>

This stuff kind of "makes sense" once you're used to it, because it's difficult to say what IList<T> ought to have been called otherwise, IList<TContainee> is a mouthful, and Action<T1,...> simply suffers from the inability to specify an unknown number of generic parameters.

https://learn.microsoft.com/en-us/dotnet/api/system.collecti...

https://learn.microsoft.com/en-us/dotnet/api/system.action-2...

https://learn.microsoft.com/en-us/dotnet/api/system.collecti...

Re:Go 1.27 Interactive Tour by setopt on Sunday August 02, 2026 @05:25AM (#49142671)
I believe Haskell did that for decades before C++.
Re:Go 1.27 Interactive Tour by logicchains on Sunday August 02, 2026 @06:09AM (#49142938)
Haskell was created in 1990, five years after C++.
Re:Go 1.27 Interactive Tour by hnlmorg on Sunday August 02, 2026 @06:25AM (#49143054)
Haskell had generics from the beginning. Whereas C++ only added templates to its specification in 1998.
Re:Go 1.27 Interactive Tour by jahnu on Sunday August 02, 2026 @10:03AM (#49144820)
I was using the STL in 1994 with Zortech C++
Re:Go 1.27 Interactive Tour by zerr on Sunday August 02, 2026 @10:57AM (#49145252)
Miranda had it since its release in 1985.
Re:Go 1.27 Interactive Tour by toinebeg on Sunday August 02, 2026 @05:58AM (#49142857)
I often use whole word for type annotation, when I can find meaningfull ones. I just type them in all caps to stay close to the convention.

I guess the single letter thing is laziness for a part. It's not simple to find words that represent the abstract idea behind the generic type without narrowing the possibilities. For array function, the Key Value from the sibling comment work but for more complex use case, it get complicated.

Re:Go 1.27 Interactive Tour by wwalexander on Sunday August 02, 2026 @07:21AM (#49143396)
Swift generics tend to idiomatically use longer names, like Element or View or Content.
Re:Go 1.27 Interactive Tour by girvo on Sunday August 02, 2026 @07:49AM (#49143589)
I’ve always done that in my typescript code bases too, and I’ve never regretted it
Re:Go 1.27 Interactive Tour by fooooor on Sunday August 02, 2026 @10:50AM (#49145192)
Lambdas usually have short variable names because the scope is small, typically half a line. And that is fine, even optimal.
Re:Go 1.27 Interactive Tour by fooooor on Sunday August 02, 2026 @10:40AM (#49145107)
What could be more idiomatic than:

for (int i=0; i<10; i++) { printf(”%d\n”, i); }

(Or the very similar Go equivalent)

If you having a hard time parsing that, due to the short variable name, i.e. if it’s a huge cognitive load for you, I suggest you switch career, b/c the IT industry is obviously not a good fit.

With that said, Go is explicit with suggesting short variable names for small scopes, and long variable names for bigger scopes. This a good practice in all languages.

Re:Go 1.27 Interactive Tour by majewsky on Monday August 03, 2026 @05:03AM (#49153106)
I'm not necessarily disagreeing, but I'm following the single-letter convention because "TIn" or "InputType" looks too much like an exported symbol. Whenever I tried to write type arguments like that, this threw me off, so I reverted to single letters.