Learning Essentials for Code Improvement

Learning Essentials for Code Improvement
Slide Note
Embed
Share

Motivation, clean code practices, identifying code smells, TDD strategies, and the process of refactoring. Dive into valuable resources and rules to enhance your coding skills efficiently.

  • Code Improvement
  • Clean Code
  • TDD Strategies
  • Refactoring
  • Development

Uploaded on Feb 19, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Motivation

  2. Disclaimer TDD is hard and needs time invested. Take it step by step

  3. Clean Code Clean Code is intuitively understandable text Not necessarily code, can be YAML, DBs, etc.. 80% of the life cycle of a project is maintenance, feature expansion and bug fixing. It s not easy and requires experience. This experience can be learned by doing.

  4. Code Smells What? How can code smell ? - Well it doesn t have a nose but it definitely can stink! - refactoring.guru Code Smells are patterns that make code less readable.

  5. What happens when I dont give a shit? My boss said it has to be done yesterday. Cumulative Functionality Good code Bad code Payoff point Time (appears in weeks, not months)

  6. Refactoring A refactoring is a structure changing, behaviour preserving process.

  7. Further Resources Clean Code, Code Smells & Refactorings https://refactoring.guru

  8. TDD The idea of TDD is to convert requirements to test cases and force the requirements to be fulfilled by writing the tests first. Two approaches Chicago / Detroit TDD (bottom up) London TDD (top down)

  9. Process Do not write more than necessary to make the test pass If you don t know what to implement next, look at the user story prioritization (what is the next most important thing to do?) Plan ahead and break the tasks up if necessary.

  10. Rules 1. Do not write production code that is more specific than the tests. Tests makes the test suite more specific. Production code makes the production app more general. 2. Don t go for the goal. Avoid the central behaviour as long as possible. 3. Do not bring TDD to work if you re not good at TDD. Trying to improve code by writing tests is never wrong. Just don t force your team until you re sure of what you re doing.

  11. Effects If you break something, you ll know it. More modular projects Examples of how to use code snippets These all should (in theory) result in faster development speed later in the development cycle % Test coverage

  12. When not to do If you re in a professional setting and you re not an expert. If you re doing teamwork and you re not an expert. Otherwise? Go for it.

  13. How to write good Tests

  14. Differentiate between Integration and Unit Differentiate between Integration and Unit Tests Tests

  15. Isolate the Testable Logic Isolate the Testable Logic Mock with Dependency Injection Patch & Mock

  16. Follow Arrange, Act, Assert Follow Arrange, Act, Assert

  17. Follow Follow Arrange Arrange, , Act Act, , Assert Assert

  18. Helpful Testing Resources JUnit and Unit Testing Frameworks for other languages Mocking Spoof the behaviour of another object with hard coded values Some Modules have built in mocking solutions Python e.g. request -> response Dependency Injection Method patching

  19. Dependency Injection

  20. Dependency Injection

  21. Exercises 2 Minute TDD Katas Program a calculator Program a calculator that uses strings (terms) as inputs A program that converts ints to roman numerals A program that converts roman numerals to ints Refactoring Katas Great to learn how to write tests in an existing code base without tests

  22. Other Remarks Don t write efficient code. Write code that is maintainable and then make it efficient. Unreadable code has probably more bugs than readable code, which can influence software security by creating exploitable vulnerabilities. Bugs are easier to identify in readable code than unreadable code. Bugs are also easier to fix in maintainable code. Therefore, readable and maintainable code is usually more secure. Only applies to code level bugs!

  23. References https://github.com/testdouble/contributing-tests/wiki/ https://tdd.mooc.fi/ https://tddmanifesto.com/exercises/ https://refactoring.guru/

  24. Cool Books The important ones Refactoring: Improving the design of existing code https://www.informit.com/store/refactoring- improving-the-design-of-existing-code-9780134757711 Test Driven Development by Examplehttps://www.informit.com/store/test-driven-development- by-example-9780321146533 Clean Code https://www.amazon.de/-/en/Robert-Martin/dp/0132350882 Other cool books https://www.informit.com/store/xunit-test-patterns-refactoring-test-code-9780132800051 https://www.informit.com/store/atdd-by-example-a-practical-guide-to-acceptance-test- 9780132763233 https://www.informit.com/store/growing-object-oriented-software-guided-by-tests- 9780321503626 https://www.informit.com/store/developer-testing-building-quality-into-software- 9780134291062#

Related


More Related Content