Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Frequency of symbols in programming languages

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.

like image 779
Senseful Avatar asked Aug 06 '10 06:08

Senseful


People also ask

What is character frequency?

Freq will be used to maintain the count of each character present in the string. Now, iterate through the string to compare each character with rest of the string. Increment the count of corresponding element in freq. Finally, iterate through freq to display the frequencies of characters.

What programming language uses symbols?

The correct answer is Assembly Language. Assembly language uses symbols to represent binary codes of machine-level instructions. The symbols (mnemonics) in Assembly Language are used to represent binary codes that are used in machine language (the most fundamental form of programming languages).

How do you find the frequency of a letter in C++?

The code snippet for this is given as follows. for(int i = 0; str[i] != '\0'; i++) { if(str[i] == c) count++; } cout<<"Frequency of alphabet "<<c<<" in the string is "<<count; The program to find the frequency of all the alphabets in the string is given as follows.

Why are symbols used in coding?

A symbol in computer programming is a primitive data type whose instances have a unique human-readable form. Symbols can be used as identifiers. In some programming languages, they are called atoms. Uniqueness is enforced by holding them in a symbol table.


2 Answers

For large code samples to use for statistical analysis, you might try browsing popular open-source projects or searching on Koders by language.

I made some simple changes to a QWERTY layout a few years ago, and I've been using it ever since as my general-purpose layout:

  • Swap digits for their corresponding shift-symbols.
  • Swap _ and -: names with underscores are common, and now - and + both require Shift.
  • Swap [] and {}: blocks are more common than subscripts.

Plus two optional changes, to taste:

  • Swap ` and ~: destructors are common.
  • Swap ' and ": strings are more common than characters.

The last is the only one that typically would interfere with typing ordinary English text. The layout works beautifully for C++, Perl, and whatever else I've used in the past two or three years. The noticeable speed increase comes from the drastic reduction in the need to hit the Shift key. I find that using Shift for the numbers isn't a big deal since the number pad is usually faster anyway.

like image 98
Jon Purdy Avatar answered Oct 29 '22 21:10

Jon Purdy


The book The New C Standard: An economic and cultural commentary contains a lot of measurements of C source usage. The usage figures and tables are available as a stand-alone pdf

like image 28
Derek Jones Avatar answered Oct 29 '22 21:10

Derek Jones