Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117433 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 82609 invoked from network); 26 Mar 2022 20:47:30 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Mar 2022 20:47:30 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CEF181804A9 for ; Sat, 26 Mar 2022 15:15:04 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.2 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 26 Mar 2022 15:15:04 -0700 (PDT) Received: by mail-wr1-f45.google.com with SMTP id m30so15292172wrb.1 for ; Sat, 26 Mar 2022 15:15:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to:content-transfer-encoding; bh=ziAy7p87bxLadW+7y/5C9/nVod41W/btAxKPzwteDhI=; b=g4egll+dSJ70Tc/nSSZwmVnHcsktZayqdIPJlWOYLBa49jzESPFRYki0Zs2PnIMJ8G p7P67iNEkQBuOdjR/xOwfAPAOC9SUbMtWn4ZWvJ3yStRqV6xAFsHkN3vNfslRQT9H5Q7 hqpJEtdyETVi5CzvCW3SNt64cphm5zUa8yuCVyMsIxRl7oOuB2PrBIL9yGMPaHw91HAe PeLviZzjq4pr7lnEfgs/p0ej5ZG3YuPJphDA1YGF4rCOKZ8lu7duQnPqnobBScsT2ZEY OIq9O5asGmuSUQGGKd/bgq5KHp6hiQKx4M04E7BlRwz7gDrTN4Z1lP6LzBPSUdz1SvVx brRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=ziAy7p87bxLadW+7y/5C9/nVod41W/btAxKPzwteDhI=; b=ULnU/71xUQR4I/07DZXzYhHGLpjUBmZcibNhhs6DE+feqZB8KkZGuvdQybG/J4OprY JGJJH4oaVgbGpMv1zOPxSWnZCHVfsae1Xfrb2MbbFEQzKC1oyFUzwUkHAFVgkI4f9+LR 758glk+zO7FibuveIAJ9iOtFxMXgIiG+EY7VmlG8BvYgYBDvYgffvTMmZzTgkp84jm8R 9zSMvF8JXNzX1XaMg1dZKiC2YvVA/Ok7s2KvuFWoTpoSqU9csHlwowyPVQOVPjHzvWCD BgJ95nPF+BszZnat1r/IM6urPy+zz9jWzi3qeDm/Cr0dj3CgLUqDwt6fRZ+tVVm9kbGz 8PjA== X-Gm-Message-State: AOAM532nW6CWy3kXFBIiNUNod71nulKNzfEGT/S60+MXXWw8nfHrtHY2 JRoZ+xWlYjVwinjR1YrC3FaHe/vMDX8= X-Google-Smtp-Source: ABdhPJzNSXyAISFZFBVoP0ktfhA6/cxnoi1wN/93AtnIM5Jp182uToovYcMZx/DXXpygVcRM+nQlXQ== X-Received: by 2002:adf:f586:0:b0:204:3bd:eb10 with SMTP id f6-20020adff586000000b0020403bdeb10mr15344084wro.552.1648332903200; Sat, 26 Mar 2022 15:15:03 -0700 (PDT) Received: from [192.168.0.22] (cpc104104-brig22-2-0-cust548.3-3.cable.virginm.net. [82.10.58.37]) by smtp.googlemail.com with ESMTPSA id n37-20020a05600c3ba500b0038cc9d6ff5bsm8290752wms.4.2022.03.26.15.15.02 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 26 Mar 2022 15:15:02 -0700 (PDT) Message-ID: Date: Sat, 26 Mar 2022 22:15:01 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Content-Language: en-GB To: internals@lists.php.net References: <10558027.nUPlyArG6x@arnaud-t490> In-Reply-To: <10558027.nUPlyArG6x@arnaud-t490> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [RFC][Under discussion] Arbitrary string interpolation From: rowan.collins@gmail.com (Rowan Tommins) On 25/03/2022 14:38, Arnaud Le Blanc wrote: > I find that sprintf() is easier to read in most cases. One reason for this is > that the text is separated from the code. Funnily enough, I find sprintf() *harder* to read for the same reason - particularly once there are more than two or three parameters, and more than a bit of punctuation between them. A large part of that is because the placeholders are positional rather than named, so you have to keep track of which is which; but by the time you've got named placeholders, you might as well have variable interpolation. As a silly example, I prefer this: $sentence = "The {$adjectives[0]} {$adjectives[1]} {$nouns[0]} jumped over the {$adjectives[2]} {$nouns[1]}"; To this: $sentence = sprintf(    'The %s %s %s jumped over the %s %s',    $adjectives[0],    $adjectives[1],    $nouns[0],    $adjectives[2],    $nouns[1] ); I think that's partly a matter of taste, though, because I've definitely seen people happily using both styles. And there are certainly situations (like translation strings) where placeholders of some sort work better than straight interpolation. That's why I thought it was interesting to see what other languages have done. While PHP and Ruby have obvious links back to Perl, many languages which didn't start off with string interpolation have added it in later versions, e.g. C#, Scala, JavaScript, Python. Clearly there were sufficient voices in favour in each of those communities to add it; and in each case, they added *expression* interpolation, not just the *variable* interpolation supported by Perl and PHP. I won't be too upset if this feature doesn't get added, but I do think it would be a nice addition. Regards, -- Rowan Tommins [IMSoP]