不是一个很好的主意! [英] Not a very good Idea!

查看:69
本文介绍了不是一个很好的主意!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

根据我们的编码规则,一行不应超过80个字符。

当访问深层嵌套的结构元素时,我们是不是

能够遵循这条规则。为了实现这一点,我们可以使用宏吗?


例如,


struct1.str1.strct3 = struct2.str2.st1.s1 + struct3 .str3.st3.s3;


#define STRUCT2 struct2.str2.st1.s1

#define STRUCT3 struct3.str3.st3.s3


然后使用


struct1.str1.strct3 = STRUCT2 + STRUCT3;


这是一个好的想法(如果没有,请告诉我它可能会导致什么问题)?或者有更好的想法吗?

解决方案



2005年4月3日星期一 va ****** @ rediffmail.com 写道:


大家好,
根据我们的编码规则,一行不应超过80个字符。
访问深层嵌套的结构元素,我们无法遵循此规则。要实现这一点,我们可以使用宏吗?


哦,亲爱的。

例如,

struct1.str1.strct3 = struct2.str2.st1.s1 + struct3 .str3.st3.s3;




首先,这个列少于80列。其次,C编程

语言是空格不敏感的(在大多数情况下),所以你总是可以写


struct1.str1.strct3 = struct2.str2 .st1.s1

+ struct3.str3.st3.s3;


一个更好的选择是重写你的数据结构,并使用

更简单


x = y + z;


当然,这需要摆脱很多微小的中间体

结构定义(struct1,str1,st1,s1等)。但这是一个非常好的事情。嵌套结构对于可读性是不利的,并且大多数情况下都是糟糕的

一般来说。


如果你做不到(例如,如果你有的话)更愚蠢的房屋规则

需要大量嵌套数据结构),你可以使用


struct foo * p =& struct2.str2。 st1;

struct foo * q =& struct3.str3.st3;


struct1.str1.strct3 = p-> s1 + q-> ; s3;


再一次,不是最好的解决方案,但是比尝试使用预处理器摆脱你自己创建的问题更好

有嵌套数据结构。


HTH,

-Arthur


< blockquote> va******@rediffmail.com 写道:

根据我们的编码规则,一行不应超过80个字符。
当访问深层嵌套的结构元素时,我们无法遵循这个ULE。为了实现这一点,我们可以使用宏吗?

例如,

struct1.str1.strct3 = struct2.str2.st1.s1 + struct3.str3.st3.s3;

#define STRUCT2 struct2.str2.st1.s1
#define STRUCT3 struct3.str3.st3.s3

然后使用

struct1.str1.strct3 = STRUCT2 + STRUCT3;

这是一个好主意(如果没有请让我知道它可能导致的问题)?或者是否有一个更好的想法这个?




struct1.str1.strct3 = struct2.str2.st1.s1 + struct3.str3.st3.s3;


显然少于80列,但假设它的意思是

的例子,那么它就没有理由在一条线上。

以下是等价的:


struct1.str1.strct3 =

struct2.str2.st1.s1 + struct3.str3 .st3.s3;


struct1.str1.strct3 =

struct2.str2.st1.s1 +

struct3.str3 .st3.s3;


struct1

.str1

.strct3

=

struct2

.str2

.st1

.s1

+

struct3

.str3

.st3

.s3;


可能更好地重构你的代码,所以你没有使用那么多深层嵌套的结构。


-

Keith Thompson(The_Other_Keith) ks***@mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。


Keith Thompson写道:

struct1.str1.strct3 =
struct2。 str2.st1.s1 +
struct3.str3.st3.s3;




我更喜欢开始,而不是终止,

a继续与二元运算符一致,

使它更加明显,它是一条持续线。


struct1.str1.strct3
= struct2.str2.st1.s1

+ struct3.str3.st3.s3;


-

pete


Hi all,
As per our coding rule, a line should not have more than 80 characters.
When accessing a structure elements which are deeply nested, we are not
able follow this rule. To acheive this Can we use macro?

For example,

struct1.str1.strct3=struct2.str2.st1.s1 + struct3.str3.st3.s3;

#define STRUCT2 struct2.str2.st1.s1
#define STRUCT3 struct3.str3.st3.s3

and then use

struct1.str1.strct3 = STRUCT2 + STRUCT3;

Is this a good Idea(if not please let me know what are the problems it
may cause)?Or Is there a better Idea than this?

解决方案


On Mon, 3 Apr 2005 va******@rediffmail.com wrote:


Hi all,
As per our coding rule, a line should not have more than 80 characters.
When accessing a structure elements which are deeply nested, we are not
able follow this rule. To acheive this Can we use macro?
Oh, dear.
For example,

struct1.str1.strct3=struct2.str2.st1.s1 + struct3.str3.st3.s3;



First of all, that''s fewer than 80 columns. Secondly, the C programming
language is whitespace-insensitive (in most ways), so you can always write

struct1.str1.strct3 = struct2.str2.st1.s1
+ struct3.str3.st3.s3;

A much better alternative is to rework your data structure, and use the
much simpler

x = y + z;

Of course, this will require getting rid of a lot of tiny intermediate
struct definitions (struct1, str1, st1, s1, and so on). But that''s a
very good thing. Nested structs are bad for readability, and mostly bad
for thinking in general.

If you can''t do that (for example, if you have more silly "house rules"
that require lots of nested data structures), you can use

struct foo *p = &struct2.str2.st1;
struct foo *q = &struct3.str3.st3;

struct1.str1.strct3 = p->s1 + q->s3;

Again, not the best solution, but a darn sight better than trying to
use the preprocessor to wiggle out of a problem you yourself created
with nested data structures.

HTH,
-Arthur


va******@rediffmail.com writes:

As per our coding rule, a line should not have more than 80 characters.
When accessing a structure elements which are deeply nested, we are not
able follow this rule. To acheive this Can we use macro?

For example,

struct1.str1.strct3=struct2.str2.st1.s1 + struct3.str3.st3.s3;

#define STRUCT2 struct2.str2.st1.s1
#define STRUCT3 struct3.str3.st3.s3

and then use

struct1.str1.strct3 = STRUCT2 + STRUCT3;

Is this a good Idea(if not please let me know what are the problems it
may cause)?Or Is there a better Idea than this?



struct1.str1.strct3=struct2.str2.st1.s1 + struct3.str3.st3.s3;

is obviously less than 80 columns, but assuming it''s meant as an
example, there''s no reason it all has to be on one line. The
following are equivalent:

struct1.str1.strct3 =
struct2.str2.st1.s1 + struct3.str3.st3.s3;

struct1.str1.strct3 =
struct2.str2.st1.s1 +
struct3.str3.st3.s3;

struct1
.str1
.strct3
=
struct2
.str2
.st1
.s1
+
struct3
.str3
.st3
.s3;

It would probably be even better to restructure your code so you''re
not using so many deeply nested structures.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


Keith Thompson wrote:

struct1.str1.strct3 =
struct2.str2.st1.s1 +
struct3.str3.st3.s3;



I prefer to start, rather than to terminate,
a continued line with a binary operator,
to make it more obvious that it''s a continued line.

struct1.str1.strct3
= struct2.str2.st1.s1
+ struct3.str3.st3.s3;

--
pete


这篇关于不是一个很好的主意!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆