C++ 最好的漂亮打印选项是什么? 代码?

发布于 2024-07-26 16:24:42 字数 1455 浏览 1 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

隐诗 2024-08-02 16:24:43

看看 Vera++

Take a look at Vera++

初懵 2024-08-02 16:24:43

嗯,我非常喜欢它。 它与 astyle 不同吗? Astyle 对于这种事情非常有效。

Well, I like it very much. Is it different to astyle though? Astyle works pretty well for this kind of thing.

霊感 2024-08-02 16:24:43

据我所知,一般的智慧是选择一种风格并与之相配。 其实选择什么风格并不重要,只要你选择一种即可。 请参阅 python,这是该语言强制执行特定风格的一个很好的示例,虽然它让某些人感到厌烦,但它的效果非常好。

我想人们往往关心的是

  • 缩进、空格与制表符以及空格数量(或制表符代表的空格数量)
  • 大括号在
  • 运算符周围有空格 for(int i=0... vs for(int i = 0...
  • if 之前的空格 (

我不会感兴趣的事情:

  • 对类的成员进行排序
  • 自动执行变量命名方案(它们应该是 。
  • 行长度限制对我来说是一个棘手的问题,具体取决于我们代码的哪个区域,我将严格使用 80。但实际上,现代 IDE 可以处理更长的行,而不会遇到太多麻烦 但无论怎样,打印都很难实现自动化,太多的极端情况会带来麻烦,需要进行调整。

As far as I know the general wisdom is pick a style and go with it. It doesn't really matter too much what style you pick as long as you pick one. See python for a good example of the language enforcing a particular style and, while it irks some people, it works pretty well.

I guess the one's that people tend to care about are

  • indenting, spaces vs tabs and number of spaces (or number of spaces the tabs represent)
  • Where the brace goes
  • spaces around operators for(int i=0... vs for(int i = 0...
  • spaces after if before the (

Things I wouldn't be as interested in:

  • Sorting the members of a class
  • Enforcing variable naming schemes automagically (they should be in place but there are too many corner cases that cause trouble)
  • Line length limits are a sore issue for me. Depending on what area of our code I will strictly use 80. But really, modern IDEs can deal with longer lines without too much trouble. But then printing becomes a pain. No matter what this is very hard to automate well. Again too many corner cases that cause trouble and would need to be tweaked.
枉心 2024-08-02 16:24:43

样式格式化程序怎么样? ,格式根据:gnu、bsd、k&r 等

例如 http://en.wikipedia.org/wiki/Indent_style

How about a style formatter. e.g. format according to: gnu, bsd, k&r etc

e.g. http://en.wikipedia.org/wiki/Indent_style

琉璃梦幻 2024-08-02 16:24:42

我在代码格式化程序中错过的一件事是它为我提供了有关代码结构的更多提示。 我经常发现自己缩进几乎相等的语句的连续行来突出它们的对应关系和差异,就像这样:

auto_ptr<Base::Int> x1 = get<DataModelI::Base::Int>( context, c_Input1 );
auto_ptr<Base::Real> x2 = get<DataModelI::Base::Real>( context, c_Input2 );
auto_ptr<Composite::Array> x3 = get<Composite::Array>( context, c_Input3 );
auto_ptr<Base::Real> x4 = get<DataModelI::Base::Real>( context, c_Input4 );

auto_ptr<Base::Int       > x1 = get<DataModelI::Base::Int >( context, c_Input1 );
auto_ptr<Base::Real      > x2 = get<DataModelI::Base::Real>( context, c_Input2 );
auto_ptr<Composite::Array> x3 = get<Composite::Array      >( context, c_Input3 );
auto_ptr<Base::Real      > x4 = get<DataModelI::Base::Real>( context, c_Input4 );

完全是无法维护的:当添加另一条更长的行时,我会浪费时间缩进所有先前的行。 是的,我确实阅读了《Code Complete》并部分同意他们对此的声明:)

如果您可以向观众添加这种(非常人性化且主观的)审美启发式,我将很高兴听到它。

我希望我的代码尽可能清晰。 在我梦想的代码查看器中,我可以切换查看 using 声明 - 也许我什至不需要它们:我可以切换完整命名空间查看,可以隐藏局部变量声明以仅关注控制流, ...

One thing I miss in code formatters is something that gives me more hints about the structure of the code. I often find myself indenting consecutive lines of almost-equal statements to highlight their correspondances and differences, much like this:

auto_ptr<Base::Int> x1 = get<DataModelI::Base::Int>( context, c_Input1 );
auto_ptr<Base::Real> x2 = get<DataModelI::Base::Real>( context, c_Input2 );
auto_ptr<Composite::Array> x3 = get<Composite::Array>( context, c_Input3 );
auto_ptr<Base::Real> x4 = get<DataModelI::Base::Real>( context, c_Input4 );

into that

auto_ptr<Base::Int       > x1 = get<DataModelI::Base::Int >( context, c_Input1 );
auto_ptr<Base::Real      > x2 = get<DataModelI::Base::Real>( context, c_Input2 );
auto_ptr<Composite::Array> x3 = get<Composite::Array      >( context, c_Input3 );
auto_ptr<Base::Real      > x4 = get<DataModelI::Base::Real>( context, c_Input4 );

This is totally unmaintainable: when another, longer, line is added, I lose time indenting all previous lines. And yes, I did read Code Complete and partially agree with their statement about this :)

If you can add this (quite human, and subjective) aesthetic heuristic to a viewer, I would be pleased to hear from it.

I want my code as clear as possible. In my dream code viewer, I can toggle viewing using declarations - maybe I don't even need them: I can toggle full-namespace viewing, can hide local variable declarations to just focus on the control flow, ...

小矜持 2024-08-02 16:24:42

GNU Indent 是一个为 C 或 C++ 设计的自动缩进程序。 如果您愿意,可以查看选项或来源。

GNU Indent is an auto-indent program designed for C or C++. You can take a look at the options or the source if you'd like.

小霸王臭丫头 2024-08-02 16:24:42

我建议看一下 eclipses 代码格式化程序。 它可能适用于 Java,但它仍然有很多适用于 C++ 的选项。 否则,你目前所拥有的对我来说看起来不错,但可能有点稀疏......我会详细说明一下,但我现在没有时间,我相信其他人也会回答......另外

,Eclipse 确实支持 C++,但我以前从未看过它,但我认为它也有一个代码格式化程序。

I would suggest taking a look at eclipses code formatter. It may be for Java, but it still has a lot of options that would apply to C++. Otherwise, what you currently have looks good to me, but maybe a bit sparse... I would elaborate a bit more, but I don't have the time right now, and I'm sure someone else will answer as well...

Also, Eclipse does have support for C++, but I've never looked at it before, but I'd assume it would have a code formatter as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文