{"id":1228,"date":"2021-07-20T09:41:00","date_gmt":"2021-07-20T15:41:00","guid":{"rendered":"https:\/\/www.great-white-software.com\/blog\/?p=1228"},"modified":"2021-07-15T16:58:14","modified_gmt":"2021-07-15T22:58:14","slug":"help-keep-your-code-sanity","status":"publish","type":"post","link":"https:\/\/www.great-white-software.com\/blog\/2021\/07\/20\/help-keep-your-code-sanity\/","title":{"rendered":"Help keep your code sanity"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Ever think to yourself &#8220;Oh I have this project to do and I&#8217;ll just cut and paste the code from there and tweak it?&#8221; And now you have two copies that are a lot alike but maybe not exactly the same.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And then you do this over &amp; over and now you have many copies of that code?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How do you deal with issues when you find them ?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Which copy is the newest &amp; the most correct ? And which one is the right good copy to use as the basis for yet another copy ?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I&#8217;ll admit that I will copy &amp; paste code to examine it. Play with it to see how it breaks. And then I throw it away and fix the real single working copy that IS the master for all others.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And there are some neat tools for this like <a href=\"https:\/\/marketplace.atlassian.com\/apps\/1211309\/snippets-for-bitbucket-server?hosting=server&amp;tab=overview\">Snippets for BitBucket Server<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Copy &amp; paste coding is fast. Repetitive. And it has issues. Which is why <a href=\"https:\/\/en.wikipedia.org\/wiki\/Copy-and-paste_programming\">copy-paste programming<\/a> is used mostly as a negative comment on coding style.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/www.bankinfosecurity.eu\/blogs\/developers-code-reuse-security-conundrum-cut-paste-fail-p-2798\">And it can be dangerous<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you have the ability to avoid it by using submodules, includes, sub-projects in whatever version control system you&#8217;re using (you ARE using version control right?), or similar mechanisms I&#8217;d encourage you to do so.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It will help you avoid the proliferation of many different versions of the same code in all your projects.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And when you need to fix the code you can fix one copy and all your other projects can be updated with it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ever think to yourself &#8220;Oh I have this project to do and I&#8217;ll just cut and paste the code from there and tweak it?&#8221; And now you have two copies that are a lot alike but maybe not exactly the same. And then you do this over &amp; over and now you have many copies &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.great-white-software.com\/blog\/2021\/07\/20\/help-keep-your-code-sanity\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Help keep your code sanity&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1],"tags":[],"class_list":["post-1228","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/1228","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/comments?post=1228"}],"version-history":[{"count":1,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/1228\/revisions"}],"predecessor-version":[{"id":1229,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/1228\/revisions\/1229"}],"wp:attachment":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/media?parent=1228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/categories?post=1228"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/tags?post=1228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}