Skip site navigation (1)Skip section navigation (2)
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

[-- Attachment #1 --]
On 22 Jan 2024, at 22:45, Robert R. Russell <robert@rrbrussell.com> wrote:
> 
> 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’s 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’t think I’ve ever used an editor other than vim to work on it.  I don’t use nvi, because it’s not the ‘80s 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’s not specific to C++.  I wouldn’t want to write C without syntax highlighting, autocompletion, or live error checking either.  It’s possible to do so for C or C++, but you’ll 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.  ‘Compliance with a certain C++ standard’ is a thing that your compiler tells you when you try to compile.  

> 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.  

> 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’t 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.  

David


[-- Attachment #2 --]
<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">On 22 Jan 2024, at 22:45, Robert R. Russell &lt;robert@rrbrussell.com&gt; wrote:<br><div><blockquote type="cite"><br class="Apple-interchange-newline"><div><span style="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="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="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="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="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="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="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="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="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="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="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="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. &nbsp;There’s absolutely nothing in newer C++ that makes it harder to write with a text editor. &nbsp;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++. &nbsp;I don’t think I’ve ever used an editor other than vim to work on it. &nbsp;I don’t use nvi, because it’s not the ‘80s 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. &nbsp;That’s not specific to C++. &nbsp;I wouldn’t want to write C without syntax highlighting, autocompletion, or live error checking either. &nbsp;It’s possible to do so for C or C++, but you’ll be less productive.</div><div><span style="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="cite"><span style="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="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="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="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="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. &nbsp;‘Compliance with a certain C++ standard’ is a thing that your compiler tells you when you try to compile. &nbsp;</div><div><br></div><blockquote type="cite"><div><span style="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&nbsp;</span><span style="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. &nbsp;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. &nbsp;And, of course, code review. &nbsp;Automated tooling is no substitute for code review. &nbsp;</div><br><blockquote type="cite"><div><span style="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="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="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="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="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="https://github.com/microsoft/cheriot-rtos/blob/main/scripts/run_clang_tidy_format.sh">https://github.com/microsoft/cheriot-rtos/blob/main/scripts/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’t want to enforce our naming rules, and for finding the relevant toolchain files. &nbsp;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. &nbsp;</div><br><div>David</div><div><br></div></body></html>

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?D846A8E3-1FE3-4A82-B9C3-5FA3BE7406A0>