s*****p 发帖数: 5342 | 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 );
多谢指教! |
g*****g 发帖数: 34805 | 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 );
|
c*****t 发帖数: 1879 | 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 );
|
f*******4 发帖数: 345 | 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. |
c**********y 发帖数: 15 | 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 );
|
m******y 发帖数: 102 | 6 现在好像不按行计算工作量了
【在 c**********y 的大作中提到】 : 多写几行岂不显得工作量很大? : : );
|
g*****g 发帖数: 34805 | 7 可以多留点空行,加点注释啥的,比写code还快。
【在 c**********y 的大作中提到】 : 多写几行岂不显得工作量很大? : : );
|
c*****t 发帖数: 1879 | 8 lol, I think that most programmers hate writing comments.
【在 g*****g 的大作中提到】 : 可以多留点空行,加点注释啥的,比写code还快。
|
g*****g 发帖数: 34805 | 9 可以多留点空行,加点注释啥的,比写code还快。
【在 c**********y 的大作中提到】 : 多写几行岂不显得工作量很大? : : );
|
f*******4 发帖数: 345 | 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. |
|
|
c**********y 发帖数: 15 | 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.
|
m******t 发帖数: 2416 | 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. |
c*****t 发帖数: 1879 | 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 );
|
L*********r 发帖数: 92 | 14 "Design Pattern" 很经典. "Refactoring"个人认为只是有一些帮助, 也许每个人的理
解不同. 不喜欢smalltalk 和它的子子孙孙.
写code就如同写小人书, 让每一个人都可以读懂. 如果要写注释, 那就应该重写code.
做起来不容易呀. |
m******t 发帖数: 2416 | 15
How about this, 8-)
return mapping.findForward(
s.login(
u.getUsername(),
u.getPassword()
)
);
【在 c**********y 的大作中提到】 : 多写几行岂不显得工作量很大? : : );
|