From patchwork Sat May 18 17:00:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marvin Scholz X-Patchwork-Id: 48989 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:3a48:b0:1af:fc2d:ff5a with SMTP id zu8csp3543876pzb; Sat, 18 May 2024 10:03:13 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVtoaiTS11VBL5tZOWJnjlkmka5OpcyADy5g+BuxlYmtFo5pio0DGTRTF2W+2ZuFrBKOME45iHRNLleDqHHkPIX3SPZ7VbIyE6/Zg== X-Google-Smtp-Source: AGHT+IEJNt9PulmgKdEbWNnVpJOi2gNSS7mB1ewmlt6N4hgLrSQB9diCBA+1uqfie5w9Xi+hK1BW X-Received: by 2002:a05:6512:3b08:b0:522:2c9b:63b7 with SMTP id 2adb3069b0e04-5222c9b648bmr18248494e87.14.1716051792846; Sat, 18 May 2024 10:03:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1716051792; cv=none; d=google.com; s=arc-20160816; b=C7owvt6LWx1rhrsFeydgySNR4ZjKm8ExGxWr2AgiaDkM25OBpmpzkBS0QJXrZBvmwZ eLr+vJaMhSAxVb+QJOBnv/dWmuFR3PRr+h6irSqU6lbNUWLDVWT1iUGiVHeFLv2JZ1Rc 7+9jyGsjnw6qN4a0XrU8RTVIp+wOYhSmcQ5fr/i9ieUFzKi6et/FiE//yzx5xhQf7BT4 73NFinnCVEc17UlbMcRD7xUyaI1UhUC+63nO3RvQezJ26FmuF+/3caKR8lNNgKEsgNNW VEfwspjspDESIepjZ33EY1EVyr0Jw+yrjDfNQNFivNO7TneiZw64wyDJN2Cw3mUfq+NL xpPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:date:from:to:message-id:dkim-signature :delivered-to; bh=zv7Z4PIFPaw83upD73+7Xg0BTAK6IQhbeA6FTKaWp2w=; fh=5IeVwzS1vbVKjIV8MP3mnmnRtZGb8uteQ9r4QD2keV0=; b=vra1IPAq/ezZB4yfrc72G4aN57BHw+FOGkhEjHNh+K5zE8pWCwIu2zkJd1UViXK2Md D6ayQxtM4sLie/38LcY81TDPv0wKO6bjwJ3LN4uPwqQi08IyFi3sg0EIp1DanNmnj1EV PqTFD8LGHJuUfTceLq263cQJ325mGQxw/nmekY3azvnGxiuKfWvcgivoMsVNjXDnc4Yh XZ0mA/lXuqGJgdYYWtJUUBAdiMtWt5kog2aN2uF6SXlIPFnls6whJTVkdDH0CQ87lb8R NCmtDSqwtTMDnUdC1AKwgkMJCapjJBsks2vDnjoTk6JE6DbFkT5GlWeKTFfLklU02X6O P1CA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=gmX3aC+w; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a5a1797bf34si1147782066b.243.2024.05.18.10.03.12; Sat, 18 May 2024 10:03:12 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=gmX3aC+w; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7C6BC68CE03; Sat, 18 May 2024 20:03:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B2F4468CA8A for ; Sat, 18 May 2024 20:03:03 +0300 (EEST) Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-51ff65b1e14so3434497e87.2 for ; Sat, 18 May 2024 10:03:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716051782; x=1716656582; darn=ffmpeg.org; h=subject:date:from:to:message-id:from:to:cc:subject:date:message-id :reply-to; bh=hOMVLEDPRCmzsidcGVOqqkY8nTnGG4CUoDz6QTb3KaA=; b=gmX3aC+wQTa6VPMFBydt4lSLGCuR9LNxnqXYTsnqVmzPwgRpsF4/UTwyCGCRUUpng9 PnyWgZZcWG0AvqdVFTheFeR8TMGpTpL0D25WZtbdA1GqU0JDboPSfHPzj3qsBY/6oRhu ORGCl60pkJZulv2Xai10sU04mRG3AaMydUgz58zJyPQVR/+k7fWLQxbr0C6gY/RETel8 f7OBk3C/Q0zOP+j+b+SQEFIETbN2In1yOJgUc8SVuLsDNqdrIQTcp6e+ZS3MtPTIxEz/ vBR3wmibMQqvrE7FEPY+28Y298JdVTr7cMiMaG+gVCk0cRBfjhqVClaOD4lU8lAX+CLA KY6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716051782; x=1716656582; h=subject:date:from:to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hOMVLEDPRCmzsidcGVOqqkY8nTnGG4CUoDz6QTb3KaA=; b=bq+QzrUQUumO1CHs+obTapYk3/UQTlECMn4mmr8hDQe6U2pLPE8FjR4jrk/DThTnzM 5nAD8hNFTUb8hqpZADiLZ1IGu3welA/Xti/KgG6xpCU9dCRmIfZL9zbo988uhcuRj9Sz o4mhCyoStV0Bw/KC6BiUqxUx/WEQQ9OXZVPSzP4V7AqzeVYsN6MQPhlUgvWKln877tSs iBhNo7reR2gSXX5Wks/G4avrRxLnG2NlPNSrdPRp0zdLHMg/HrtucmQg/xfgzl7p7NYS Im9S1vc2Dx8hG+QIHRWI4w1Z3iQtjYY4LtyUAuUstnwCY4cq4CNCVOu055JPXwMWamLX EwVA== X-Gm-Message-State: AOJu0YyiEiiCLe+3P2n7X2qcBHC0EXq1YcPillaShY4BzCzKt9Uednjx BRS/vBjT6jnjRRVdTH0aKc14y1Wio9G/qjjyFVaP7Y8KW9ouYBUVRRw75Q== X-Received: by 2002:a05:6512:b81:b0:51e:f7de:d8eb with SMTP id 2adb3069b0e04-5220fb76879mr20826424e87.10.1716051782048; Sat, 18 May 2024 10:03:02 -0700 (PDT) Received: from localhost (dynamic-2a01-0c23-5cdf-1c00-28f3-4e89-826e-7677.c23.pool.telefonica.de. [2a01:c23:5cdf:1c00:28f3:4e89:826e:7677]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5a17b015besm1258793766b.144.2024.05.18.10.03.00 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 18 May 2024 10:03:00 -0700 (PDT) Message-Id: To: From: "Marvin Scholz" Date: Sat, 18 May 2024 19:00:50 +0200 Subject: [FFmpeg-devel] [PATCH] doc/developer: add examples to clarify code style X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: qXAntfeOQuL+ Given the frequency that new developers, myself included, get the code style wrong, it is useful to add some examples to clarify how things should be done. --- doc/developer.texi | 57 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) base-commit: 86e418ffd7bbdc0530e1e4d5bd7534b6e03b5b05 diff --git a/doc/developer.texi b/doc/developer.texi index 63835dfa06..d7bf3f9cb8 100644 --- a/doc/developer.texi +++ b/doc/developer.texi @@ -115,7 +115,7 @@ Objective-C where required for interacting with macOS-specific interfaces. @section Code formatting conventions -There are the following guidelines regarding the indentation in files: +There are the following guidelines regarding the code style in files: @itemize @bullet @item @@ -135,6 +135,61 @@ K&R coding style is used. @end itemize The presentation is one inspired by 'indent -i4 -kr -nut'. +@subsection Examples +Some notable examples to illustrate common code style in FFmpeg: + +@itemize @bullet + +@item +Spaces around @code{if}/@code{do}/@code{while}/@code{for} conditions and assigments: + +@example c +if (condition) + av_foo(); +@end example + +@example c +for (size_t i = 0; i < len; i++) + av_bar(i); +@end example + +@example c +size_t size = 0; +@end example + +However no spaces between the parentheses and condition, unless it helps +readability of complex conditions, so the following should not be done: + +@example c +// Wrong: +if ( cond ) + av_foo(); +@end example + +@item +No unnecessary parentheses, unless it helps readability: + +@example c +flags = s->mb_x ? RIGHT_EDGE : LEFT_EDGE | RIGHT_EDGE; +@end example + +@item +No braces around single-line blocks: + +@example c +if (bits_pixel == 24) + avctx->pix_fmt = AV_PIX_FMT_BGR24; +else if (bits_pixel == 8) + avctx->pix_fmt = AV_PIX_FMT_GRAY8; +else @{ + av_log(avctx, AV_LOG_ERROR, "Invalid pixel format.\n"); + return AVERROR_INVALIDDATA; +@} +@end example + +@end itemize + + @subsection Vim configuration In order to configure Vim to follow FFmpeg formatting conventions, paste the following snippet into your @file{.vimrc}: