On 15/04/16 05:22, Levi Morrison wrote:
>> Unless you like having is_null() scattered around your code in a hundred
>> > places...  I don't. :-)
You have lots of code instead in exception handling away fro the normal
program flow?

>> > [1] https://en.wikipedia.org/wiki/Tony_Hoare#Apologies_and_retractions
>> >
>> > --Larry Garfield
> My point is that `foo(bar(), $val)` won't die because bar may return
> null. Bar is expected to return null sometimes.
> 
> For example, let's consider an administrator page where they look up
> user information based on an identifier. The routine we'll use will
> have this signature:
> 
>     function get_user(string $id): User | Null;
> 
> It is possible for an identifier to not exist and this is not an error
> (database successfully returned no results). If there is no User data
> to display then it makes sense for the UI to present that differently.
> Thus it makes sense to pass that User | Null onto the code that will
> present it:
> 
>     $user_data = get_user($id);
>     // ...
>     $user_html = render_user_data($user_data);
> 
> In fact this is a common operation that is encountered in many code
> bases (I think every single one I've ever looked at).

That is a possible database type scenario, although on all of my
systems, the 'guest' user will be accessed as a default which gives the
default user data set.

The main thing I see with the 'null is not needed' argument is that it
instead relies on 'exception handling'? If I am scanning a file or
reading a record set, at some point I hit the end, and in ALL my code
base I get a null object rather than result object, be that reading and
processing a file or a database feed. We have already had the complaints
about file handling should give an exception when there is nothing left,
but MY workflow keeps everything in line ... when the last record is
processed we see the 'null' and progress to the next step in the
process. There is nothing here that needs to involve throwing exceptions
which may well be coded out of line with the main program flow and make
debugging more difficult?

-- 
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk
Rainbow Digital Media - http://rainbowdigitalmedia.co.uk

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to