Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113538 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 45004 invoked from network); 15 Mar 2021 13:59:35 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Mar 2021 13:59:35 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 05A501804E4 for ; Mon, 15 Mar 2021 06:53:07 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ot1-f50.google.com (mail-ot1-f50.google.com [209.85.210.50]) (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 ; Mon, 15 Mar 2021 06:53:05 -0700 (PDT) Received: by mail-ot1-f50.google.com with SMTP id h6-20020a0568300346b02901b71a850ab4so5146403ote.6 for ; Mon, 15 Mar 2021 06:53:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/kHfSxn50kngJMDvftXzZa4DuvDt3RWciCA3MLxWnRw=; b=KnKequ6ARNVMee9yd+NQD7zQreaigC8CnYV5zexLFz8pQbZCJS0lNCxVrhqfHaDgME zYOTpC72kGftcRQZAWbm/URJlf4mFkPlwMFNQ9ZmZRrsuUYDnCO4DOvJiNK9WVDr6cZc iuoe0tZ82kddYOm7VT7bDURhOwl8DtdWVzVMG2bBK9wBcjMrTZNffpOOtE3V/6pLDoWr 4NA7Nf8PDcdkN4NnmXO7UegAGbjNM6AyANOAOOxp5CugvTA/qOu79/ssVjqhmBUMGiwf YiDDsirhuNFfJFjW3Os0tip1LKTRgvsHC4W69raONdjbfJYWO4WqIVVlIopNSSW3QPg1 LmzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/kHfSxn50kngJMDvftXzZa4DuvDt3RWciCA3MLxWnRw=; b=l7NLzEapWfKBifxJ4bKl+DDKQfC1PFxT+DX9Xyrh73BoKLyaqkIjbIUj3qgydxNAiF vne557zN7nya3CaGehOdcSfnPAoWhqeGvVKPncpwIdKdFJDFJqLAZM/mOTQYKwRxtCa5 GhOGrUuOZJjpbafcb6WzGiWJGmY9AdpxKSfx4rls/fEjFAppLKDPhCXKLRQauhf0dHpq rf+keFV3lF5N3v6aCnYsH8ud4wdUfo+bA6aHAoJFnKsCQ2R7AkskWVEGjL4ckQo8CHUg a0wHVOdyIxAFbfO2J6Ufam4LAl5wmAvSDq3CbfzvwUoQL4rxxRR8svJ2LZsuecfH85UE 6+lQ== X-Gm-Message-State: AOAM53201zcPS5WrONWbRkahiai13dTk509bWCmO5+KwR9tZU2yC9QLK GkMx1ErvN30io01NM3XLJXNpYW4qtGaxrMD91LE= X-Google-Smtp-Source: ABdhPJwtfTGrQTdnkldNAlXRg8MfBWv9SfgKaxRW7/xcsy1WZfYfSRHwyA5A9/tDmUTBZiHVvbQ/7AEdqlZPfBob6kc= X-Received: by 2002:a9d:1c89:: with SMTP id l9mr14509364ota.25.1615816383723; Mon, 15 Mar 2021 06:53:03 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 15 Mar 2021 13:52:52 +0000 Message-ID: To: Peter Stalman Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000931c8205bd9391de" Subject: Re: [PHP-DEV] Built-in decorator attribute? From: davidgebler@gmail.com (David Gebler) --000000000000931c8205bd9391de Content-Type: text/plain; charset="UTF-8" > Would it make sense to have both options? If you have the wrapper pattern, you already have both options. This would be my preferred way of doing it but harder to implement, particularly in any way which significantly mimics Python's way of doing it. > One problem with the wrapper pattern is that if you have multiple decorators then wouldn't that end up calling the function multiple times? Not so with the before/after. It really depends on the intended behavior. How does Python and others handle this? Python the @decorator syntax is just sugar for re-assigning a method so they are easily stacked. Say we have a trivial decorator: def timer(func): def wrap(): start = time.perf_counter() func(*args) end = time.perf_counter() print("Did thing in this many seconds...") return wrap Then @timer def foo(a, b, c): # do some stuff is equivalent to foo = timer(foo) and @timer @somethingElse def foo(a, b, c): # do some stuff is equivalent to foo = timer(somethingElse(foo)) Regards, David On Mon, Mar 15, 2021 at 1:46 AM Peter Stalman wrote: > On Sun, Mar 14, 2021 at 6:34 PM Peter Stalman wrote: > >> Would it make sense to have both options? >> > > 6) Multiple decorators on the same function? > One problem with the wrapper pattern is that if you have multiple > decorators then wouldn't that end up calling the function multiple times? > Not so with the before/after. It really depends on the intended behavior. > How does Python and others handle this? > > Thanks, > Peter > > > --000000000000931c8205bd9391de--