Array argument naming convention: upper case or lower case?

What is the official Julia convention for naming array arguments?

f(x::AbstractArray) # lower case? or
f(A::AbstractArray) # upper case / CamelCase?

I think the convention is lower case for argument names, CamelCase for type names. But in Julia Base I see many examples of both lower case and upper case array arguments. Just do methodswith(AbstractArray) to convince yourself.

Both exist in the wild. Use what you like.

Technically, upper case variable names do go against the style recommendations, but they are single-letter so they are fine visually.

Usually matrices are written with uppercase like A because it is a common notation in the literature. Unless there is a good reason, use lowercase.

1 Like

Thank you. I’ll go with that.

The way I name arguments is the lowercase first letter of the type (if it is specificied and unique) or a descriptive name otherwise.

1 Like

I’ve seen that a lot, but I dislike single character (esp. lowercase) variable names (although IMO i, j, k are fine for loop variables, as long as they stay strictly in the loop!).
If you are trying to search for that variable in a file, it’s a pain. It’s not so hard with uppercase ones, because there are usually a lot fewer uppercase characters in a file, and I’ve become used to the convention of using T and S for type variables in Julia.

So instead of s for a string, c for a character, l for length, I tend to use 3 letter abbreviations, such as str, chr, len. Short enough the code doesn’t become unwieldy, just long enough to be more mnemonic and easier to find.

In general I avoid any and all abbreviations. The reason I make exceptions for abbreviations from the type signature is that you can check to see what the variable stands for in the type signature itself.

1 Like