From owner-svn-src-all@freebsd.org Thu Dec 17 16:35:18 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 035684BBFD7 for ; Thu, 17 Dec 2020 16:35:18 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Cxczn6RN9z3sNb for ; Thu, 17 Dec 2020 16:35:17 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Received: by mail-wr1-f50.google.com with SMTP id d13so8969931wrc.13 for ; Thu, 17 Dec 2020 08:35:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=3v8V9Y8578pQvBzfjczMk65qiNep9/uGTiBqwuCC+t8=; b=Otpse1JiWCKGxg2+BdKTUsTFBiRi5mP+z33+6O5fmf3mRX9339fra72rHkwlLV+vwj 9ORmbS9PMWDbjLXGE1EpRed6A8BCBbQ8fHduKqM2Jx+z39POxJQQXWo9tgOc+mqsaBrg YeT3thrvvL5wLmpzUbLl3IbnIR8TkbjssaoydRTaFgrYQjJhEYx7A3A9lMzsmsF1sj4P J+8Sxmutl3kQy8g4+HlCTpxHg3gdrBa51xVn3O+SaeQS1CiAd7cOkmrdxkotpo1EJJdX cp8AyJB9CbqMrJ/lcmKuXYxEBfC3Ga2pioitGO1ZWMjvj4C1ILAefMa/mDbMMe2tIxZB kAfA== X-Gm-Message-State: AOAM533aJdtd3C79KBYxSmzg+x9gFVqJNMGhc7WHPFggFJSy5fBBQPlw Eoh4a1ovE6u/zt+hZPr1xP8Pew== X-Google-Smtp-Source: ABdhPJxX1wYTEfbiAFTUZfNP9IYvVreQue6V3LNQTcXhrrSuUT41FRN66ROHF+XPLEwYW1eF9sc8GA== X-Received: by 2002:adf:ec41:: with SMTP id w1mr3850341wrn.12.1608222916370; Thu, 17 Dec 2020 08:35:16 -0800 (PST) Received: from [192.168.149.251] (trinity-students-nat.trin.cam.ac.uk. [131.111.193.104]) by smtp.gmail.com with ESMTPSA id h14sm9840668wrx.37.2020.12.17.08.35.15 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Dec 2020 08:35:15 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Subject: Re: svn commit: r368714 - head/lib/libc/string From: Jessica Clarke In-Reply-To: Date: Thu, 17 Dec 2020 16:35:15 +0000 Cc: Mateusz Piotrowski <0mp@freebsd.org>, src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Transfer-Encoding: quoted-printable Message-Id: <871DEE71-F3DD-4E1C-BAAA-12CCF5C2FADE@freebsd.org> References: <202012171241.0BHCfl1r008452@repo.freebsd.org> <686CF2E6-1D3C-4A83-A323-02CD9F536675@freebsd.org> To: Konstantin Belousov X-Mailer: Apple Mail (2.3608.120.23.2.4) X-Rspamd-Queue-Id: 4Cxczn6RN9z3sNb X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Dec 2020 16:35:18 -0000 On 17 Dec 2020, at 16:22, Konstantin Belousov = wrote: > On Thu, Dec 17, 2020 at 01:01:01PM +0000, Jessica Clarke wrote: >> On 17 Dec 2020, at 12:53, Konstantin Belousov = wrote: >>>=20 >>> On Thu, Dec 17, 2020 at 12:41:47PM +0000, Mateusz Piotrowski wrote: >>>> Author: 0mp (doc,ports committer) >>>> Date: Thu Dec 17 12:41:47 2020 >>>> New Revision: 368714 >>>> URL: https://svnweb.freebsd.org/changeset/base/368714 >>>>=20 >>>> Log: >>>> strerror.3: Add an example for perror() >>>>=20 >>>> This is a nice and quick reference. >>>>=20 >>>> Reviewed by: jilles, yuripv >>>> MFC after: 2 weeks >>>> Differential Revision: https://reviews.freebsd.org/D27623 >>>>=20 >>>> Modified: >>>> head/lib/libc/string/strerror.3 >>>>=20 >>>> Modified: head/lib/libc/string/strerror.3 >>>> = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D >>>> --- head/lib/libc/string/strerror.3 Thu Dec 17 03:42:54 2020 = (r368713) >>>> +++ head/lib/libc/string/strerror.3 Thu Dec 17 12:41:47 2020 = (r368714) >>>> @@ -32,7 +32,7 @@ >>>> .\" @(#)strerror.3 8.1 (Berkeley) 6/9/93 >>>> .\" $FreeBSD$ >>>> .\" >>>> -.Dd December 7, 2020 >>>> +.Dd December 17, 2020 >>>> .Dt STRERROR 3 >>>> .Os >>>> .Sh NAME >>>> @@ -170,6 +170,31 @@ The use of these variables is deprecated; >>>> or >>>> .Fn strerror_r >>>> should be used instead. >>>> +.Sh EXAMPLES >>>> +The following example shows how to use >>>> +.Fn perror >>>> +to report an error. >>>> +.Bd -literal -offset 2n >>>> +#include >>>> +#include >>>> +#include >>>> + >>>> +int >>>> +main(void) >>>> +{ >>>> + int fd; >>>> + >>>> + if ((fd =3D open("/nonexistent", O_RDONLY)) =3D=3D -1) { >>>> + perror("open()"); >>>> + exit(1); >>>> + } >>>> + printf("File descriptor: %d\en", fd); >>> This lines is indented with spaces, while other lines have tabs. >>>=20 >>>> + return (0); >>> return (0) is redundand. >>=20 >> It's not required as per the standard, but omitting it is needlessly >> obfuscating it and bad practice. C lets you do a whole load of things >> that are a bad idea, and whilst this one is harmless, it is = nonetheless >> confusing to anyone who is not intimately acquainted quirks like this >> special case in the standard. > Why it is bad practice ? >=20 > C is a small language, and while knowing some quirks (like this one) > seems to be optional, others are not. And worse, that other quirks are > essential for writing correct code at all. Consequence is that = ignoring > details indicates insufficient knowledge of the fundamentals and = lowers > the trust in the provided suggestion. Small does not mean simple. You admit that the language has quirks you need to know in order to be able to write correct code, so why should we confound the problem by forcing people to be aware of additional optional quirks? This is just another kind of code golfing that achieves nothing other than confuse some people (how many C courses do you know of that actually teach you that you can omit the final return statement from main?) and possibly mask a bug if you meant to return a non-zero value (generally unlikely as error conditions will be handled early, but maybe you have a final ret value lying around you meant to return), when the alternative is just to add a single extra line to be explicit about what you want. Especially since this is example code, we should be seeking to provide as simple and clear code as is possible, though I would not like to see this kind of code enter the base system either. Jess