Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSC305 Lecture 02

CSC305 Lecture 02

Individual Software Design and Development
Clean Coding
(202409)

Javier Gonzalez-Sanchez

September 24, 2024
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. Dr. Javier Gonzalez-Sanchez [email protected] www.javiergs.info o ffi ce: 14 -227

    CSC 305 Individual Software Design and Development Lecture 02. Clean Coding
  2. Some Ideas. It is NOT a Complete List 5 MOVE

    EAT SHOW DETECT COLLISION MOVE/ HUNT SHOW SHOW/ CREATE SCORE HANDLING WINNER DETECTOR MOVE/ HUNT
  3. Single Responsibility + Modularity • E a ch cl a

    ss or 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. 8
  4. Don't Repeat Yourself (DRY) • Avoid code duplic a tion

    by a bstr a cting common function a lity. • Use functions or cl a sses to enc a psul a te repe a ted jobs. 9
  5. Keep It Simple (KIS) • Aim for simplicity in your

    design a nd implement a tion. • Avoid unnecess a ry complexity or over-engineering. 10
  6. Error Handling • Implement robust error h a ndling a

    nd logging mech a nisms. • Use exceptions a ppropri a tely a nd a void silent f a ilures - keep the user informed! 11
  7. Readability • Write e ff icient code but prioritize re

    a d a bility a nd m a int a in a bility. • Optimize perform a nce-critic a l sections only when necess a ry. 12
  8. Commenting and Documentation • Write me a ningful comments th

    a t expl a in why something is done, not wh a t is done. • Keep comments up to d a te with code ch a nges. • Document public APIs a nd complex logic thoroughly. 13
  9. Consistent Formatting • Follow a consistent code style a nd

    form a tting guidelines. https://google.github.io/styleguide/javaguide.html • Use indent a tion, whitesp a ce, a nd comments e ff ectively to enh a nce re a d a bility. 14
  10. Meaningful Names • Use descriptive a nd un a mbiguous

    n a mes for v a ri a bles, functions, cl a sses, etc. • Avoid using misle a ding or cryptic n a mes. • Follow consistent n a ming conventions. 15
  11. Refactoring • Regul a rly ref a ctor code to

    improve its structure a nd re a d a bility without ch a nging its function a lity. • Simplify complex code a nd elimin a te code smells. 16
  12. CSC 305 Individual Software Design and Development Javier Gonzalez-Sanchez, Ph.D.

    [email protected] Fall 2024 Copyright. These slides can only be used as study material for the class CSC305 at Cal Poly. They cannot be distributed or used for another purpose.