public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
	Christoph Heiss <c.heiss@proxmox.com>
Subject: Re: [pve-devel] [PATCH installer 3/6] tui, ui: switch over to JSON-based protocol
Date: Sat, 24 Feb 2024 17:55:01 +0100	[thread overview]
Message-ID: <2b33087e-a327-4b37-b995-94c83b48a2a5@proxmox.com> (raw)
In-Reply-To: <20231206113456.411898-4-c.heiss@proxmox.com>

Am 06/12/2023 um 12:34 schrieb Christoph Heiss:
> Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
> ---
>  Proxmox/UI/StdIO.pm                           |  41 ++++--
>  .../src/views/install_progress.rs             | 117 ++++++++----------
>  2 files changed, 83 insertions(+), 75 deletions(-)
> 
> diff --git a/Proxmox/UI/StdIO.pm b/Proxmox/UI/StdIO.pm
> index a97245c..25d1c82 100644
> --- a/Proxmox/UI/StdIO.pm
> +++ b/Proxmox/UI/StdIO.pm
> @@ -3,10 +3,26 @@ package Proxmox::UI::StdIO;
>  use strict;
>  use warnings;
>  
> +use JSON qw(from_json to_json);
> +
>  use base qw(Proxmox::UI::Base);
>  
>  use Proxmox::Log;
>  
> +my sub send_msg : prototype($$) {

wrong prototype, the second argument isn't a scalar but a list interpreted as
hash.

That's why you had to use &send_msg on the call sites, which calls it via
reference and so does not checks prototypes at all.

Correct would be prototype($%), but that's not really catching any issues,
so it could be just left out.

In general I'd recommend to try to not overuse prototypes, they are best
for cases where one interacts with other functions or bindings that have
to map to an exact argument style, like the syscall wrapper we have in
pve-common, and even there the "is correctly called" is mostly a side-effect
(that can be circumvented as you've done here).

Prototypes basically allow you to create functions that behave like Perl
built-in functions, and e.g., take an array-ref even if a list is passed,
but for us that's seldom of use, or rather said, a bit to magic for my
taste and can lead to bugs on its own (list based to scalar prototype
results in the list-size being actually passed, way better for long term
maintenance to just do such things explicitly...

That doesn't mean that they should not be used at all, they sometimes can
have benefits, but if you need to result to use &method() to call a sub then
you're just doing something strange (and most of the time also wrong).




  reply	other threads:[~2024-02-24 16:55 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-06 11:34 [pve-devel] [PATCH installer 0/6] switch low-level installer protocol to json Christoph Heiss
2023-12-06 11:34 ` [pve-devel] [PATCH installer 1/6] low-level: align wording of finish message Christoph Heiss
2023-12-06 11:34 ` [pve-devel] [PATCH installer 2/6] ui: stdio: log error if display_html() is called on stdio backend Christoph Heiss
2023-12-06 11:34 ` [pve-devel] [PATCH installer 3/6] tui, ui: switch over to JSON-based protocol Christoph Heiss
2024-02-24 16:55   ` Thomas Lamprecht [this message]
2023-12-06 11:34 ` [pve-devel] [PATCH installer 4/6] test: add tests for UI^2 stdio protocol Christoph Heiss
2023-12-06 11:34 ` [pve-devel] [PATCH installer 5/6] buildsys: setup proper test environment for testsuite Christoph Heiss
2023-12-06 11:34 ` [pve-devel] [PATCH installer 6/6] tui: install progress: add tests for UI^2 stdio protocol Christoph Heiss
2024-01-24  9:54 ` [pve-devel] [PATCH installer 0/6] switch low-level installer protocol to json Christoph Heiss
2024-02-26 14:07 ` [pve-devel] applied-series: " Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2b33087e-a327-4b37-b995-94c83b48a2a5@proxmox.com \
    --to=t.lamprecht@proxmox.com \
    --cc=c.heiss@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal