tag:blogger.com,1999:blog-7409597408023081712.post8942415637919913266..comments2024-03-07T06:50:03.725+01:00Comments on Random Thoughts on Java Programming: Another weird if statementTurbohttp://www.blogger.com/profile/05959847299811800007noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-7409597408023081712.post-55750300534150379322012-07-31T22:34:30.001+02:002012-07-31T22:34:30.001+02:00By the definition of Refactoring, and limiting sco...By the definition of Refactoring, and limiting scope to the visible section of coe, I am forced to admit truth in your point. When Refactoring code, the program MUST retain the original program's behaviour.<br /><br />Through a swamp of logic and reasoning I would be able to argue the case for my choice (or at least disprove it's falseness based on your particular point), though in the end my argument would hinge on one particular point:<br /><br />1) The assumption that the state of 'order' <br />1.a) be of particular value<br />1.b) the conditions in question attempt to disprove earlier value<br />1.c) further testing is useless once the original value be proven non-applicable.<br /><br />In this case, if simpleOrder were not false to begin with, the assumption was it would be useless to check for order's existential state or length.Joop Carelshttps://www.blogger.com/profile/07287495438771933765noreply@blogger.comtag:blogger.com,1999:blog-7409597408023081712.post-66551491414376732732012-06-25T14:06:44.668+02:002012-06-25T14:06:44.668+02:00Your first attempt is the proper solution.
I disa...Your first attempt is the proper solution.<br /><br />I disagree on your second attempt, as it alters the behaviour of the original program. The original program will <i>never</i> set <b>simpleOrder</b> to <b>false</b>, yet "<b>x =(a||b)</b>" will, if a and b are false. It's a small point, but worth making, I think.<br /><br />It illustrates the hazard of refactoring without tests.Turbohttps://www.blogger.com/profile/05959847299811800007noreply@blogger.comtag:blogger.com,1999:blog-7409597408023081712.post-67317190075290971252012-05-19T14:18:48.668+02:002012-05-19T14:18:48.668+02:00Is this a challenge, or an attempt to crowdsource ...Is this a challenge, or an attempt to crowdsource your job? ;-)<br /><br /><br />From my ancient programming experience I would say that, at the very least, the nesting in the if/else construct is undesirable and a single compound conditional would be more efficient. (assuming that the second proposition in the condition is not tested if by implication the first proposition has already provided the outcome)<br /><br />e.g. something like<br /><br />if (a||b)<br />{<br /> x = true;<br />}<br /><br />Also, I do believe that an explicit assignment of "true" is unnecessary? As is the entire "if" conditional construct. One could assign the outcome of a conditional proposition directly? (especially since the comparative outcome is analogous to the assignment)<br /><br />So something like <br /><br />x = (a || b);<br /><br />Ready For Comments.Joop Carelshttps://www.blogger.com/profile/07287495438771933765noreply@blogger.com