Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123160 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id E75661A009C for ; Fri, 19 Apr 2024 19:20:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1713554453; bh=158FKsxBwJYiNvXP0i7Jx6cmWs3DvDY37FEkeAdh/jw=; h=From:Date:Subject:To:References:Cc:In-Reply-To:From; b=mBY3ZPDJtYhCP/wMlrFzq+Q7AnT+v4mt4psl6JB5MfkEEMJ9HUzBMrm68YkCpUNCX NQJwNSkNkxjCY5vsFU2wxBxzXEcRaHDqUPWK1WoGnCA3AH5y9lOqp1bEBGibAjyXJO SGa/4gFyaHH40A/P163ZjwvrM4d3EQHRf7Rp7azsa2UOmbwucmeNWamqx+nB55a3W6 w8YxrqVAMLUUrOWQJuaz9Z/yO6Yd3CPp0mAvrnO6k562z4a0KQwvxn2XZ4zdKa8Kde E3tC3Vr7O1PNnSpfROSv5Tq56GF1LEpPm9UDGrc9UvH72BpqgLXhwvbp5dmktlD0kO FQQEmxfhE91OA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 205A7180055 for ; Fri, 19 Apr 2024 19:20:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 19 Apr 2024 19:20:51 +0000 (UTC) Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-56e6affdd21so1109608a12.3 for ; Fri, 19 Apr 2024 12:20:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wcflabs.de; s=google; t=1713554412; x=1714159212; darn=lists.php.net; h=content-transfer-encoding:in-reply-to:cc:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=EdbfQ02w2D0fV9tJDJcsF4vuQoFU9QMIJYD+57EELY8=; b=GrXkmO2ztINWp2c+a4rSMlTAkwqOQf5lj/CBT0UITwDbgPWUZ5asasrO+yMaEakvuM +Sf/vNDQCrov4Svy8wACALL869JYJc8kVamalmXDOXbAgfzeLVX3aRimu+8ruE3f2JTt EhW1KgYFlIAyIRDSjgX/B+G9N0NatuuG7QwxUkc7eex0n6TROTZ6pKOXuvrbkNnDDFaC mMMMSMPDJuQ0Cv8/SLr0UUBkjxVsXCbspf1caEETotGUkO5GwyKOTDmdaQVMrml1rZqw Aesk1Bj93d+OyeHEA086ka17BEnMYNe7ERgbsIbAv3Eaq2H7TJI21o6WDRruxdoTaxPw zc/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713554412; x=1714159212; h=content-transfer-encoding:in-reply-to:cc:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=EdbfQ02w2D0fV9tJDJcsF4vuQoFU9QMIJYD+57EELY8=; b=ZFk3oS3q11WEBrT/ItM+lLZnswY0f7h4ML4UUeQbHTK7cTCS5sms9oAcXijsVrhQY2 e+U5kSXfbau1GtIl1eaYRqUvVJW7blFIYSknGAjH6EOmnQo9Sp3Rm0gZi4L9ZqI4HqIF qZRFbQHRC4czOkqPxm40u38gF19a1Rw5vD4N0PxYF7hL2jru1TMYF7nMn2KSssfP3+Kk uP6WzjmAraB+Dc5FkvRTP6qp79Zja766HzRGGd/ZDZQBcZW0y36yw2JiBxyFT+2iWT7N bPvgBUtIf+umeC7Xqr748i0kCsFgFT9F5F90W6kfeGWbxHf28lOpKOJI389NjigWviV0 ylYg== X-Gm-Message-State: AOJu0YwY594Ob7widsGfY3pUx9/djr322gPbs+yXFuEiKyX3yCrH+VbS VX72FNDG2MbHdt+4Uimjt/tBqEtTNYUvyKjNKItpu8IMeb7q9AUcEpTtz/SPi00= X-Google-Smtp-Source: AGHT+IGks2yyud4HKILdcUOCtTnP2p5qpLQIwWj35PKWXsxTunBSj2wHijucFKtSnirSkovXN+4uJQ== X-Received: by 2002:a50:8d17:0:b0:56e:1010:cd7c with SMTP id s23-20020a508d17000000b0056e1010cd7cmr2315142eds.12.1713554412269; Fri, 19 Apr 2024 12:20:12 -0700 (PDT) Received: from ?IPV6:2a01:598:c000:b860:f477:8504:6874:238c? ([2a01:598:c000:b860:f477:8504:6874:238c]) by smtp.gmail.com with ESMTPSA id k4-20020a50cb84000000b005705bb48307sm2451792edi.42.2024.04.19.12.20.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 19 Apr 2024 12:20:11 -0700 (PDT) X-Google-Original-From: =?UTF-8?Q?Joshua_R=C3=BCsweg?= Message-ID: <06373f2b-5de0-4582-96c5-29c3b474c01d@wcflabs.de> Date: Fri, 19 Apr 2024 21:20:10 +0200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] RFC [Discussion]: array_find Content-Language: de-DE To: Levi Morrison References: <24e4529d-0b75-44de-90ef-34de5dfb1c99@wcflabs.de> <278889be-82ab-4827-a9e7-801b5ba2d8f8@app.fastmail.com> Cc: PHP internals In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit From: josh@wcflabs.de ("=?UTF-8?Q?Joshua_R=C3=BCsweg?=") On 11.04.24 03:03, Levi Morrison wrote: > IMO, it's better to separate it into two functions because its type is > stable without control flow. For instance: > > // Returns K if $b is true, V otherwise. > function array_find( > array $array, > callable(V, K): bool $callback, > bool $b = false > ) -> K|V; > > This isn't stable and requires control-flow to understand the type. > These are simpler: > > function array_find( > array $array, > callable(V, K): bool $callback > ) -> V; > > function array_find_key( > array $array, > callable(V, K): bool $callback > ) -> K; > > Naming bikeshedding aside, it's better to have types that are > inferrable without function-specific knowledge of control flow. It > doesn't matter if it's a bool or an enum, it still has problems. > Better to just separate them to different functions. I definitely see the point where there is an advantage to having two separate methods and can definitely understand that it is easier for developers to understand the control flow without evaluating the parameters. I'm unsure if that's really necessary though, because basically it's probably not necessary to directly see what exactly the function returns. Perhaps there will be another opinion on this in an email in the next few days. Cheers Josh