由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - 问个programming style 的问题 (转载)
相关主题
JavaBean variable name standardAny body uses wicket framework for web development?
SCJP都考些啥?Is it possible to get Class object for T from a generic class? (下列空档,是否可填)
view templating technologyRe: Desperately need help on DB2 connection through jdbc in jsp page
请教Programming bookseclipse 气死我了!
请问java的ide调查:最好的Java IDE
any tools for ...Indian and Java
使用eclipse方法对第三方库建立Wrapper的小技巧。Re: 考JCEA归来
how to refactor overlayered applications?What's your habit to document this?
相关话题的讨论汇总
话题: string话题: retval话题: code话题: return话题: username
进入Java版参与讨论
1 (共1页)
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.
相关主题
any tools for ...Any body uses wicket framework for web development?
使用eclipse方法对第三方库建立Wrapper的小技巧。Is it possible to get Class object for T from a generic class? (下列空档,是否可填)
how to refactor overlayered applications?Re: Desperately need help on DB2 connection through jdbc in jsp page
进入Java版参与讨论
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 的大作中提到】
: 多写几行岂不显得工作量很大?
:
: );

1 (共1页)
进入Java版参与讨论
相关主题
What's your habit to document this?请问java的ide
Java5 compatibility issueany tools for ...
有多少人对annotation这个东西不满,请举手!!使用eclipse方法对第三方库建立Wrapper的小技巧。
eclipse有没有update变量名称的功能?how to refactor overlayered applications?
JavaBean variable name standardAny body uses wicket framework for web development?
SCJP都考些啥?Is it possible to get Class object for T from a generic class? (下列空档,是否可填)
view templating technologyRe: Desperately need help on DB2 connection through jdbc in jsp page
请教Programming bookseclipse 气死我了!
相关话题的讨论汇总
话题: string话题: retval话题: code话题: return话题: username