├── LICENSE └── README.md /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Very clean code 2 | 3 | [![Tweet](https://img.shields.io/badge/Tweet-share-d5d5d5?style=social&logo=twitter)](https://twitter.com/intent/tweet?text=Found%20useful%20policies%20of%20%40szepeviktor&url=https%3A%2F%2Fgithub.com%2Fszepeviktor%2Fvery-clean-code) 4 | [![theories](https://img.shields.io/badge/more-theories-purple)](https://github.com/stars/szepeviktor/lists/theory) 5 | 6 | Additions to https://github.com/piotrplenik/clean-code-php 7 | 8 | 💡 Cognitive Load is what matters https://github.com/zakirullin/cognitive-load 9 | 10 | ## 🟢 Happy and unhappy path 11 | 12 | ``` 13 | if (error) unhappy path; 14 | 15 | happy path; 16 | ``` 17 | 18 | 🖱️ https://szymonkrajewski.pl/why-should-you-return-early/ 19 | 20 | ## 🟢 Arrays versus objects 21 | 22 | An array is a dumb container of unknown data. Arrays should be used to store lists: keyless elements of the same type. 23 | BTW strings are containers of unknown bytes. 24 | 25 | 🖱️ https://github.com/CuyZ/Valinor 26 | 27 | ## 🟢 Base value of an array 28 | 29 | The base value of an array is not `null` but `[]`. 30 | 31 | ## 🔴 String manipulation 32 | 33 | String manipulation including concatenation is the job of low level libraries as it is highly error prone. 34 | 35 | :bulb: Creating messages for UI and logs is not string manipulation. 36 | 37 | ## 🟢 Write positive conditions 38 | 39 | Explicit is better than implicit. 40 | 41 | ``` 42 | ❌ if (state !== null) 43 | ✔️ if (state instanceof Resolver) 44 | ``` 45 | 46 | ## 🔴 Mixing programming languages 47 | 48 | Have low-level libraries connect different languages. 49 | 50 | - Main language + SQL: ORM 51 | - Main language + HTML: template engine 52 | - Main language + JavaScript: JSON 53 | - Main language + CSS: use CSS classes and CSS variables 54 | 55 | ## Principles 56 | 57 | - Abstraction: strive to make deeper layers do the work, write less project-specific code. 58 | - Be explicit! Implicit things need more brain work thus are error prone. 59 | - > There are only two hard things in Computer Science: cache invalidation and naming things. 60 | 61 | — Phil Karlton 62 | 63 | Gain knowledge of _things_, so you can name them. 64 | 65 | ## Support my thinking 66 | 67 | Please consider supporting my work, as formulating the conclusions above takes at least several months. 68 | 69 | [![Sponsor](https://github.com/szepeviktor/.github/raw/master/.github/assets/github-like-sponsor-button.svg)](https://github.com/sponsors/szepeviktor) 70 | 71 | Thank you! 72 | --------------------------------------------------------------------------------