Traditional programming could be done quite readable. Like this:FUNCTION do_HTTP_request(url) {    if(!ask_user_if_he_wants_to_connect()) return;    if(!network_is_enabled()){        enable_network();    }    var content = download(url);    //  do something with content}However, nowerdays frameworks are rich in callbacks. This splits up the above lines over various fuctions:var listener;var url;FUNCTION async_completed(content) {    switch (content.which) {        case async_http.SUCCESS:            //  do something with content        case bar.CLOSED:            // unrelated stuff        case bar.LAST_ORDER:            // unrelated stuff        case bar.OPENED:            // unrelated stuff        case foo.SUCCESS:            // unrelated stuff    }}FUNCTION async_progress(progress) {    // unused, but must be there to satisfy the compiler}// 8 unrelated functions between a and dFUNCTION do_HTTP_request(url) {    this.url = url;    ask_user_if_he_wants_to_connect();}FUNCTION do_the_request() {    new async_http(url).execute();}FUNCTION enabled() {    remove_listener(listener);    do_the_request();}// 26 unrelated functions between e and oFUNCTION on_OK_button_press() {    if(network_is_enabled()) do_the_request();        else {            enable_network();            listener = new network_enabled_listener(this);            set_listener(listener);        }}In separate class (file / editor window) network_enabled_listener:FUNCTION on_receive(data) {    if(enabled in data) my_main.enabled();}This code is far more complex and totally obfuscates the control flow, which is merely the same as the first code block. Are there good programming practices, design patterns, or code style recommendations that target the challenge to reveal the control flow in code that is rich in callbacks?
How to clarify the control flow when dealing with many callbacks?
design patterns;programming practices;coding style;callbacks