I noticed in the example on page 33 (boj-random-blog-posts.php below) that the function boj_randomly_order_blog_posts is called BEFORE it is defined. The function is defined immediately after the line that invokes it in the add_action hook. I am new to PHP (obviously

), but I do know that in other languages the function must be defined before they are called.
Is this allowed in PHP? If so, what is the best practice regarding this?

Is it better to go one way or the other?
Example from book:
<?php
add_action( 'pre_get_posts', 'boj_randomly_order_blog_posts' );
function boj_randomly_order_blog_posts( $query ) {
if ( $query->is_home && empty( $query->query_vars['suppress_filters'] ) )
$query->set( 'orderby', 'rand' );
}
?>