What's the difference between Low-level functions & Top-level functions?

The closer it is to human language, the higher-level the function is.

The closer it is to machine language, the lower-level the function is.

I'm simplyfying but here are some examples:

High level functions:

Car.Start()
Car.MoveTo(Home)

Low level functions:

Car.Insert(Key);
if (Car.IsKeyInserted() == False)
   return False;

Car.StartEngine();
Car.ApplyAccelerator(0.1f);
Car.ChangeGear();
Car.RotateWheel(-25);

When we talk about "high level" and "low level" in programming it's usually referring to the level of abstraction. A high level function is one which abstracts away the details, here's an example of a high level abstraction:

$('div#foo p').show('fast');

That snippet is from the jQuery JavaScript framework, it demonstrates a very complicated task but enables you to initiate it very easily. A lower level abstraction would be something like this:

$('div#foo p').animate({height: 'show', width: 'show', opacity: 1}, 200);

It's still jQuery but more details are being involved, it's lower level. Of course, you can get even lower:

animate(document.getElementById('foo').getElementsByTagName('p'), {
    height: 300, width: 600, opacity: 1, alphaFilter: 1
}, 200);

(using a custom built animate method)

Etc. etc.

The optimum level of abstraction is always under heavy debate. Going too high can cause an abstraction leak but going to low can be inefficient and a waste of time, especially if higher abstractions exist.


Top level function is a term that describes writing program code outside of sub or function. There are various levels from declaring stuff to actually running program code like vbs/jscript.

It normally discouraged or not allowed on languages that are expected to be complex. VB for instance only allows const and declares and dim. C# allows nothing top level.

We normally use higher level to describe the abstraction of a language.

In some languages the term will be top level method.

I remember reading this a long time ago.

http://blogs.msdn.com/b/ericlippert/archive/2009/06/22/why-doesn-t-c-implement-top-level-methods.aspx which links back to this site Why C# is not allowing non-member functions like C++