Redian新闻
>
问个programming style 的问题 (转载)
avatar
问个programming style 的问题 (转载)# Java - 爪哇娇娃
s*p
1
【 以下文字转载自 Programming 讨论区 】
发信人: startup (startup), 信区: Programming
标 题: 问个programming style 的问题
发信站: BBS 未名空间站 (Thu Aug 24 14:32:45 2006)
I have one line code:
return mapping.findForward( s.login( u.getUsername(), u.getPassword()));
Should I write 4 lines like
String username = u.getUsername();
String passwrod = u.getPassword();
String retval = s.login( username, password );
return mapping.findForward( retval );
多谢指教!
avatar
g*g
2
If you don't resue username, password, retval,
the style is fine as long as the logic's easy to understand.
t

);

【在 s*****p 的大作中提到】
: 【 以下文字转载自 Programming 讨论区 】
: 发信人: startup (startup), 信区: Programming
: 标 题: 问个programming style 的问题
: 发信站: BBS 未名空间站 (Thu Aug 24 14:32:45 2006)
: I have one line code:
: return mapping.findForward( s.login( u.getUsername(), u.getPassword()));
: Should I write 4 lines like
: String username = u.getUsername();
: String passwrod = u.getPassword();
: String retval = s.login( username, password );

avatar
c*t
3
Either is fine.
I write long code lines too, although sometimes I would break them up
to limit the # of nested (), or if the line gets too long. Sometimes
when I debug intermediate values, the long line gets broken up too.
The bottomline is readability. Although breaking them up helps reading
the particular line better, it may obscure the flow of code reading.
I sometimes pay more attention to a big block of code, but if is only a
simple thing, it would waste my energy.

);

【在 s*****p 的大作中提到】
: 【 以下文字转载自 Programming 讨论区 】
: 发信人: startup (startup), 信区: Programming
: 标 题: 问个programming style 的问题
: 发信站: BBS 未名空间站 (Thu Aug 24 14:32:45 2006)
: I have one line code:
: return mapping.findForward( s.login( u.getUsername(), u.getPassword()));
: Should I write 4 lines like
: String username = u.getUsername();
: String passwrod = u.getPassword();
: String retval = s.login( username, password );

avatar
f*4
4
Yeah, personally I like
return mapping.findForward( s.login( u.getUsername(), u.getPassword()) style
if it's not too long.
I seems to me more readable than the 4 lines version.
avatar
c*y
5
多写几行岂不显得工作量很大?

);

【在 s*****p 的大作中提到】
: 【 以下文字转载自 Programming 讨论区 】
: 发信人: startup (startup), 信区: Programming
: 标 题: 问个programming style 的问题
: 发信站: BBS 未名空间站 (Thu Aug 24 14:32:45 2006)
: I have one line code:
: return mapping.findForward( s.login( u.getUsername(), u.getPassword()));
: Should I write 4 lines like
: String username = u.getUsername();
: String passwrod = u.getPassword();
: String retval = s.login( username, password );

avatar
m*y
6
现在好像不按行计算工作量了

【在 c**********y 的大作中提到】
: 多写几行岂不显得工作量很大?
:
: );

avatar
g*g
7
可以多留点空行,加点注释啥的,比写code还快。

【在 c**********y 的大作中提到】
: 多写几行岂不显得工作量很大?
:
: );

avatar
c*t
8
lol, I think that most programmers hate writing comments.

【在 g*****g 的大作中提到】
: 可以多留点空行,加点注释啥的,比写code还快。
avatar
g*g
9
可以多留点空行,加点注释啥的,比写code还快。

【在 c**********y 的大作中提到】
: 多写几行岂不显得工作量很大?
:
: );

avatar
f*4
10
For those methods with complicated or quirky logic, comments helps clarify
our thoughts and so forth reduce potential bugs and make maintenance easier
in future as well.
avatar
c*y
11
有句话叫做:剽悍的程序不需要注释

easier

【在 f*******4 的大作中提到】
: For those methods with complicated or quirky logic, comments helps clarify
: our thoughts and so forth reduce potential bugs and make maintenance easier
: in future as well.

avatar
m*t
12

.
IMHO, when it gets to writing comments for one's own code, EQ is more
important than IQ - one has to be careful to assume everbody reading the
code is neither an idiot nor a genius.
avatar
c*t
13
Either is fine.
I write long code lines too, although sometimes I would break them up
to limit the # of nested (), or if the line gets too long. Sometimes
when I debug intermediate values, the long line gets broken up too.
The bottomline is readability. Although breaking them up helps reading
the particular line better, it may obscure the flow of code reading.
I sometimes pay more attention to a big block of code, but if is only a
simple thing, it would waste my energy.

);

【在 s*****p 的大作中提到】
: 【 以下文字转载自 Programming 讨论区 】
: 发信人: startup (startup), 信区: Programming
: 标 题: 问个programming style 的问题
: 发信站: BBS 未名空间站 (Thu Aug 24 14:32:45 2006)
: I have one line code:
: return mapping.findForward( s.login( u.getUsername(), u.getPassword()));
: Should I write 4 lines like
: String username = u.getUsername();
: String passwrod = u.getPassword();
: String retval = s.login( username, password );

avatar
L*r
14
"Design Pattern" 很经典. "Refactoring"个人认为只是有一些帮助, 也许每个人的理
解不同. 不喜欢smalltalk 和它的子子孙孙.
写code就如同写小人书, 让每一个人都可以读懂. 如果要写注释, 那就应该重写code.
做起来不容易呀.
avatar
m*t
15

How about this, 8-)
return mapping.findForward(
s.login(
u.getUsername(),
u.getPassword()
)
);

【在 c**********y 的大作中提到】
: 多写几行岂不显得工作量很大?
:
: );

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。