Cov txheej txheem:

Yuav suav li cas cyclomatic complexity?
Yuav suav li cas cyclomatic complexity?

Video: Yuav suav li cas cyclomatic complexity?

Video: Yuav suav li cas cyclomatic complexity?
Video: khwv nyiaj tsis nce tes yog vim li cas 2024, Hlis ntuj nqeg
Anonim

Cyclomatic complexity yog qhov chaw code nyuaj kev ntsuas uas raug correlated rau ib tug xov tooj ntawm coding yuam kev. Nws yog xam los ntawm kev tsim lub Control Flow Graph ntawm cov cai uas ntsuas tus naj npawb ntawm linearly-independent paths los ntawm ib qho kev pab cuam module.

Tsis tas li ntawd, McCabe's cyclomatic complexity xam tau li cas?

Yuav ua li cas xam Cyclomatic Complexity (McCabe)

  1. P = tus naj npawb ntawm qhov cuam tshuam ntawm cov kab hluav taws xob ntws (piv txwv li kev hu xov tooj thiab cov txheej txheem subroutine)
  2. E = tus naj npawb ntawm ntug (hloov tswj)
  3. N = tus naj npawb ntawm cov nodes (ib pawg ntawm cov nqe lus uas tsuas muaj ib qho kev hloov ntawm kev tswj)

Tsis tas li ntawd, cyclomatic complexity yog dab tsi thiab vim li cas nws tseem ceeb? Testability thiab kev ruaj ntseg yog tseem ceeb vim lawv siv sij hawm feem ntau nyob rau hauv txoj kev loj hlob lub neej voj voog ntawm cov khoom. Cyclomatic complexity feem ntau yog siv los ntsuas qhov nyuaj nyob rau hauv chav kawm lossis theem txheej txheem.

Tsis tas li ntawd, yuav ua li cas yog code complexity xam?

Xyoo 1976, Thomas McCabe Snr tau npaj ib qho kev ntsuas rau kev xam code complex , hu ua Cyclomatic nyuaj . Nws txhais tau tias: A quantitative ntsuas ntawm tus naj npawb ntawm linearly ywj siab txoj hauv kev los ntawm ib qho kev pab cuam qhov chaw code … suav nrog kev tswj cov kab hluav taws xob ntawm qhov kev pab cuam.

Dab tsi yog qhov qhab nia zoo cyclomatic complexity?

Rau feem ntau niaj hnub, a cyclomatic complexity hauv qab no 4 yog xam zoo ; a cyclomatic complexity nruab nrab ntawm 5 thiab 7 yog suav tias yog nruab nrab nyuaj , ntawm 8 thiab 10 yog siab nyuaj , thiab saum toj no yog heev nyuaj.

Pom zoo: