Kev lees paub yuav tsum tau siv los tshuaj xyuas qee yam uas yuav tsum tsis txhob tshwm sim, thaum qhov kev zam yuav tsum raug siv los tshuaj xyuas qee yam uas yuav tshwm sim. Piv txwv li, kev ua haujlwm yuav faib los ntawm 0, yog li yuav tsum tau siv qhov tshwj xeeb, tab sis qhov kev lees paub tuaj yeem siv los xyuas tias lub harddrive tam sim ntawd ploj mus.
YPuas hais tias zoo los yog phem?
No, neither goto or assert is evil. Tab sis ob leeg tuaj yeem siv tsis raug. Kev lees paub yog rau kev kuaj mob zoo. Tej yam uas yuav tsum tua cov program yog tias lawv tsis raug.
Vim li cas cov lus hais phem?
Kev lees paub tuaj yeem siv los txheeb xyuas qhov kev siv sab hauv invariants, zoo li lub xeev sab hauv ua ntej lossis tom qab ua tiav ntawm qee txoj kev, thiab lwm yam. Yog tias kev lees paub ua tsis tiav nws tiag tiag txhais tau tias lub laj thawj ntawm qhov kev pab cuam tawg thiab koj tuaj yeem ' tsis rov los ntawm no.
Yuav ua li cas hais tau zoo?
Cov lus qhia qhia kev lees paub muaj qee cov lus qhia zoo uas yog qhov kuv nyuam qhuav piav qhia. Yes it is good practice. Nyob rau hauv lub caij nplooj ntoos hlav, nws yog ib qho tseem ceeb heev vim hais tias cov checks yog validating cov cuab yeej nqis, thiab lwm yam uas feem ntau yog los ntawm XML thaiv cov ntaub ntawv.
Yuav ua li cas yog qhov kev lees paub muaj txiaj ntsig?
Piv txwv tias tus lej tau raug kuaj kom raug, kev lees paub ua ntau yam tseem ceeb: Tshawb nrhiav qhov yuam kev me me uas yuav txwv tsis pub mus nrhiav tsis pom . Ntawm qhov yuam kev sai sai tom qab lawv tshwm sim dua li lawv yuav raug kuaj pom. Ua ib nqe lushais txog cov teebmeem ntawm txoj cai uas tau lees tias muaj tseeb.