Date: Tue, 23 Jan 2024 09:41:01 +0000 From: David Chisnall <theraven@FreeBSD.org> To: "Robert R. Russell" <robert@rrbrussell.com> Cc: freebsd-hackers@freebsd.org Subject: Re: The Case for Rust (in the base system) Message-ID: <D846A8E3-1FE3-4A82-B9C3-5FA3BE7406A0@FreeBSD.org> In-Reply-To: <20240122164543.066e3cec@venus.private.rrbrussell.com> References: <CAOtMX2hAUiWdGPtpaCJLPZB%2Bj2yzNw5DSjUmkwTi%2B%2BmyemehCA@mail.gmail.com> <1673801705774097@mail.yandex.ru> <CANCZdfpqWgvV_RCvVO_pvTrmajQFspW%2BQ9TM_Ok3JrXZAfeAfA@mail.gmail.com> <ef4ad207-5899-42b6-8728-bc46f1417e9e@antonovs.family> <202401210751.40L7pWEF011188@critter.freebsd.dk> <20240121102421.GE14773@memo2.memo.frmug.org> <2f38cbcd-61a9-42b7-b7e6-ebd261fe66da@FreeBSD.org> <20240122164543.066e3cec@venus.private.rrbrussell.com>
next in thread | previous in thread | raw e-mail | index | archive | help
--Apple-Mail=_D32357AB-84CC-416C-992B-1A0C0BCFDB0C Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 On 22 Jan 2024, at 22:45, Robert R. Russell <robert@rrbrussell.com> = wrote: >=20 > Having had the luxury or curse of not being stuck with only one > programming language I have learned usable pieces of several. C++ is > not on that list even though I have the most formal education in it. > My best way of answering why is this. Would you write or use a C++ > codebase maintained by the average developer with just Vi? Up to C++03 > I can say yes, after that the answer is no. I have no idea what this means. There=E2=80=99s absolutely nothing in = newer C++ that makes it harder to write with a text editor. There is a = lot that makes it easier to write correctly. For reference LLVM is about 4MLoC (and about 5M lines of comments, = something that FreeBSD could definitely learn from) and is written in = modern C++. I don=E2=80=99t think I=E2=80=99ve ever used an editor = other than vim to work on it. I don=E2=80=99t use nvi, because it=E2=80=99= s not the =E2=80=9880s anymore. I use ALE with vim, which integrates with clangd via LSP and provides = autocompletion and error reporting for anything that can generate a = compile_commands.json. That=E2=80=99s not specific to C++. I = wouldn=E2=80=99t want to write C without syntax highlighting, = autocompletion, or live error checking either. It=E2=80=99s possible to = do so for C or C++, but you=E2=80=99ll be less productive. > A consequence of Microsoft's "Welcome back to C++" item that may have > gotten missed is what resources are they spending to enforce = compliance > with a certain C++ standard? I have no idea what this means. =E2=80=98Compliance with a certain C++ = standard=E2=80=99 is a thing that your compiler tells you when you try = to compile. =20 > Particularly, to enforce the restrictions on anti-patterns? That varies from project to project. I generally use clang-tidy and = clang-format in pre-merge hooks in CI for the projects that I worked on = at MS and that I work on personally. And, of course, code review. = Automated tooling is no substitute for code review. =20 > Cargo needs approximately a dozen lines in a > configuration file to restrict its upstream sources. That includes > whitespace and formatting. Here is the script that runs formatting and static analysis across a = codebase that I maintain: = https://github.com/microsoft/cheriot-rtos/blob/main/scripts/run_clang_tidy= _format.sh Almost all of the complexity is in *not* running it on files that we = have imported from elsewhere or where, for compliance with external = standards, we don=E2=80=99t want to enforce our naming rules, and for = finding the relevant toolchain files. The actual checker bit is right = at the end. Most projects run this kind of check through their build system, but we = wanted to run it on headers in isolation as well as on full compilation = units. =20 David --Apple-Mail=_D32357AB-84CC-416C-992B-1A0C0BCFDB0C Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 <html><head><meta http-equiv=3D"content-type" content=3D"text/html; = charset=3Dutf-8"></head><body style=3D"overflow-wrap: break-word; = -webkit-nbsp-mode: space; line-break: after-white-space;">On 22 Jan = 2024, at 22:45, Robert R. Russell <robert@rrbrussell.com> = wrote:<br><div><blockquote type=3D"cite"><br = class=3D"Apple-interchange-newline"><div><span style=3D"caret-color: = rgb(0, 0, 0); font-family: SourceCodePro-Regular; font-size: 12px; = font-style: normal; font-variant-caps: normal; font-weight: 400; = letter-spacing: normal; text-align: start; text-indent: 0px; = text-transform: none; white-space: normal; word-spacing: 0px; = -webkit-text-stroke-width: 0px; text-decoration: none; float: none; = display: inline !important;">Having had the luxury or curse of not being = stuck with only one</span><br style=3D"caret-color: rgb(0, 0, 0); = font-family: SourceCodePro-Regular; font-size: 12px; font-style: normal; = font-variant-caps: normal; font-weight: 400; letter-spacing: normal; = text-align: start; text-indent: 0px; text-transform: none; white-space: = normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; = text-decoration: none;"><span style=3D"caret-color: rgb(0, 0, 0); = font-family: SourceCodePro-Regular; font-size: 12px; font-style: normal; = font-variant-caps: normal; font-weight: 400; letter-spacing: normal; = text-align: start; text-indent: 0px; text-transform: none; white-space: = normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; = text-decoration: none; float: none; display: inline = !important;">programming language I have learned usable pieces of = several. C++ is</span><br style=3D"caret-color: rgb(0, 0, 0); = font-family: SourceCodePro-Regular; font-size: 12px; font-style: normal; = font-variant-caps: normal; font-weight: 400; letter-spacing: normal; = text-align: start; text-indent: 0px; text-transform: none; white-space: = normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; = text-decoration: none;"><span style=3D"caret-color: rgb(0, 0, 0); = font-family: SourceCodePro-Regular; font-size: 12px; font-style: normal; = font-variant-caps: normal; font-weight: 400; letter-spacing: normal; = text-align: start; text-indent: 0px; text-transform: none; white-space: = normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; = text-decoration: none; float: none; display: inline !important;">not on = that list even though I have the most formal education in it.</span><br = style=3D"caret-color: rgb(0, 0, 0); font-family: SourceCodePro-Regular; = font-size: 12px; font-style: normal; font-variant-caps: normal; = font-weight: 400; letter-spacing: normal; text-align: start; = text-indent: 0px; text-transform: none; white-space: normal; = word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: = none;"><span style=3D"caret-color: rgb(0, 0, 0); font-family: = SourceCodePro-Regular; font-size: 12px; font-style: normal; = font-variant-caps: normal; font-weight: 400; letter-spacing: normal; = text-align: start; text-indent: 0px; text-transform: none; white-space: = normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; = text-decoration: none; float: none; display: inline !important;">My best = way of answering why is this. Would you write or use a C++</span><br = style=3D"caret-color: rgb(0, 0, 0); font-family: SourceCodePro-Regular; = font-size: 12px; font-style: normal; font-variant-caps: normal; = font-weight: 400; letter-spacing: normal; text-align: start; = text-indent: 0px; text-transform: none; white-space: normal; = word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: = none;"><span style=3D"caret-color: rgb(0, 0, 0); font-family: = SourceCodePro-Regular; font-size: 12px; font-style: normal; = font-variant-caps: normal; font-weight: 400; letter-spacing: normal; = text-align: start; text-indent: 0px; text-transform: none; white-space: = normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; = text-decoration: none; float: none; display: inline = !important;">codebase maintained by the average developer with just Vi? = Up to C++03</span><br style=3D"caret-color: rgb(0, 0, 0); font-family: = SourceCodePro-Regular; font-size: 12px; font-style: normal; = font-variant-caps: normal; font-weight: 400; letter-spacing: normal; = text-align: start; text-indent: 0px; text-transform: none; white-space: = normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; = text-decoration: none;"><span style=3D"caret-color: rgb(0, 0, 0); = font-family: SourceCodePro-Regular; font-size: 12px; font-style: normal; = font-variant-caps: normal; font-weight: 400; letter-spacing: normal; = text-align: start; text-indent: 0px; text-transform: none; white-space: = normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; = text-decoration: none; float: none; display: inline !important;">I can = say yes, after that the answer is no.</span><br style=3D"caret-color: = rgb(0, 0, 0); font-family: SourceCodePro-Regular; font-size: 12px; = font-style: normal; font-variant-caps: normal; font-weight: 400; = letter-spacing: normal; text-align: start; text-indent: 0px; = text-transform: none; white-space: normal; word-spacing: 0px; = -webkit-text-stroke-width: 0px; text-decoration: = none;"></div></blockquote><div><br></div><div>I have no idea what this = means. There=E2=80=99s absolutely nothing in newer C++ that makes = it harder to write with a text editor. There is a lot that makes = it easier to write correctly.</div><div><br></div><div>For reference = LLVM is about 4MLoC (and about 5M lines of comments, something that = FreeBSD could definitely learn from) and is written in modern C++. = I don=E2=80=99t think I=E2=80=99ve ever used an editor other than = vim to work on it. I don=E2=80=99t use nvi, because it=E2=80=99s = not the =E2=80=9880s anymore.</div><div><br></div><div>I use ALE with = vim, which integrates with clangd via LSP and provides autocompletion = and error reporting for anything that can generate a = compile_commands.json. That=E2=80=99s not specific to C++. I = wouldn=E2=80=99t want to write C without syntax highlighting, = autocompletion, or live error checking either. It=E2=80=99s = possible to do so for C or C++, but you=E2=80=99ll be less = productive.</div><div><span style=3D"caret-color: rgb(0, 0, 0); = font-family: SourceCodePro-Regular; font-size: 12px; font-style: normal; = font-variant-caps: normal; font-weight: 400; letter-spacing: normal; = text-align: start; text-indent: 0px; text-transform: none; white-space: = normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; = text-decoration: none; float: none; display: inline = !important;"><br></span></div><blockquote type=3D"cite"><span = style=3D"caret-color: rgb(0, 0, 0); font-family: SourceCodePro-Regular; = font-size: 12px; font-style: normal; font-variant-caps: normal; = font-weight: 400; letter-spacing: normal; text-align: start; = text-indent: 0px; text-transform: none; white-space: normal; = word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: = none; float: none; display: inline !important;">A consequence of = Microsoft's "Welcome back to C++" item that may have</span><br = style=3D"caret-color: rgb(0, 0, 0); font-family: SourceCodePro-Regular; = font-size: 12px; font-style: normal; font-variant-caps: normal; = font-weight: 400; letter-spacing: normal; text-align: start; = text-indent: 0px; text-transform: none; white-space: normal; = word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: = none;"><span style=3D"caret-color: rgb(0, 0, 0); font-family: = SourceCodePro-Regular; font-size: 12px; font-style: normal; = font-variant-caps: normal; font-weight: 400; letter-spacing: normal; = text-align: start; text-indent: 0px; text-transform: none; white-space: = normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; = text-decoration: none; float: none; display: inline !important;">gotten = missed is what resources are they spending to enforce = compliance</span><br style=3D"caret-color: rgb(0, 0, 0); font-family: = SourceCodePro-Regular; font-size: 12px; font-style: normal; = font-variant-caps: normal; font-weight: 400; letter-spacing: normal; = text-align: start; text-indent: 0px; text-transform: none; white-space: = normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; = text-decoration: none;"><span style=3D"caret-color: rgb(0, 0, 0); = font-family: SourceCodePro-Regular; font-size: 12px; font-style: normal; = font-variant-caps: normal; font-weight: 400; letter-spacing: normal; = text-align: start; text-indent: 0px; text-transform: none; white-space: = normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; = text-decoration: none; float: none; display: inline !important;">with a = certain C++ standard? </span></blockquote><div><br></div><div>I have no = idea what this means. =E2=80=98Compliance with a certain C++ = standard=E2=80=99 is a thing that your compiler tells you when you try = to compile. </div><div><br></div><blockquote = type=3D"cite"><div><span style=3D"caret-color: rgb(0, 0, 0); = font-family: SourceCodePro-Regular; font-size: 12px; font-style: normal; = font-variant-caps: normal; font-weight: 400; letter-spacing: normal; = text-align: start; text-indent: 0px; text-transform: none; white-space: = normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; = text-decoration: none; float: none; display: inline = !important;">Particularly, to enforce the restrictions </span><span = style=3D"caret-color: rgb(0, 0, 0); font-family: SourceCodePro-Regular; = font-size: 12px; font-style: normal; font-variant-caps: normal; = font-weight: 400; letter-spacing: normal; text-align: start; = text-indent: 0px; text-transform: none; white-space: normal; = word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: = none; float: none; display: inline !important;">on anti-patterns? = </span></div></blockquote><div><br></div><div>That varies from project = to project. I generally use clang-tidy and clang-format in = pre-merge hooks in CI for the projects that I worked on at MS and that I = work on personally. And, of course, code review. Automated = tooling is no substitute for code review. </div><br><blockquote = type=3D"cite"><div><span style=3D"caret-color: rgb(0, 0, 0); = font-family: SourceCodePro-Regular; font-size: 12px; font-style: normal; = font-variant-caps: normal; font-weight: 400; letter-spacing: normal; = text-align: start; text-indent: 0px; text-transform: none; white-space: = normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; = text-decoration: none; float: none; display: inline !important;">Cargo = needs approximately a dozen lines in a</span><br style=3D"caret-color: = rgb(0, 0, 0); font-family: SourceCodePro-Regular; font-size: 12px; = font-style: normal; font-variant-caps: normal; font-weight: 400; = letter-spacing: normal; text-align: start; text-indent: 0px; = text-transform: none; white-space: normal; word-spacing: 0px; = -webkit-text-stroke-width: 0px; text-decoration: none;"><span = style=3D"caret-color: rgb(0, 0, 0); font-family: SourceCodePro-Regular; = font-size: 12px; font-style: normal; font-variant-caps: normal; = font-weight: 400; letter-spacing: normal; text-align: start; = text-indent: 0px; text-transform: none; white-space: normal; = word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: = none; float: none; display: inline !important;">configuration file to = restrict its upstream sources. That includes</span><br = style=3D"caret-color: rgb(0, 0, 0); font-family: SourceCodePro-Regular; = font-size: 12px; font-style: normal; font-variant-caps: normal; = font-weight: 400; letter-spacing: normal; text-align: start; = text-indent: 0px; text-transform: none; white-space: normal; = word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: = none;"><span style=3D"caret-color: rgb(0, 0, 0); font-family: = SourceCodePro-Regular; font-size: 12px; font-style: normal; = font-variant-caps: normal; font-weight: 400; letter-spacing: normal; = text-align: start; text-indent: 0px; text-transform: none; white-space: = normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; = text-decoration: none; float: none; display: inline = !important;">whitespace and = formatting.</span></div></blockquote></div><div><br></div><div>Here is = the script that runs formatting and static analysis across a codebase = that I maintain:</div><div><br></div><div><a = href=3D"https://github.com/microsoft/cheriot-rtos/blob/main/scripts/run_cl= ang_tidy_format.sh">https://github.com/microsoft/cheriot-rtos/blob/main/sc= ripts/run_clang_tidy_format.sh</a></div><div><br></div><div>Almost all = of the complexity is in *not* running it on files that we have imported = from elsewhere or where, for compliance with external standards, we = don=E2=80=99t want to enforce our naming rules, and for finding the = relevant toolchain files. The actual checker bit is right at the = end.<br></div><div><br></div><div>Most projects run this kind of check = through their build system, but we wanted to run it on headers in = isolation as well as on full compilation units. = </div><br><div>David</div><div><br></div></body></html>= --Apple-Mail=_D32357AB-84CC-416C-992B-1A0C0BCFDB0C--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?D846A8E3-1FE3-4A82-B9C3-5FA3BE7406A0>