The difference is that the first is a controller inside the module.
The second method is a controller on the global ( on the Window object! ).
Like you would have heard already, polluting the global object is a bad idea. Hence, the second method is not preferred (But is used for quick prototyping to show off a feature easily and is easier to type. So this one is used in pretty much all examples.)
The first way, i.e
angular.module('myApp.controllers',[])
.controller('MainCtrl', ['$scope'], function($scope){
//controller code
}
is the preferred way and should be used in all for production applications.