{"id":1495,"date":"2016-05-13T14:14:45","date_gmt":"2016-05-13T19:14:45","guid":{"rendered":"https:\/\/blogs.mathworks.com\/loren\/?p=1495"},"modified":"2016-08-04T09:24:25","modified_gmt":"2016-08-04T14:24:25","slug":"save-yourself","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/loren\/2016\/05\/13\/save-yourself\/","title":{"rendered":"Save Yourself!"},"content":{"rendered":"<div class=\"content\"><!--introduction--><p>Today I am going to talk a little about code development and appropriate hygiene that goes with it.  Why?  Well, have you ever ended up with a really sick feeling after spending hours on something, only to realize that it's been deleted?  It's happened to me, but never again!<\/p><!--\/introduction--><h3>Contents<\/h3><div><ul><li><a href=\"#6550862e-1179-4e63-8a89-620555822ec7\">Did You Know...?<\/a><\/li><li><a href=\"#15b376db-c44c-4e5a-8d52-d41e49de05e3\">Git Outta Here<\/a><\/li><li><a href=\"#dce901cd-38f5-4de3-9e7c-53c0dce7bb50\">What Do You Do?<\/a><\/li><\/ul><\/div><h4>Did You Know...?<a name=\"6550862e-1179-4e63-8a89-620555822ec7\"><\/a><\/h4><p>MATLAB currently allows you to make backups of your code, and you can control some aspects of that.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/loren\/files\/saveCodeBackups.png\" alt=\"\"> <\/p><p>Here you can see my preferences.  I choose to:<\/p><div><ul><li>allow frequent backups of open files<\/li><li>save these with an alternate extension<\/li><li>delete them when I quit MATLAB so I don't litter my file system with these backups<\/li><li>place them in a central location rather than in the same folder as the code I am working on<\/li><\/ul><\/div><p>You might want to choose different options suitable to your style of coding.<\/p><h4>Git Outta Here<a name=\"15b376db-c44c-4e5a-8d52-d41e49de05e3\"><\/a><\/h4><p>So, that's one way of working and using a bit of a safety net.  You can also use some method of <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/matlab_prog\/about-mathworks-source-control-integration.html\">source code control<\/a> from within MATLAB.  Out of the box you can use SVN (Subversion) or GIT. If you choose this route, you don't even have to worry about pesky *.asv files lying around.  Instead, you make some code changes and commit them to your system of choice.  In these systems, you can always go back to prior versions.  And so you don't risk causing permanent damage - generally a good idea.<\/p><h4>What Do You Do?<a name=\"dce901cd-38f5-4de3-9e7c-53c0dce7bb50\"><\/a><\/h4><p>How do you back up your work in MATLAB?  With autosaved files?  With source code control?  Something else?  <\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_3f41176a868a45b4bd565ad1740be8cf() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='3f41176a868a45b4bd565ad1740be8cf ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 3f41176a868a45b4bd565ad1740be8cf';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        copyright = 'Copyright 2016 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\r\n    }   \r\n     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_3f41176a868a45b4bd565ad1740be8cf()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2016a<br><\/p><\/div><!--\r\n3f41176a868a45b4bd565ad1740be8cf ##### SOURCE BEGIN #####\r\n%% Save Yourself!\r\n% Today I am going to talk a little about code development and appropriate\r\n% hygiene that goes with it.  Why?  Well, have you ever ended up with a\r\n% really sick feeling after spending hours on something, only to realize\r\n% that it's been deleted?  It's happened to me, but never again!\r\n%% Did You Know...?\r\n% MATLAB currently allows you to make backups of your code, and you can\r\n% control some aspects of that.\r\n%\r\n% <<saveCodeBackups.png>>\r\n%\r\n% Here you can see my preferences.  I choose to:\r\n%\r\n% * allow frequent backups of open files\r\n% * save these with an alternate extension\r\n% * delete them when I quit MATLAB so I don't litter my file system with these backups\r\n% * place them in a central location rather than in the same folder as the code I am working on\r\n%\r\n% You might want to choose different options suitable to your style of\r\n% coding.\r\n%% Git Outta Here\r\n% So, that's one way of working and using a bit of a safety net.  You can\r\n% also use some method of\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/matlab_prog\/about-mathworks-source-control-integration.html\r\n% source code control> from within MATLAB.  Out of the box you can use SVN\r\n% (Subversion) or GIT. If you choose this route, you don't even have to\r\n% worry about pesky *.asv files lying around.  Instead, you make some code\r\n% changes and commit them to your system of choice.  In these systems, you\r\n% can always go back to prior versions.  And so you risk causing permanent\r\n% damage - generally a good idea.\r\n%% What Do You Do?\r\n% How do you back up your work in MATLAB?  With autosaved files?  With\r\n% source code control?  Something else?  Let us know\r\n% <https:\/\/blogs.mathworks.com\/?p=1495#respond here>.\r\n##### SOURCE END ##### 3f41176a868a45b4bd565ad1740be8cf\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/loren\/files\/saveCodeBackups.png\" onError=\"this.style.display ='none';\" \/><\/div><!--introduction--><p>Today I am going to talk a little about code development and appropriate hygiene that goes with it.  Why?  Well, have you ever ended up with a really sick feeling after spending hours on something, only to realize that it's been deleted?  It's happened to me, but never again!... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/loren\/2016\/05\/13\/save-yourself\/\">read more >><\/a><\/p>","protected":false},"author":39,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/1495"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/users\/39"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/comments?post=1495"}],"version-history":[{"count":8,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/1495\/revisions"}],"predecessor-version":[{"id":1981,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/1495\/revisions\/1981"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/media?parent=1495"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/categories?post=1495"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/tags?post=1495"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}