From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS53758 23.128.96.0/24 X-Spam-Status: No, score=-2.3 required=3.0 tests=AWL,BAYES_00,BODY_8BITS, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id 6BE4E1F5AE for ; Tue, 11 May 2021 12:53:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231441AbhEKMyf (ORCPT ); Tue, 11 May 2021 08:54:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231270AbhEKMye (ORCPT ); Tue, 11 May 2021 08:54:34 -0400 Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 646CAC061574 for ; Tue, 11 May 2021 05:53:28 -0700 (PDT) Received: by mail-io1-xd2f.google.com with SMTP id p8so17966772iol.11 for ; Tue, 11 May 2021 05:53:28 -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:content-transfer-encoding; bh=GnMYATIUMcRABXXfk9PVzscWGLeIcQG7dDOdD9pJ2Pw=; b=CXIVM6vFIjqsQyie/VXsIk3RMHkomGyRiMi9MqSNTibPpK1N6bNd4iB6qPeP07Feyn eQqg0Ch9q0Z+x1QXL4+tIHsFXx1ALzdcBuNPSfbFJqcjk8eTi7AXb0FMF/8OOXqlODQo jTxFSfcSrSSGVTpoJLO+9ClcFdRVabQL3lzh9kX2ZsluRiV/g02OEwdH2gSrYXEan8No aasW5UVH2wVH9i2kHHwv3Tqq9FdkyvfWDEGOfAE/fwZzUWsGECHaFQFpU30ZKQMBdfog ZFk7ajo6LILxOAaCnYrAx0p0PV/i6MkZ6qD6uFScO1pGVI2XwioI+fOgX57UnrP3iUwO rvZQ== 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:content-transfer-encoding; bh=GnMYATIUMcRABXXfk9PVzscWGLeIcQG7dDOdD9pJ2Pw=; b=L8L+qGB9XJjVZpwiO01/h2Cjg+LDJRG3MSD31QwbhLcf2YZBGm41aPBTQpCcHu87hP 1T8WU/XLuxAjXZXnAuEuZDR1z9cYTrBAjWc/ZOJBFV+Wru+qjDL+9f/nx/EZF0QkZf/e bjdlOPGl07SZYAASnswciVtT9kehW9j0cRBHaK+ptpceydxA+T+OeDUBCi6SmpYQGjUi DduMlas+S+5yYp9ekJvwr4PZGo8dBhpmxZzYl68sANsE+JiycrB4CBplnIMBFtwt/rlT YRBFhswPlzrG+n6bfDeZWeVlP6PRx3GM675F72klfNEC4ax99m2O0Bno5wnLQW+2GT12 YhcQ== X-Gm-Message-State: AOAM5308JVi39uRfqJ0Pxno4JYHnLELQ1uEzwRCtyhh6MaNBYD84xQx6 uzUVn/gW6SBOtciaDCvYK/bXj8ITBTpQ8uR++Uo= X-Google-Smtp-Source: ABdhPJxx4Qed8qgIKY+kzEDZU2jPDtk/bxLLJZkjynPZ8afL2CvQu3Y1sauReH+ubGaTxJHA6VbIjfQq50QeGbh44u8= X-Received: by 2002:a05:6638:1242:: with SMTP id o2mr26581771jas.10.1620737607865; Tue, 11 May 2021 05:53:27 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: ZheNing Hu Date: Tue, 11 May 2021 20:53:11 +0800 Message-ID: Subject: Re: [PATCH v2 2/2] [GSOC] ref-filter: introduce enum atom_type To: Junio C Hamano Cc: Christian Couder , ZheNing Hu via GitGitGadget , git , Jeff King , Hariom Verma Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Junio C Hamano =E4=BA=8E2021=E5=B9=B45=E6=9C=8811=E6=97= =A5=E5=91=A8=E4=BA=8C =E4=B8=8B=E5=8D=882:12=E5=86=99=E9=81=93=EF=BC=9A > > Christian Couder writes: > > >> I find it far more intuitive to say > >> > >> for (i =3D 0; i < ATOM_INVALID; i++) > >> > >> than having to say UNKNOWN+1. > > > > Yeah, that's more intuitive. But in my opinion, using `ATOM_UNKNOWN + > > 1` instead of `0` at least shouldn't often result in more lines of > > code, and should be a bit easier to get right, compared to having to > > initialize the field with ATOM_UNKNOWN. > > Number of lines is not all that important. > > But the developers must remember that UNKNOWN is at the bottom end > and INVALID is at the top end, which is very taxing. Tying UNKNOWN > to the top end and INVALID to the bottom end would equally be > plausible and there is no memory aid to help us remember which one > is which. Compare it to "array indices begin at 0, and the upper > end is MAX". Your scheme is much easier for developers to screw up. > Yes, UNKNOWN + 1 is difficult to use. But using UNKNOWN =3D -1, this means that the coder may indirectly use an init atom_type with junk value "ATOM_REFNAME", they maybe did't notice they need reinitialize the value to UNKNOWN. I thought that perhaps such a naming would be better: ATOM_BEGIN =3D ATOM_UNKNOWN + 1, ATOM_END =3D ATOM_INVALID for (i =3D ATOM_BEGIN; i < ATOM_END; i++) { } But ATOM_END has been used... -- ZheNing Hu