Code Monkey home page Code Monkey logo

java-mod-3-pattern-recognition's Introduction

Pattern Recognition

Learning Goals

  • Understand and explain how to recognize different coding patterns

Recognizing Patterns

A big aspect of programming is problem-solving. Whether that's bug fixes in existing code, or problems that businesses come to us to help solve, we are constantly solving problems. And most of the time, there are more than one solution to each problem.

As we saw in the previous section, there are many patterns you could leverage to implement the specific functionality you need to support. So an important skill to learn is to recognize patterns and apply them appropriately.

Since the problem space is essentially infinite, so are the possible solutions, and therefore the possible patterns to look for. However, there are a few methods you should rely on in order to become better at recognizing patterns:

  1. Always start with the simplest possible form of implementation you can for the specific functionality you are implementing. This will allow you to detect complexity as it starts to creep into the system.
  2. Make sure your code is both testable and tested. This will give you the confidence to re-factor your code as you see specific patterns emerge. Code that does not have automated test coverage is much more difficult to restructure because it requires a lot of manual work (when it's even possible) to validate that the changes do not break previous functionality
  3. Lean on the SOLID principles we studied in a previous section. These are foundational principles that you can rely on to make sound design decisions with your code.
  4. Don't be afraid to a) experiment, b) simplify and c) ask questions:
    1. Experiment: if you think something may be doable in a different, better way, don't hesitate to test out your theory.
    2. Simplify: a very useful skill for experimentation is to boil down your candidate solution to its simplest form and experiment with it "on the side". This is because you might be working on a complex system with a lot of dependencies and experimentation may be "expensive" (i.e. slow and require a lot of work) in that environment. Starting a smaller, standalone project where you can iterate more quickly can speed up your experimentation cycles.
    3. Ask questions: interrogate every aspect of the code you don't understand. This can be done by running tests, adding log statements, asking direct questions to people more familiar with the system than you are, ... In general, do not assume that something you don't understand makes sense because someone else wrote it.
  5. Be aware of repeating code, solutions: solving the same problem multiple times is a good sign that you should build something that you can leverage in the multiple places where this type of problem occurs.
  6. Sleep on it: it pays to step away from your code for some time and look at it with a fresh pair of eyes after some rest to give you a new perspective.
  7. Collaborate: also in the service of getting a different perspective, collaborate with others around you so they can lend you their perspective and look at the problem you are tackling from a different angle.

Beyond these general strategies, there are specific "code smells" you should also be on the lookout for. More on this in the following section.

java-mod-3-pattern-recognition's People

Contributors

alveem avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.