Magento 1: why some observer method call getEvent() and some don't?

One thing is clear.

Calling $observer->getEvent()->getSomething() and $observer->getSomething() return the same thing.

Take a look at the Mage_Core_Model_App::dispatchEvent method.

At one point you have $event = new Varien_Event($args); where $args are the arguments passed to the dispatchEvent method.
And Varien_Event extends Varien_Object so you can magically access the elements in $args from the Varien_Event instance.

but there is also this line $observer->addData($args); where $args are the same things as above.

Varien_Event_Observer also extends Varien_Object so this allows you to magically access elements in $args via the Observer object.

Conclusion:

The $_data member in the Observer class and Event class contain kind of the same things. The observer has in addition a few other fields. like event, event_name.

Let's say the $args look like this:

array(
   'some_arg' => 'someArg',
   'other_arg' => 'otherArg',
)

When dispatching the event, the $_data in the Event object would look like this:

array(
   'some_arg' => 'someArg',
   'other_arg' => 'otherArg',
   'name' => 'event name here'
)

and in the Observer class would looks like this:

array(
   'some_arg' => 'someArg',
   'other_arg' => 'otherArg',
   'event_name' => 'event name here',
   'event' => instance of Varien_event,
   'callback' => ..., 
   'name' => 'observer name here'
)

But I cannot answer to why this lack of consistency exists.
I can only speculate that the code was written by 2 different developers.
If it's worth something, I always use $observer->getEvent()->getSomething().

[EDIT]

Why is the getEvent() method called in example #1 ? Or why is getEvent() not called in example #2 ?

Lack of consistency

What's the purpose of the getEvent() method ?

The Varien_Event object should be a wrapper object over the arguments passed to the observer

Where should one use getEvent() and where shouldn't one use it ? Use them as you like. You will get the same result all the time.


It probably has historical reasons, reaching back beyond the 1.0 release.

The Varien_Event object is the logical place to contain parameters for a concrete event, but since Magento passes a Varien_Observer object to all observer methods, shortcut access the parameters made sense (and it has been there at least since 1.1).

I actually don't see any value in two different objects as they are used today.

But it obviously not was planned like that from the beginning. In the method Mage::addObserver(), not only the event and observer names and static arguments from the <args> XML node are set, but also a callback:

$observer->setName($observerName)->addData($data)->setEventName($eventName)->setCallback($callback);

This way, the observers are able to dispatch themselves, with $observer->dispatch($event). In that case, the observers would not have the event data on themselves and you would need you use getEvent() to access it. But the method is not used anywhere, so in practice it does not matter.

If you want to practice some software archaeology and dig more, you'll find more dead code that hints on original ideas that never made it into the final product, like the Varien_Event_Observer_Collection.


Explanation regarding lack of consistency.

According to Vinai and what Vitaly Korotun told him at some point:

getEvent() is legacy. Back in Magento 1.0 days the event data could not be pulled from the observer directly.

So if you don't need to get event_name and don't care too much about your code being Magento 1.0 compatible, you can leave out getEvent().