- 论坛徽章:
- 4
|
本帖最后由 linux_c_py_php 于 2013-01-31 17:18 编辑
这里所指的 " 代码风格 " 是指 单纯的排版, 即indent工具能够取代我们做到的事情.
最近偶然看到一种个性的风格, 发现非常美观, 一句话总结就是: 多使用水平留白, 尽可能使用大段的留白对齐代码, 可以显著地增加代码的 层叠感 与 优雅程度.
平时写代码也会刻意的留白对齐, 但实际编码反复修改, 没有形成习惯.
大家刻意注意到括号内部两侧全都留白了, 甚至[ 这里也留白了 ], 如果整片采用这种风格, 最后代码看起来特别的清晰.
大家看一下这种风格如何? 留下你觉得漂亮的排版.- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main( int argc, char* const argv[] ) {
- int i = 2;
- short j = 3;
- char line[ 5 ] = { '\0' };
-
- while ( fgets( line, sizeof( line ), stdin ) != NULL) {
- int len = strlen( line );
- if ( line[ len - 1 ] != '\n' ) {
- printf( "line is too long" );
- }
- }
-
- return 0;
- }
复制代码 |
|