Alter comments query to order by DESC

Drupal ordinary comment listing under nodes are ordered earliest first.(created ASC)
If you need to make it DESC, without using views:

<?php
/* Implements hook_query_TAG_alter().
https://www.drupal.org/node/1095656#comment-7885467
* * Alter comments query to order by DESC as well as the default ASC. */
function CUSTOM_query_comment_filter_alter(QueryAlterableInterface $query) {
 
$orderby = &$query->getOrderBy(); 
 
$expressions = &$query->getExpressions(); 
 
// Sorting for threaded comments.
 
if (isset($orderby['torder'])) {  
   
// Get rid of the expressions that prepare the threads for ASC ordering.
    // Simply order by the thread field.
     
   
unset($expressions['torder']);
    unset(
$orderby['torder']);
   
$orderby['c.thread'] = 'DESC';  
        
      
  }else{ 
// Sorting for flat comments.  
   
$direction = 'DESC';
    if (isset(
$orderby['c.cid'])) {
      unset(
$orderby['c.cid']);   
    }
   
$orderby['c.created'] = $direction;
   
$orderby['c.cid'] = $direction;
  }
}
?>

Surprisingly complex. Maybe should just use views...

Google