Re: [閒聊] 真的有扯到...

看板Soft_Job作者 (酷捏)時間13年前 (2012/03/28 20:40), 編輯推噓0(004)
留言4則, 1人參與, 最新討論串2/13 (看更多)
以下截錄自 Java How to Program @ Deitel : The boolean logical AND (&) and boolean logical inclusive OR (|) operators are identical to the && and || operators, except that the & and | operators always evaluate both of their operands (i.e., they do not perform short-circuit evaluation). So, the expressionev). So, the expression ( gender == 1 ) & ( age >= 65 ) evaluates age >= 65 regardless of whether gender is equal to 1. This is useful if the right operand of the boolean logical AND or boolean logical inclusive OR operator has a required side effect — a modification of a variable’s value. For example, the expression ( birthday == true ) | ( ++age >= 65 ) guarantees that the condition ++age >= 65 will be evaluated. Thus, the variable age is incremented, regardless of whether the overall expression is true or false. 我想這本書是很廣泛的入門書 出現錯誤的機會應該不高 照上面的意思跟你同事的觀念並無不同 另外 Java 沒有 pointer,用 bitwise 的情形真的不多 也沒有什麼奇怪的 ※ 引述《erspicu (.)》之銘言: : 有時候亂七八糟的書或是亂七八糟的講師 : 真的害死人... : 話說我有兩個寫Java的同事 : 都有一個很奇怪的觀念 : 這種巧合機率極低 但是卻發生了 : 讓我懷疑他們應該是看到同一本書或是上了同一講師的課誤導 : | vs || 的差異 : 底下是他們認為 : |是指 不管前條件為真或是偽 都會進行後條件的計算 : => true | false -> true : false | true -> false : ||是指 如果前條件為偽 則回傳為偽 跳出 不進行後條件計算 : 如果前條件為真 則進行後條件計算 : => false || true -> false : true || false -> false : true || true -> true : 以上是他們認為 : 我的媽...夠扯的 兩個人工作經驗都非常久 : 而且都擔任過知名公司的RD : 1. | 是bitwise的計算子 ,通常很少用在邏輯判斷用途上, : 把|用在邏輯判斷上也不是說不行,但是得在特定條件下才能使用, : 而且得小心使用,不熟悉語言和編譯器特性,容易發生發預期情況. : (話說也不一定是每種語言布林底層其實就是0.1數值,這樣做很危險) : 2. || 就是 或是的意思... 如果前為偽,一定會跳下去做後面的條件, : 如果前為真,有些語言或是編譯器會直接回傳真,而忽略後面條件計算, : 有些則都會做完,不太一定. : 重點是...也太扯了吧 (而且我同是好像根本不知道bitwise的意思) : 這種奇怪的觀念下,寫出來的系統沒爆掉也真的滿神的... : 到底是哪位講師或是哪本書的作者..槍斃算了 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.243.0.134

03/28 20:46, , 1F
這並沒有寫說 || 前條件為偽則後面回傳為偽不進行後面計算
03/28 20:46, 1F

03/28 20:47, , 2F
只是寫說 | 會兩個都算 而已
03/28 20:47, 2F
那我在多補一點 The parts of an expression containing && or || operators are evaluated only until it’s known whether the condition is true or false. Thus, evaluation of the expression ( gender == FEMALE ) && ( age >= 65 ) stops immediately if gender is not equal to FEMALE (i.e., the entire expression is false) and continues if gender is equal to FEMALE (i.e., the entire expression could still be true if the condition age >= 65 is true). This feature of conditional AND and conditional OR expressions is called s hort-circuit evaluation. ※ 編輯: icecastleo 來自: 111.243.0.134 (03/28 20:51)

03/28 21:09, , 3F
其實就算JAVA沒有point 但是如果有寫到需要速度或是
03/28 21:09, 3F

03/28 21:10, , 4F
像是影像處裡之類類似的程式 還是都需要用到
03/28 21:10, 4F
文章代碼(AID): #1FSmQsRn (Soft_Job)
討論串 (同標題文章)
文章代碼(AID): #1FSmQsRn (Soft_Job)