abbrcode / abbreviations-in-code

The list of common abbreviations in program codes.
https://abbreviations-in-code.vercel.app
MIT License
426 stars 52 forks source link

Add 'chr' to character #17

Closed Firemanarg closed 1 year ago

kisvegabor commented 1 year ago

I think we should pick either chr or char to have a clear recommendation for character.

@philipeachille @T1xx1
What do you think?

T1xx1 commented 1 year ago

I agree and I think "char" is better. In programming languages like C# or Typescript when defining a character is char x = ect... So we should pick that one. Also consider that "chr" or "char" are not that different so using "char" is not such a big deal.

h-h-h-h commented 1 year ago

I've also seen ch in code. This is also part of the famous getch().

Firemanarg commented 1 year ago

But using 'char' in some languages is a reserved word. In C or C++ for example, you just can't declare a char variable called 'char', because it is a type name.

kisvegabor commented 1 year ago

I've also seen ch in code. This is also part of the famous getch().

I think the naming in C is not that consistent. getch is a good example:

char x = getch();

What was the intention in C to abbreviate character? char or ch?

IMO ch is too short and it could mean channel too. E.g. if I saw a variable like ch_index I could assume channel_index or character_index too.

But using 'char' in some languages is a reserved word. In C or C++ for example, you just can't declare a char variable called 'char', because it is a type name.

But you can use it in function names, like: find_char.

h-h-h-h commented 1 year ago

@kisvegabor: You're onto something. Reading your variable name examples, I also think the part ch would rather be pronounced as the beginning of "channel" and not as the first sound of "character". So, in this sense, having it abbreviating "character" is less intuitive. However, having a solution for the problem where you would like to name a variable char, but can't, would still be desirable. Instead of naming a variable string, you can name it text; but that's about multiple characters in one variable.

BTW, "chan" in "4chan" means "channel", so there's another abbreviation for "channel".

kisvegabor commented 1 year ago

However, having a solution for the problem where you would like to name a variable char, but can't, would still be desirable. Instead of naming a variable string, you can name it text; but that's about multiple characters in one variable.

char is not working only if you use as it is. E.g. char_index or last_char is fine. As the name char on it's own could mean a lot of things it's unlikely that it will be used in a larger context (e.g. as a global variable name). In smaller contexts (e.g. in an if) I usually use c. Probably it lives only in a few lines so it's easy to remember what it is.

BTW, "chan" in "4chan" means "channel", so there's another abbreviation for "channel".

IMO chan doesn't make channel that much shorter. On instruments I usually see ch1, ch2, etc. image

T1xx1 commented 1 year ago

So it's better using 'char' for character and 'ch' for channel.

I've checked and after this discussion I think we have to change the channel circle to green because right now is yellow.

kisvegabor commented 1 year ago

I've checked and after this discussion I think we have to change the channel circle to green because right now is yellow.

I agree.

philipeachille commented 1 year ago

"So it's better using 'char' for character and 'ch' for channel." I also agree

kisvegabor commented 1 year ago

I close this PR. Thank you for the contribution.

kisvegabor commented 1 year ago

Ups, I forgot to click the Close button. :slightly_smiling_face: