Re: OOP leads to lousy websites?

From: Bruno Desthuilliers (bdesth.quelquechose_at_free.quelquepart.fr)
Date: 02/22/04


Date: Sun, 22 Feb 2004 19:26:11 +0100

Chung Leong wrote:
> Uzytkownik "Tom Thackrey" <use.signature@nospam.com> napisal w wiadomosci
> news:VUcZb.21$0A2.5@newssvr27.news.prodigy.com...
>
>>Your example is too trivial. Plus the error you avoid is essentially using
>>an undeclared variable. I'd rather have it fail catastrophically than
>>subtly.
>
>
> Not necessarily. The null can be returned from a function, or is an element
> not set in an associative array (in $_POST for instance). In 99 out of 100
> cases, the difference between null and an empty string is philosophical. The
> point is, there's no data.

The difference between null and '' is much more than just philosophical
IMHO. An empty string is not 'no data', not more than 0 is 'no data'.

> A more realistic example would be XML data extraction. To get an element
> with a particular id, the OO code would look like:
>
> $country = $doc->GetElementById('Poland');
>
> while a function-based API would yield this syntax:
>
> $country = xml_get_element_by_id($doc, 'Poland');
>
> Now say we want to get a list of its child-elements, the OO code looks like:
>
> $cities = $country->GetElementsByTagName('city');
>
> while the non-OO counterpart is:
>
> $cities = xml_get_elements_by_tag_name($country, 'city');
>
> If there is no element with the id 'Poland', the OO could fail
> castatrophically without additional safeguard, while the non-OO version
> probably generates an warning (which the users probably will never see)
(snip)

'would', 'could' etc... Why 'could' the OO version 'fail
castatrophically' and why 'would' the procedural one generate a warning?
this is just plain non-sense. The only correct behaviour *in both cases*
should be to return null, and the caller to check the return value.

If that's all your case against OO, there is no need to continue this
thread.

Bruno



Relevant Pages

  • Re: dereferencing type-punned pointer will break strict-aliasing rules
    ... our warning flags are missing other new gcc warnings. ... object code size (the memcpy gets optimized away in almost the same way ... The temporary variable with a basic type is to avoid gcc getting confused ... There is no problem loading the source operand since only its address ...
    (freebsd-current)
  • Re: give me some tips
    ... Rod Pemberton schrieb: ... avoid the use casts, except to ensure the type and precision of numerical ... If you decide that the warning is not critical and your compiler ... offers a #pragma to switch off a warning for a code section, ...
    (comp.lang.c)
  • Re: is it ok to return null?
    ... But the goal should not necessarily be to avoid an exception. ... That's not to say I don't agree with returning an empty array from a ... by the advice to return an empty string to avoid a null. ...
    (comp.lang.java.help)
  • Re: need some help with threading module...
    ... But how will i learn using threads if i avoid using them ... That is an excellent reason to mess with them, it was just a warning ... controller class, please look again at what I gave you this as an ... You also mention the MVC pattern. ...
    (comp.lang.python)
  • Re: Confirm each email when running mail merge
    ... The warning comes up (for security purposes) when "another program" is ... To avoid having to click Yes on each occasion, ... services on a paid consulting basis. ...
    (microsoft.public.word.mailmerge.fields)