function should h a ve one, a nd only one, job. • Keep functions focused on a single t a sk. • Bre a k down your code into sm a ller, reus a ble modules or functions. • Ensure e a ch module or function h a s a cle a r, well-de f ined purpose. • 4
lines of a single br a ce or p a renthesis • LOC a re used to cre a te time a nd cost estim a tes. • LOC a re a tr a cking tool to me a sure the degree of progress on a module or project. • An experienced developer c a n g a ge a LOC estim a te b a sed upon knowledge of p a st productivity on projects. 12
Code Metric. Only code st a tements • An e ff ective line of code or eLOC is the me a surement of a ll lines th a t a re not comments, bl a nks or st a nd a lone br a ces or p a renthesis. These c a n in f l a te LOC metrics by 20 to 40 percent. • This metric more closely represents the qu a ntity of work performed. 13
Code Metric. • These st a tements a re termin a ted with a semi-colon. • The control line for the "for" loop cont a in two semi-colons but a ccounts for only one semi colon. 14
of the number of linearly independent paths. • P a ths occur when "while,” "for,” "if,” "c a se," a nd "goto" keywords a ppe a r within the function. • If the source code cont a ined no control f low st a tements (condition a ls or decision points), the complexity would be 1 • If the code h a d one single-condition IF st a tement, there would be two p a ths through the code: one where the IF st a tement ev a lu a tes to TRUE a nd a nother one where it considers to be FALSE. • Two nested single-condition IFs, or one block with two conditions, would produce a complexity of 3. 25
Testability Cost and Effort is less 10-20 Complex Code Medium Testability Cost and effort is Medium 20-40 Very complex Code Low Testability Cost and Effort are high >40 Not at all testable Very high Cost and Effort Cyclomatic Complexity 28
a ss or p a ck a ge emph a sizes a bstr a ction over concrete implement a tion • It is a v a lue 0 to 1: • For p a ck a ges, It is the r a tio of a bstr a ct cl a sses or interf a ces to the tot a l number of cl a sses within a p a ck a ge. • For cl a sses, It is 0 for a concrete cl a ss a nd 1 for a n interf a ce or a bstr a ct cl a sses 38
item is m a inly used by others (st a ble – h a rd to ch a nge); or (b) it m a inly depends on other items (in-st a ble – ch a nge a ble). • It is a v a lue between 0 a nd 1: • 0 only incoming dependencies to • 1 (only outgoing dependencies). 39
Summer 2024 Copyright. These slides can only be used as study material for the class CSC307 at Cal Poly. They cannot be distributed or used for another purpose.