Why do many functions now require more code than the equivalent functions of the previous version? Every time I read about how to convert code from D7 to D8 is seems like the D8 version is longer.

For example drupal_goto was:

drupal_goto('user');


and the D8 equivalent is: 

return new RedirectResponse(\Drupal::url('user.page'));


And an example hook_init in D7:

function mymodule_init() {
  if (!empty($_GET['redirect-me'])) {
    drupal_goto('http://example.com/');
  }
}


And the equivalent is D8 is:

mymodule.services.yml

services:
  mymodule_event_subscriber:
    class: Drupal\mymodule\EventSubscriber\MymoduleSubscriber
    tags:
      - {name: event_subscriber}


and then also:

namespace Drupal\mymodule\EventSubscriber;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class MymoduleSubscriber implements EventSubscriberInterface {
  public function checkForRedirection(GetResponseEvent $event) {
    if ($event-&gt;getRequest()-&gt;query-&gt;get('redirect-me')) {
      $event-&gt;setResponse(new RedirectResponse('http://example.com/'));
    }
  }
  /**
   * {@inheritdoc}
   */
  static function getSubscribedEvents() {
    $events[KernelEvents::REQUEST][] = array('checkForRedirection');
    return $events;
  }
}


This is only a couple of examples but it seems that to achieve anything is D8 is going to take far more code.


Is this actually the case or am I misinterpreting whats happening.
If this is the case then what is the advantage?
Would it be possible / desirable to use lots of wrapper functions to reduce the amount of code to achieve simple tasks?
Is this actually the case or am I misinterpreting whats happening.


Yep, a lot of D8 stuff is more verbose than that of its predecessor. A huge chunk of the codebase has moved to OO based on PSR-0, so you're always going to be writing more code, more files, creating more folders to put those files in, etc.


  If this is the case then what is the advantage?


You can't directly apply an 'advantage' or 'disadvantage' to the concept of "D8 will use more code" (if that's indeed even true when you average it all out); it's simply an inevitability - the D8 page request has completely changed with the introduction of Symfony, so what was possible in a few lines in D7 just isn't possible with the same code now. The overall advantage is that Drupal gets all the power of Symfony driving it, and Symfony's framework/request lifecycle is generally considered to be stable and to use good practice. Plus, introducing a strict DI methodology to any kind of project is a big win in my opinion.


  Would it be possible / desirable to use lots of wrapper functions to reduce the amount of code to achieve simple tasks?


Possible? Of course. Desirable? Depends on your opinion, and what you're creating a wrapper for. If it's something you do 10 times a day, and you can shorten 10 lines to 1 or 2 lines, then you'd be mad not to do it. Obviously that attitude transcends Drupal/PHP and should apply to any language/technology.


  This is only a couple of examples but it seems that to achieve anything is D8 is going to take far more code.


The anything there isn't true - some things will be more verbose, some things less, it depends on exactly what you're looking to do.