{"id":27963215,"url":"https://github.com/windmillcode/clean_code","last_synced_at":"2026-01-22T05:33:17.131Z","repository":{"id":132081341,"uuid":"423166217","full_name":"WindMillCode/clean_code","owner":"WindMillCode","description":"summary of Clean Code A Handbook of Agile Software Craftsmanship","archived":false,"fork":false,"pushed_at":"2021-11-09T17:03:10.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-07T19:58:27.669Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WindMillCode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-10-31T14:10:40.000Z","updated_at":"2021-11-09T17:03:12.000Z","dependencies_parsed_at":"2023-07-12T08:45:18.374Z","dependency_job_id":null,"html_url":"https://github.com/WindMillCode/clean_code","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/WindMillCode/clean_code","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WindMillCode%2Fclean_code","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WindMillCode%2Fclean_code/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WindMillCode%2Fclean_code/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WindMillCode%2Fclean_code/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WindMillCode","download_url":"https://codeload.github.com/WindMillCode/clean_code/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WindMillCode%2Fclean_code/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28656282,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-22T01:17:37.254Z","status":"online","status_checked_at":"2026-01-22T02:00:07.137Z","response_time":144,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-07T19:58:27.089Z","updated_at":"2026-01-22T05:33:17.125Z","avatar_url":"https://github.com/WindMillCode.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Meaningful Names\n\n* dont use single letters, makes it hard to search for\n* dont encode variable names\n* the class should be small enough where you dont have to prefix\n* dont be cute\n    * say what you mean ,mean what you say\n* pick one word per concept\n    * not fetch,retrieve,get, just get \n* dont use same word for 2 different concepts\n* choose technicalNames, programmers know what you mean\n* if it needed a comment an issue\n* use prefixes for context or context object \n    * not too much context\n```ts\n// good\ncouchAccount\n\n// bad\ncouchFromMacysAndPjAccount\n\n```\n# Functions\n* keep functions small\n* functions do one thing\n    * section with in functions, cant reasonably do one thing\n* theres level of abstractation\n    * lowe level -  .append(\"/n\")\n    * medium level - String pagePathName = PathParser.render(pagePath);\n    * high level - getHtml();\n* longer descriptive name is better\n* a fn should have no argunments, greatest is 2 \n* flag args are bad\n    * violates SRP, if true do x, else do y\n* make argument objects\n* make arg lists\n* use keywords to remember the order of args\n    instead of equals use, expectedEqualActual(expected,actual)\n* side effect, a function does not do what its supposed to\n* functions should either change the state of an object or return information\n* sepearte try catch from acutal function\n    * functions that handle errors should only do that\n\n# Comments\n* a necessary evil\n* cant realisitically maintain  comments\n* comments dont make up for bad code*\n* if you have to explain yourself use a function\n* we need legal comments \n* good for explaing regexp\n* good for intent\n* good for warnings\n    * ex: // dont run DAST unless you have time to kill\n* banners of demarcation are ususally ignored\n* avoid commented out code?\n* tmi\n\n\n# Formatting\n* put spaces between thoughts in your code\n* avoid protected vairables\n* instance variables are used in many methods of the class\n    * everyone should know where instance variables are\n* if one fn calls another they should be vertically close\n* there is conceptual affinitiy\n* programmers prefer short lines\n* 120 max limit for programming\n* aligned decorratores make your eyes forget the actual important  details\n* rmbr indentation always make code that can scale\n\n\n# Objects and Data Structures\n* keep variables private in order to change them\n* dont expose details of data keep in abstract terms\n\n```java\npublic interface Vehicle {\n double getFuelTankCapacityInGallons();\ndouble getGallonsOfGasoline();a\n}\n```\n\n* this is preferabble\n```java\npublic interface Vehicle {\n double getPercentFuelRemaining();\n}\n```\n* __law of demeter__\n* method f of class C should only call methods of\n    * C\n    * object created by f\n    * object passed as an arg to f\n    *  An object held in an instance variable of C\n    * not invoke methods on object that are returned\n* if we have an object we should be telling it to do something not asking about it's intnernals\n\n\n\n## Questions \n* not understanding the law of demeter too well, to clarify i should use properties on the object to get what I need I should use a methods that does it for me\n    * according to demeters law - Objects expose behavior and hide data, Data structures expose data and have no significant behavior\n\n# Error Handling\n*   Error  handling  is  important, but  if  itobscures logic, it’s wrong.\n* use exceptions rather than return codes\n```java\npublic void sendShutDown() {    \n    try {      tryToShutDown();    } \n    catch (DeviceShutDownError e) {      logger.log(e);    }  \n}\n\n```\n* start with try,catch,finally statement first\n* try to write tests that force exceptions and add behavior to satisfy tests\n* use unchecked exceptions\n* make informative error message\n    * bad\n        * An exception occured, 1 periodic timer left in queue\n    * good\n        * you may have a subscrition that was not unsubbed or a timer that did not complete before the test ended\n    \n* use a wrapper class to conceptualize your error classes, aka exception classes\n* use special case  objects instead of exceptions, better for performance\n```java\n// dont\ntry {\n    MealExpenses expenses = expenseReportDAO.getMeals(employee.getID());\n    m_total += expenses.getTotal();\n} catch (MealExpensesNotFound e) {\n    m_total += getMealPerDiem();\n}\n\n// do \nMealExpenses expenses = expenseReportDAO.getMeals(employee.getID());\nm_total += expenses.getTotal();\npublic class PerDiemMealExpenses implements MealExpenses {  \n    public int getTotal() {    // return the per diem default  }\n}\n```\n* dont return null, throw exception or return special case, \n    * returning null makes more work for yourself\n* dont pass null to methods\n    * in your method forbid passing null\n    * use a list of assertions\n\n```java\npublic class MetricsCalculator {\n    public double xProjection(Point p1, Point p2) {\n        assert p1 != null: \"p1 should not be null\";\n        assert p2 != null: \"p2 should not be null\";\n        return (p2.x– p1.x) * 1.5;\n    }\n}\n```\n\n# Boundaries\n* provides want broad range of support, users want focus on particular needs\n```java\nMap sensors = new HashMap();\nSensor s = (Sensor)sensors.get(sensorId );\n```\n* we dont want a generic to support anything, thats not clean code because before we interact it takes more code to find out what is the data structure were dealing with\nuse generic type\n* use this \n    * now the user just uses Sensors without having to worry about implementation\n    * Map can evolve without affecting the application\n    * type management handled within class\n```java\npublic class Sensors {\n    private Map sensors = new HashMap();\n    public Sensor getById(String id) {\n        return (Sensor) sensors.get(id);\n    }\n    //snip\n}\n```\n\n* __learning tests__ - contain all the functionality you want to use from the 3rd party in a class\n    *  new releases of the third-party package, we run the learning tests to see whether there\nare behavioral differences. \n\n* depend on something you control, then something you cant or it will control you\n* 3rd party adapters\n\n new releases of the third-party package, we run the learning tests to see whether there\nare behavioral differences. \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwindmillcode%2Fclean_code","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwindmillcode%2Fclean_code","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwindmillcode%2Fclean_code/lists"}