Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75248 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 37206 invoked from network); 4 Jul 2014 12:34:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Jul 2014 12:34:35 -0000 Authentication-Results: pb1.pair.com header.from=php@tutteli.ch; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=php@tutteli.ch; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain tutteli.ch designates 80.74.154.78 as permitted sender) X-PHP-List-Original-Sender: php@tutteli.ch X-Host-Fingerprint: 80.74.154.78 ns73.kreativmedia.ch Linux 2.6 Received: from [80.74.154.78] ([80.74.154.78:51923] helo=hyperion.kreativmedia.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A3/10-35335-85F96B35 for ; Fri, 04 Jul 2014 08:34:33 -0400 Received: (qmail 10360 invoked from network); 4 Jul 2014 14:34:28 +0200 Received: from 91.141.1.167.wireless.dyn.drei.com (HELO RoLaptop) (91.141.1.167) by ns73.kreativmedia.ch with (AES128-SHA encrypted) SMTP; 4 Jul 2014 14:34:28 +0200 To: "'Xen'" , References: In-Reply-To: Date: Fri, 4 Jul 2014 14:34:17 +0200 Message-ID: <002b01cf9784$4c1fe670$e45fb350$@tutteli.ch> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQEXw8xSC1llRw+ZtijSr3FQoKfQBZz/PHLQ Content-Language: de-ch Subject: RE: [PHP-DEV] not_null function From: php@tutteli.ch ("Robert Stoll") Hey, > -----Original Message----- > From: Xen [mailto:xen@dds.nl] > Sent: Thursday, July 03, 2014 11:40 AM > To: internals@lists.php.net > Subject: [PHP-DEV] not_null function >=20 > Heya, >=20 > I was just wondering about something. >=20 > It seems way more natural and flowing to have and use a "not_null" > function in addition to some "is_null" that currently exists. >=20 > The reason is that most of the time you are not checking null = condition, > you are really checking the non-null condition. >=20 > But a line like "if (!is_null($a))" feels like there are two verbs in = it. >=20 > It is like you are saying "if $a is not is null". >=20 > It is different for the "empty" function because there is no "is_" = prefix > in it. So "if (!empty($a)) feels completely sane. >=20 > So generally I will *want* to test a null condition but I just hope my > variable won't contain anything that evaluates to false and just test = "if > ($a)". >=20 > If there was a not_null() I would use that instead, because "if > (not_null($a))" only contains one "verb" instead of two. >=20 > And I would define that helper function myself, but I don't want to = write > code that another person would not be able to run just because = not_null is > not defined in his library. >=20 > -------- > In general I believe this is rather a problematic feature of most > languages. >=20 > The "if" statement implies a verb, but many functions and methods also > contain a verb in their name. >=20 > This seems to be only the case for the "is" verb. I know in my = language > (Dutch) the "to be" verb (zijn) is treated differently from all other > verbs when it comes to the adverb/adjective difference. >=20 > When you state "I am good" the adjective is used, but "I work good" = should > be "I work well". The adjective applies to the subject "I" but the = adverb > applies to the verb "work". I guess there are all sorts of mixtures, = "I am > well" is also used. But I think it is improper. >=20 > Thus, "if (has_members())" feels natural because it uses a different = verb > replacing the default "is". >=20 > But "if (is_null())" feels odd because "if (null())" would say the = same > thing only more concise and more natural as far as if statements go, = or at > least it seems that way to me. >=20 > Personally I try to avoid those "is_something" functions whenever I = can. > It is not so much an issue if it is some rarely used library call. >=20 > Like WordPress has functions like "is_single()" which returns a = boolean > indicating whether the currently loaded page is a single post display. >=20 > But notice that "if (single())" would give very little information as = to > what you were actually testing. There is no parameter, and just = "single" > would be so general that it would completely obfuscate the fact that = it > had to do with WordPress. It would have to become "page_is_single()" > although "page" is (improperly) dedicated to a special type of post = that > sits outside of the regular post structure. They ought to rename it to > "staticpage" or "static". "page_is_single" and "page_is_home" and > "page_is_category" would be more descriptive. >=20 > But in any case, this language incongruency is most annoying with core > functions you have to use all the time, or would be using all the time = if > they were okay. >=20 > So my suggestion would be to consider introducing at least "not_null". > "isset" seems to be a different category, if only because the verb is = not > visually separated from the condition. >=20 > So "if (isnull($a))" would again be more natural. But because the verb = is > visually separated using the underscore, you get two verbs in your = mind. > Perhaps creating an "isnull" alias and then deprecating the "is_null" > function would be best. >=20 > Regards, >=20 > Bart Schouten >=20 > ps. please "reply all" for I am not subscribed as of yet. >=20 > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php [Robert Stoll]=20 I really like how ruby tackles this problem with the syntactic sugar = "unless" which basically is a substitute for "if( !() )". Maybe we could consider to introduce it in PHP next? It is very natural = to read "unless(is_null($x))" an much nicer than "if(!is_null($x)" IMO. = And it would not only solve your issue with is_null but is_Xy = functions/methods in general. Cheers, Robert=20