Axel Stone
Axel Stone

Reputation: 1580

Should I call these functions "procedures"?

I've made a plugin for Google Chrome. It is a scripting tool for browser automatization - it executes instructions defined in javascript file and click on links, fills forms and so on..

The simple example of script with instructions looks like this:

function tron_main(step) {

  switch (step) {

    case 0:
      tron_visit('http://www.example.com');
      break;

    case 1:
      tron_click('#login-button');    
      break;

    case 2:    
      tron_fill('#login-form input.username', 'admin', 1);
      tron_fill('#login-form input.password', 'password123', 1);
      tron_click('#login-form input[type="submit"]', 1);    
      break;

    case 3:    
      tron_end('End of TRON, we should be logged in').    
      break;

  }
}

It opens an url, then clicks on login button, then fill and submit login form.

There is also possibility to use "secondary functions" (as I call it for now) for repetitive tasks - something like procedures, subroutines, that contains ther own set of instructions.

Example of use of these "secondary functions":

function tron_main(step) { 
    ...
    case 3:
      // execute secondary function tron_log_me_in()
      tron_execute('tron_log_me_in');
      break;
    ...
}

// our secondary function
function tron_log_me_in(step) {    
  switch (step) {

    case 0:    
      tron_click('#login-button');    
      break;

    case 1:
      tron_fill('#login-form input.username', 'admin', 1);
      tron_fill('#login-form input.password', 'password123', 1);
      tron_click('#login-form input[type="submit"]', 1);
      break;

    case 2:
      // terminate secondary function and return to tron_main() function           
      tron_return();    
      break;

  }
}

My question is that is it correct to call those secondary functions "PROCEDURES" since it does not return any values and only performs a set of instructions? Even if it is actually a javascript function? Or are there more suitable naming conventions for such a "constructions"?


Full documentation for more details: http://automatron.activit.sk

Upvotes: 0

Views: 28

Answers (1)

gbr
gbr

Reputation: 1302

Some languages do distinguish between procedures, which don't return values, and functions, which do, and mathematically speaking it would even be incorrect to call something that doesn't return a value a function.

However most languages call everything "function" and it's been so for more than 50 years, so no one is going to rectify you if you call a subroutine that doesn't return a value "function", at least when speaking about code written in a language that has only functions such as javascript.


By the way the naming-conventions tag is most likely inappropriate, that is used for questions about how to name stuff in the actual code, which doesn't seem the case here.

Upvotes: 1

Related Questions