Redian新闻
>
faint, unreachable statement in java
avatar
faint, unreachable statement in java# Java - 爪哇娇娃
w*t
1
if I put
return;
in the middle, it returns an 'error', telling me there are
unreachable stuff after that...
if I put
if (true)
return;
then it doesnot complain a thing.
shouldnot the first one be a warning instead of error?
avatar
c*t
2
That's one thing I absolutely hate about Java compiler. It's just
a pain sometimes doing the debugging w/o early return statement.

【在 w*******t 的大作中提到】
: if I put
: return;
: in the middle, it returns an 'error', telling me there are
: unreachable stuff after that...
: if I put
: if (true)
: return;
: then it doesnot complain a thing.
: shouldnot the first one be a warning instead of error?

avatar
g*g
3
Usually the compiler doesn't know the first
one is equal to the second one. Only optimizer
knows that. It's the compiler who gives warning.

【在 w*******t 的大作中提到】
: if I put
: return;
: in the middle, it returns an 'error', telling me there are
: unreachable stuff after that...
: if I put
: if (true)
: return;
: then it doesnot complain a thing.
: shouldnot the first one be a warning instead of error?

avatar
g*g
4
Well, usually a sensitive compiler avoids you
much pain by adding some inconvenience.

【在 c*****t 的大作中提到】
: That's one thing I absolutely hate about Java compiler. It's just
: a pain sometimes doing the debugging w/o early return statement.

avatar
w*t
5
it gave me ERROR instead of warning, or I wont complain. hehe.

【在 g*****g 的大作中提到】
: Usually the compiler doesn't know the first
: one is equal to the second one. Only optimizer
: knows that. It's the compiler who gives warning.

avatar
w*t
6
not really bah... java is arrogant in a few places... not to mention the JDKs
dont live up to many of their claims...

【在 g*****g 的大作中提到】
: Well, usually a sensitive compiler avoids you
: much pain by adding some inconvenience.

avatar
g*g
7
You should comment out the left part when you
enter a hard return for debugging, otherwise
you may forget it later. I am OK with that.
A strict compiler never does you bad.

【在 w*******t 的大作中提到】
: it gave me ERROR instead of warning, or I wont complain. hehe.
avatar
g*g
8
Not for compiler bah, JDK is buggy, but compiler
should be stable.

【在 w*******t 的大作中提到】
: not really bah... java is arrogant in a few places... not to mention the JDKs
: dont live up to many of their claims...

avatar
w*t
9
any way, 1.5 has a lot changes for the competition from c#, good for both of
them.. c# needs improvement too.

【在 g*****g 的大作中提到】
: Not for compiler bah, JDK is buggy, but compiler
: should be stable.

avatar
w*t
10
when it's 200 lines of code, with /* */ comment inside, I dont think it's
nice to force programmer to do that. I just think it should be warning, and
I will see warning and wont forget it.. hehe..

【在 g*****g 的大作中提到】
: You should comment out the left part when you
: enter a hard return for debugging, otherwise
: you may forget it later. I am OK with that.
: A strict compiler never does you bad.

avatar
g*g
11
C/C++ allows you to do something like
if(a=b), while java doesn't as long as a & b are not boolean.
Many C/C++ programmers complain they can not use 0/1
in if and that kills convenience.
On the other hand, it saves life of millions of newbie
programmers.

【在 w*******t 的大作中提到】
: when it's 200 lines of code, with /* */ comment inside, I dont think it's
: nice to force programmer to do that. I just think it should be warning, and
: I will see warning and wont forget it.. hehe..

avatar
e*g
12
sure javac knows that it is dead code, and will eliminate it. (javap -c)
however, semantically, if() is a runtime thing; javac has to
treat the two situation differently when compiling.
practically this is very useful, for example,
1. final boolean FLAG=true;
2. if(FLAG)... else...;
you can change line 1, to be false, or to be non-const,
but compiler should not give different message to line 2,
(though indeed very different bytecodes are generated)
because structure and semantics of of line 2

【在 g*****g 的大作中提到】
: Usually the compiler doesn't know the first
: one is equal to the second one. Only optimizer
: knows that. It's the compiler who gives warning.

avatar
m*t
13

that's not necessarily true when you have a large project built by ant
that would spit out thousands of lines of output. It would be hard
to pick out that one line of warning.
As far as I'm concerned, I wouldn't have problem with either way,
but I guess Java chooses to error on the safe side, which I sure
wouldn't complain. 8-)

【在 w*******t 的大作中提到】
: when it's 200 lines of code, with /* */ comment inside, I dont think it's
: nice to force programmer to do that. I just think it should be warning, and
: I will see warning and wont forget it.. hehe..

avatar
m*t
14

Instead of calling it convenient, I'd rather say it's some
inherent pain resulted from the fact that C/C++ doesn't have a built-in
boolean type.
and their sanity...

【在 g*****g 的大作中提到】
: C/C++ allows you to do something like
: if(a=b), while java doesn't as long as a & b are not boolean.
: Many C/C++ programmers complain they can not use 0/1
: in if and that kills convenience.
: On the other hand, it saves life of millions of newbie
: programmers.

avatar
w*t
15
maybe you are right, btw, I dont like ant, usually if you just compile one
file, you can notice that warning easily... :D

【在 m******t 的大作中提到】
:
: Instead of calling it convenient, I'd rather say it's some
: inherent pain resulted from the fact that C/C++ doesn't have a built-in
: boolean type.
: and their sanity...

avatar
g*g
16
C++ has it, and C99 has it now.
Of course I know there are legacy codes.

【在 m******t 的大作中提到】
:
: Instead of calling it convenient, I'd rather say it's some
: inherent pain resulted from the fact that C/C++ doesn't have a built-in
: boolean type.
: and their sanity...

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