Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Writing C code and trying to keep it indented was a bit of a pain and I wish I would have done something else. I believe some compilers write ugly code and then “pretty it up” with a library before writing it out. This is something to explore!

There's a tool for this nowadays: `clang-format`.



And if you only trust tools old enough to drink, you can use `indent`.

https://www.gnu.org/software/indent/manual/indent.html


+1 for clang-format. I have been using it as a beautifier on generated code in a TypeScript to C++ compiler.

There are some other features I wish it did for me in cleaning up my generated code. For example it doesn't remove superfluous parenthesis. It doesn't remove unused labels. It doesn't remove superfluous semi-colons (a single line of just a semi-colon). And so on. (I should, of course, just be building up an AST and pretty-printing the AST instead.)


clang-tidy?


Haven't looked into it. Thanks!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: