问题
Charles Simonyi introduced the idea of "organizing really big software teams by creating one super duper uber programmer writing the top-level functions, while handing off the implementation of the lower-level functions to a team of grunt junior-programmers as needed. They called this position program manager."
I want to know what are the Top-level functions, and how can I identify it? My language is Javascript. So far that's the only language I know hence please give me examples using JavaScript please.
BTW, the quote above is taken from Joel Spolsky. Check out his blog and read How to be a program manager.
Thanks
回答1:
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);
回答2:
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.
回答3:
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++
回答4:
This refers to how far down the call stack the function is located. When a program starts, the operating system calls the main() or top level, which consists of calls to the next lower level functions. Each in turn calls other functions to do more basic tasks, which end up calling functions in operating system eg to open a file. The low level functions are the functions in your program which don't call any other functions that you have written (but use the operating system or framework to compute their results etc).
回答5:
Simple question could be answered in just a few words but the underlying subject covers entire books. However is is not related to Javascript per say, just that Javascript could be used to create the functions.
Mr Valdez is right though.. it all depends on the level of abstraction your function defines.
There are other approach to software desing and architecture look em up
This one has a section that answer your question quite nicely
This page discuss the subject with a broader perspective
回答6:
In reality there are only higher or lower-level functions.
function higherlevel(){
foo
.init() // aha, this is daisychained
.loadFromDatabase() // gotcha
.render() // makes sense
.logProgress() // right.
}
function render(){ // lowerlevel
// if
// while
// for
// throw/catch
// _.get(foo,'bar.flop')
return foo
}
Daisychaining functions in JS can easily by identified as higher/lower-level functions.
Private,Protected class-methods and/or underscore-functions can be identified as lower-level functions.
Functions living in the global scope can be identified as top-level functions. They can be lowerlevel (window.querySelector(..) e.g. operating on DOM) or higherlevel (window.close())
来源:https://stackoverflow.com/questions/633617/i-want-to-know-the-difference-between-low-level-functions-top-level-functions