2
$\begingroup$

I was wondering if there are any resources for a study/ranking of the most frequently used statements (by statements I mean assigning, invoking, instantiating etc, like in C#) in programming overall (or at least for one modern language).

This is for a private research project where I am writing my own bytecode assembler and compiler for a custom language.

For example, the C#-code:

int a = 0;
int b = a * 2;
DoSomething(a, b);

would have 2 assignments and 1 function call.

So I'm wondering is there any study or somethig similar, regarding the usage frequency of statement types in general?

thx in advance

$\endgroup$
1
  • 1
    $\begingroup$ In C++ programming, i++; is the most used statement :-) Seriously, who cares? $\endgroup$
    – gnasher729
    Nov 3 '20 at 21:47
2
$\begingroup$

I don't know about statement types, but there's been a lot of research over the decades about CPU instruction frequency and how it impacts ISA design, IR design, and VM design... but it's all for languages like C. See, for example, loads/stores/branch frequencies for the SPEC2017 benchmarks.

If your language is C-like, there are basically only two reasons to compile to a virtual machine:

  • The goal is portability and/or optimisation convenience, in which case it is an intermediate representation on the way to generating code for a real machine.
  • The goal is some unusual performance constraint, such as extremely fast compilation, or for the generated code to be as tiny as possible.

In managed/interpreted languages, the main considerations are:

  • If the VM code is also a distribution format (e.g. JVM or DotNET), size may be a factor.
  • When interpreting, maximising the amount of "actual computation" (as opposed to interpreter overhead) performed for each interpreted instruction.
  • When compiling (whether AoT or JIT), preserve as much of the relevant semantics of the source language as is needed for efficient optimisation, and discard (as far as possible) as much of the irrelevant semantics as possible.

Examples of that last point: Preserving basic types (integers, floats) is much more important than preserving non-basic types (structs, objects). Preserving the distinction between static calls and dynamic calls in OO languages is also extremely important.

I suspect that a reason why there isn't as much general research on object-oriented, managed, non-C-like languages (calling them "modern" is arguably misleading!) is because specific libraries and frameworks tend to dictate the style of programming that programmers do.

For C# specifically, if such information has been collected, it seems unlikely that Microsoft is telling anyone.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.