Frequency of symbols in programming languages

Viewed 5298

I'm looking for some kind of reference which shows the frequency of symbols of popular programming languages. I'm trying to design an optimal keyboard layout for programming.

If there is no such reference, I wouldn't mind creating a simple utility that figures this out. However, I would need suggestions as to which files to analyze for each language.

One of the problems I can foresee is say I get some objective-c code, if it is a simple program with no objects, then the [ and ] keys will be far less frequent than an average objective-c file. So, I would say one of the guidelines is that the sample code should be representative of an average file and use the most commonly used features of the language.

Originally I was thinking that I should get the same code written in different languages, but I'm not sure if that's a good idea since some languages have different uses than others.

6 Answers

@Derek Jones cited The New C Standard: An economic and cultural commentary which has the information but here are the frequencies contained therein for quick reference:

space 15.083
! 0.102
" 0.376
# 0.175
$ 0.005
% 0.105
# 0.175
& 0.237
' 0.101
( 1.372
) 1.373
* 1.769
+ 0.182
, 1.565
- 1.176
. 1.512
/ 0.718
: 0.192
; 1.276
< 0.118
= 1.039
> 0.587
? 0.022
@ 0.009
[ 0.163
\ 0.97
] 0.163
^ 0.003
_ 2.550
{ 0.303
| 0.098
} 0.210
~ 0.002

Here is the same sorted by frequency:

space 15.083
_ 2.550
* 1.769
, 1.565
. 1.512
) 1.373
( 1.372
; 1.276
- 1.176
= 1.039
/ 0.718
> 0.587
" 0.376
{ 0.303
& 0.237
} 0.210
: 0.192
+ 0.182
# 0.175
# 0.175
] 0.163
[ 0.163
< 0.118
% 0.105
! 0.102
' 0.101
| 0.098
? 0.022
@ 0.009
$ 0.005
^ 0.003
~ 0.002
Related