This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| great_developer_habits [2019/11/01 15:21] admin created | great_developer_habits [2021/05/16 15:21] (current) admin | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ### Keep Organized | ||
| + | |||
| + | - **Let go code scraps:** Don't comment out old code. Delete them. You can find them in your git history. | ||
| + | - **Don't ignore warning:** Treat warning as error. Fix them as you go on. | ||
| + | |||
| + | ### Use Source Control | ||
| + | |||
| + | - **Keep commit small:** Keep it small, localized and self contained.  | ||
| + | - **Write clean and helpful commit message:** What is changed? Why change it? | ||
| + | |||
| + | - **Write code comment:** Explain "why this code is written" and "How it fit into the whole picture" | ||
| + | - **Do Code Review** | ||
| + | |||
| + | |||
| + | ### A Template of code document | ||
| + | <file> | ||
| + | - Summary | ||
| + | - How to use it in the code | ||
| + | - Discussion | ||
| + | </file> | ||
| - | - **Let go scraps:** Don't comment out old code. Delete them. You can find them in your git history. | ||
| - | - **Don't ignore warning:** Don't let it piles up. | ||
| <wrap lo>Reference: | <wrap lo>Reference: | ||
| - WWDC 2019 Great Developer Habbits: https://developer.apple.com/videos/play/wwdc2019/239/ | - WWDC 2019 Great Developer Habbits: https://developer.apple.com/videos/play/wwdc2019/239/ | ||
| </wrap> | </wrap> | ||
| + | |||
| + | |||
| + | ### Minimizing Function Footprint | ||
| + | |||
| + | It's good practice when writing plugins to only take up one slot within $.fn. This reduces both the chance that your plugin will be overridden, and the chance that your plugin will override other plugins. In other words, this is bad: | ||
| + | ```javascript | ||
| + | (function( $ ) { | ||
| + | |||
| + | $.fn.openPopup = function() { | ||
| + | // Open popup code. | ||
| + | }; | ||
| + | |||
| + | $.fn.closePopup = function() { | ||
| + | // Close popup code. | ||
| + | }; | ||
| + | |||
| + | }( jQuery )); | ||
| + | ``` | ||
| + | |||
| + | It would be much better to have one slot, and use parameters to control what action that one slot performs. | ||
| + | |||
| + | ```javascript | ||
| + | (function( $ ) { | ||
| + | |||
| + | $.fn.popup = function( action ) { | ||
| + | |||
| + | if ( action === "open") { | ||
| + | // Open popup code. | ||
| + | } | ||
| + | |||
| + | if ( action === "close" ) { | ||
| + | // Close popup code. | ||
| + | } | ||
| + | |||
| + | }; | ||
| + | |||
| + | }( jQuery )); | ||
| + | ``` | ||