From owner-svn-src-head@freebsd.org Thu Dec 17 16:33:10 2020 Return-Path: Delivered-To: svn-src-head@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 C262D4BBFC4 for ; Thu, 17 Dec 2020 16:33:10 +0000 (UTC) (envelope-from ian@freebsd.org) Received: from outbound5a.ore.mailhop.org (outbound5a.ore.mailhop.org [44.233.67.66]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4CxcxL3YDnz3s9f for ; Thu, 17 Dec 2020 16:33:10 +0000 (UTC) (envelope-from ian@freebsd.org) ARC-Seal: i=1; a=rsa-sha256; t=1608222782; cv=none; d=outbound.mailhop.org; s=arc-outbound20181012; b=YM9r4gY3sbh+ZAQb4cQgw/KjRTHk2l4dMZ2LY6EkmgAmVYk84vK4S3+L/iFwYEGHV9tzz1s7jyGxD 3mG9bpkVTUmgia/a53AIZseDTdDJMCZFH6worzwPsu+NO2tbkmqtnepQAXhAH04kK+2mBWmvsIOcSj UrUjeCFMftRzVxpzhkKbbkkAU2+sfYUR9CGPW4PsB0AdubF/8/gCpm9Qj2etpRmTBDSkiZCUXv/yc/ 2rYU5JLnW/G66dMDkjXRSup14cTyrN8gLXrHR+b0RirAr4racBkvT1zAgcFfOoTia1kYSIYxc/yG/y IVr7sbCASFdHCCdEki3uDJWoR5DnLpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=outbound.mailhop.org; s=arc-outbound20181012; h=content-transfer-encoding:mime-version:content-type:references:in-reply-to: date:cc:to:from:subject:message-id:dkim-signature:from; bh=vq503+VYc8S5q/eKo0WZV+GDM8zM/+LzhShQvaBiBuE=; b=AxqTGfK2ytIh959CVxOfHBNGTRMavBypbB79C3kFrnr+EJ7RSZJEb5PoyEen+8SiqepQ4Uw4E5J26 Hvx/bO6QhoxQhJQPIbB3ddrIt0OGlqzCjk8IV5+YtoGx3K0CoHmZfgTDsd4DesbAXoZMJoWHLdQ2G4 vYvghqYgb5ySIZui9n72eJhqbvLpHErr/Rx+CPon8gRwkwLWw9mCZvoy8tW6RzV7rpP58gf9TRO33T kl+S5MaYNd58kHeTz9X1DXBrZGsouOqpAel8Sjvbuxj+SVceC+R75HWodzQ9wlqMSG7cfnFZDDy8EO 0Tj5lYzA6PsgmxnG6KspE1UVO0l7otQ== ARC-Authentication-Results: i=1; outbound3.ore.mailhop.org; spf=softfail smtp.mailfrom=freebsd.org smtp.remote-ip=67.177.211.60; dmarc=none header.from=freebsd.org; arc=none header.oldest-pass=0; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outbound.mailhop.org; s=dkim-high; h=content-transfer-encoding:mime-version:content-type:references:in-reply-to: date:cc:to:from:subject:message-id:from; bh=vq503+VYc8S5q/eKo0WZV+GDM8zM/+LzhShQvaBiBuE=; b=StjK4Ryg+A8Jh/ULfMRUwBfJ8CGBI90WKiHWrN4U/rxzSHzDsARhnMQrWbQFWqe8679+UDZDuh0JV bBjBysmKWvSXbnlvmTlyYwNsqwZPZb6uhOR6T68BMsagzKkrgnZ+4TZBNrF9JS78iVsZMjAMFQ1pRm oHk84ju1h4GFLOw6tzxlsIWw4z/kJQi7yhQDs8MU1w0S7fppRghZazUJFRVbodoRB6VRLuZaoy7zhn A5zO43oMTI/niUEKuW6JMLcVHQ2ii4nvZL0QRKSFC5h0DNrsNQPPZaBww5Ak+VyH8As7LFmBdMwbYE SZ9iiNiK+b8tYB8Ct0FBNEkWbJlECmw== X-MHO-RoutePath: aGlwcGll X-MHO-User: 7b6ff382-4085-11eb-8b5f-614106969e8d X-Report-Abuse-To: https://support.duocircle.com/support/solutions/articles/5000540958-duocircle-standard-smtp-abuse-information X-Originating-IP: 67.177.211.60 X-Mail-Handler: DuoCircle Outbound SMTP Received: from ilsoft.org (c-67-177-211-60.hsd1.co.comcast.net [67.177.211.60]) by outbound3.ore.mailhop.org (Halon) with ESMTPSA id 7b6ff382-4085-11eb-8b5f-614106969e8d; Thu, 17 Dec 2020 16:32:45 +0000 (UTC) Received: from rev (rev [172.22.42.240]) by ilsoft.org (8.15.2/8.15.2) with ESMTP id 0BHGWeLM058596; Thu, 17 Dec 2020 09:32:40 -0700 (MST) (envelope-from ian@freebsd.org) Message-ID: <452cbb1060b7134315999c2323ed431714dc03fe.camel@freebsd.org> Subject: Re: svn commit: r368714 - head/lib/libc/string From: Ian Lepore To: Konstantin Belousov , Jessica Clarke Cc: Mateusz Piotrowski <0mp@freebsd.org>, src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Date: Thu, 17 Dec 2020 09:32:40 -0700 In-Reply-To: References: <202012171241.0BHCfl1r008452@repo.freebsd.org> <686CF2E6-1D3C-4A83-A323-02CD9F536675@freebsd.org> Content-Type: text/plain; charset="ASCII" X-Mailer: Evolution 3.28.5 FreeBSD GNOME Team Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 4CxcxL3YDnz3s9f 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-head@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Dec 2020 16:33:10 -0000 On Thu, 2020-12-17 at 18:22 +0200, 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: > > > > > > 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 > > > > > > > > Log: > > > > strerror.3: Add an example for perror() > > > > > > > > This is a nice and quick reference. > > > > > > > > Reviewed by: jilles, yuripv > > > > MFC after: 2 weeks > > > > Differential Revision: https://reviews.freebsd.org/D27623 > > > > > > > > Modified: > > > > head/lib/libc/string/strerror.3 > > > > > > > > Modified: head/lib/libc/string/strerror.3 > > > > =============================================================== > > > > =============== > > > > --- 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 = open("/nonexistent", O_RDONLY)) == -1) { > > > > + perror("open()"); > > > > + exit(1); > > > > + } > > > > + printf("File descriptor: %d\en", fd); > > > > > > This lines is indented with spaces, while other lines have tabs. > > > > > > > + return (0); > > > > > > return (0) is redundand. > > > > 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 ? > > 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. I completely disagree. Writing example code where you fail to return a value and just fall out the bottom of some function that declares it returns an int is just Bad Code. Using some obscure quirk of the language as justification for that bad code doesn't help the situation at all. How obscure is this quirk? I've been writing C code since 1983, including having released a freeware compiler (pre-gcc days) and working on a commercial C compiler. I used to moderate the c_language conference on BIX (back when that was a thing). I make my living writing C and C++ code every day. And yet, I had completely forgotten about this quirk. Example code shouldn't be used to establish how much more clever you are than the reader, it should be as easy to understand as possible. -- Ian