Should I call my function in Drupal custom modules? I've been trying to implement  a redirect to user register page if an anonymous user tries to access a specific page. I used the following code in my custom module.

function myregistration_init(){
  global $user;
  if ($user-&gt;uid == 0  &amp;&amp; $_GET['q'] == 'order_translaton' ) {
    drupal_goto('user/register');
  }
}


However, this code did not work until I wrote myregistration_init() after the function body. I know that in Drupal modules function works automatically without the need to call it. For instance, the following code works without function call:

function myregistration_form_user_register_form_alter(&amp;$form,&amp;$form_state){
$form['#submit'][] = 'myregistration_submit';
function myregistration_submit(&amp;$form,&amp;$form_state) {
$form_state['redirect']= 'order_translaton';
}
}


Please explain how all this works in Drupal modules.
Do not get confused with drupal hooks and functions.

Drupal Hooks:

They allow you to interact with core functionality without hacking it. In our custom module we implement hooks which are invoked by drupal at the event the hook is exposed for automatically. So consider the hook_init(), so when drupal is initialized the system will look inside each contributed, custom module if any of the module has implemented hook_init(), and if so, drupal will invoke functionality written inside the hook implementation for every single module in the order of their module weight.Basically all we do is implement the hook in custom module and clear the caches (clearing the caches is important step as drupal caches all hook implementations so that it doesn't have to look inside every enabled module files to find if there is a matching hook implementation in order to be executed, but since a new hook is added to system we have to clear the cache so that drupal can rebuild information about implemented hooks.), we never explicitly call the hooks, as they are invoked by drupal system itself. 
So hooks are kind of functions invoked by drupal itself.

functions:

Set of code which gets executed when called explicitly.

About your code

  /**
    * Implements hook_init()
    */
    function myregistration_init(){
      global $user;
      if ($user-&gt;uid == 0  &amp;&amp; $_GET['q'] == 'order_translaton' ) {
        drupal_goto('user/register');
      }
    }


About your code:

function myregistration_form_user_register_form_alter(&amp;$form,&amp;$form_state){
  $form['#submit'][] = 'myregistration_submit';
  function myregistration_submit(&amp;$form,&amp;$form_state) {
    $form_state['redirect']= 'order_translaton';
  }
}


I am not sure why this code is working, it should be rather like following.

/**
  * Implements hook_form_alter()
  */
function myregistration_form_user_register_form_alter(&amp;$form,&amp;$form_state){
  $form['#submit'][] = 'myregistration_submit';
}

/**
  * Custom submit hanlder.
  */
function myregistration_submit(&amp;$form,&amp;$form_state) {
  $form_state['redirect']= 'order_translaton';
}


Both hook implementation codes above should work, but you might need to clear your caches after implementing the code. But do not call it explicitly anywhere in code.