5 ms·
The code style on this makes my eyes bleed. It was a long time since I saw anyone do "if () single statement; else { block of statements }" Making the first th
by procaryote 1y ago
The code style on this makes my eyes bleed. It was a long time since I saw anyone do "if () single statement; else { block of statements }"
Making the first thing a block doesn't add any lines and makes it less brittle, and makes future diffs better
And they do some weird alignment of assignments, and for some reason carry on adding extra spaces for some assignments even when they're alone in a block?
And they go out of their way to do pointer arithmetic rather than array operations that are more readable
And the code is essentially sscanf(str, "%%%2x", &value) plus some checks, so why not write that instead?
Also what kind of psycho uses CppStyleFunctionNames() in C?
- stevage 1y agoTbh it's been a while since I've seen anyone manually format code. Automatically formatted code definitely does help avoid certain kinds of bugs. Does C not have the equivalent of Prettier? I am curious what their editing process was that changed: > assert(isxdigit((src+1))); to > if (!isxdigit(src+1)) return '\0';
- commandersaki 1y agoDoes C not have the equivalent of Prettier? There is clang-format, but it is not always easy to use on a code base because you don't want to have it run on imported/3rd party source which may mix in with your regular source tree. I've been meaning to use it on a project but only have run on an explicit list of files.
- ciupicri 1y agoThere's the good old GNU indent https://www.gnu.org/software/indent/ https://www.gnu.org/software/indent/ > But even if you fail in getting emacs to do sane formatting, not everything is lost: use indent. > Now, again, GNU indent has the same brain-dead settings that GNU emacs has, which is why you need to give it a few command line options. However, that’s not too bad, because even the makers of GNU indent recognize the authority of K&R (the GNU people aren’t evil, they are just severely misguided in this matter), so you just give indent the options -kr -i8 (stands for K&R, 8 character indents), or use scripts/Lindent, which indents in the latest style. > indent has a lot of options, and especially when it comes to comment re-formatting you may want to take a look at the man page. But remember: indent is not a fix for bad programming. (Linux kernel coding style, https://www.kernel.org/doc/html/latest/process/coding-style.html#you-ve-made-a-mess-of-it https://www.kernel.org/doc/html/latest/process/coding-style....)
- 9029 1y ago> I am curious what their editing process was They said: > I typed in the new code as that's faster than modifying the existing code
- stevage 1y agoAh. I bet there's a lot of vim users violently disagreeing...
- lastdong 1y agoI was thinking the same thing; also being more explicit would have prevented the bug described in the first place
- zabzonk 1y ago> Also what kind of psycho uses CppStyleFunctionNames() in C? People influenced by the Win32 C API. I prefer it that way myself.
- pjmlp 1y agoThat style predates Windows.
- GabrielTFS 1y agoI would guess a significant portion of people using the style (if not most), did so inspired by Windows, though
- pjmlp 1y agoIt was common across all not UNIX operating systems. You will find it on MS-DOS, Amiga, OS/2, Mac OS. It was based on what was common in ALGOL derived languages. On UNIX you will find it on X Windows, and Motif.