> On Jan 11, 2021, at 6:52 PM, Larry Garfield <la...@garfieldtech.com> wrote:
> 
> On Mon, Jan 11, 2021, at 2:27 PM, Ben Ramsey wrote:
>>> On Jan 10, 2021, at 20:09, Larry Garfield <la...@garfieldtech.com> wrote:
>>> 
>>> On Sun, Jan 10, 2021, at 4:40 PM, Mark Randall wrote:
>>>> On 10/01/2021 21:27, Larry Garfield wrote:
>>>>> The "a method that begins with try is nullable, so watch out" idiom is 
>>>>> present in C# and Rust, but to my knowledge has never existed in PHP.  
>>>>> That doesn't make it bad; it actually combines quite well with the null 
>>>>> coalesce operator to allow for default values, making a valueOrDefault() 
>>>>> method unnecessary.
> 
> 
>> I have no problem introducing this idiom (or similar). In fact, I welcome it.
>> 
>> In userland, the same concept is often achieved with methods like 
>> `fromOrNull()`, and as Mark points out, the word “try” makes me think 
>> the method should throw an exception if it fails. I’m not advocating 
>> for `xOrNull()`, though, since I think that smacks of Hungarian 
>> notation, but maybe we can come up with something that is a more 
>> PHP-ish name. ;-)
>> 
>> “There are two hard things in computer science: cache invalidation, 
>> naming things, and off-by-one errors.” --Phil Karlton
>> 
>> Cheers,
>> Ben
> 
> Do you have a suggestion for a better, more PHP-ish naming convention?

maybeFrom()?

> 
> "It's what other languages use and they don't have a problem" is a valid 
> argument, but not a slam dunk so alternate naming patterns are on the table.
> 
> --Larry Garfield
> 
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: https://www.php.net/unsub.php 
> <https://www.php.net/unsub.php>

Reply via email to