{"id":659,"date":"2013-07-06T07:21:41","date_gmt":"2013-07-06T05:21:41","guid":{"rendered":"http:\/\/antoine.wojdyla.free.fr\/blog\/?p=659"},"modified":"2013-12-08T05:01:20","modified_gmt":"2013-12-08T03:01:20","slug":"lab-resources-ii-software-coding","status":"publish","type":"post","link":"http:\/\/antoine.wojdyla.fr\/blog\/2013\/07\/06\/lab-resources-ii-software-coding\/","title":{"rendered":"Lab resources II- Software coding"},"content":{"rendered":"<p>Sometimes, I wonder &#8220;WWFD?&#8221;<br \/>\nHere&#8217;s a collection of ideas and resources for scientific programming.<\/p>\n<div id=\"attachment_897\" style=\"width: 695px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/antoine.wojdyla.free.fr\/blog\/wp-content\/uploads\/programmers_steps.png\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'http:\/\/antoine.wojdyla.free.fr\/blog\/wp-content\/uploads\/programmers_steps.png', '']);\" ><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-897\" class=\"size-full wp-image-897\" title=\"programmers_steps\" alt=\"\" src=\"http:\/\/antoine.wojdyla.free.fr\/blog\/wp-content\/uploads\/programmers_steps.png\" width=\"685\" height=\"609\" \/><\/a><\/p>\n<p id=\"caption-attachment-897\" class=\"wp-caption-text\">Steps in programming&#8230;<\/p>\n<\/div>\n<p style=\"text-align: left;\"><!--more--><br \/>\nThe best personal advice I can give you is : take your time to design (spending 10 minutes can save you a week).<br \/>\nAlso, do not hesitate to spend time on thinking of how to<a href=\"http:\/\/antoine.wojdyla.free.fr\/blog\/?p=352\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'http:\/\/antoine.wojdyla.free.fr\/blog\/?p=352', ' visualize your data ']);\" title=\"The Visual Display of Quantitative Information\"> visualize your data <\/a>: it makes a huge difference, for you and for others !<\/p>For the rest, follow the list !<\/p>\n<h1>Coding best practice<\/h1>\n<ol>\n<li>Commenting & documentation (design and purpose, not mechanics)\n<ol>\n<li>Consistent indentation (do not mix space and tabs)<\/li>\n<li>Avoid obvious comments<\/li>\n<\/ol>\n<\/li>\n<li>Consistent naming scheme (define it!)\n<ol>\n<li>Minimize the use of abbreviations<\/li>\n<li>Consistent temporary names<\/li>\n<li>Avoid homonyms<\/li>\n<li>Pair antonym procedures (open\/close, etc.)<\/li>\n<\/ol>\n<\/li>\n<li>Keep your code simple (The \u201c20 lines\u201d rule)\n<ol>\n<li>Avoid deep nesting (hard to read)<\/li>\n<li>Limit line length (hard to read & viewer dependancy)<\/li>\n<li>File and folder organization<\/li>\n<li>Don\u2019t repeat yourself<\/li>\n<li>Code refactoring<\/li>\n<li>Code grouping<\/li>\n<li>Use globals sparingly<\/li>\n<\/ol>\n<\/li>\n<li>Write programs for people, not computers\n<ol>\n<li>Do you have testers\/hallway usability testing?<\/li>\n<li>Provide useful error messages<\/li>\n<\/ol>\n<\/li>\n<li>Have a high level design or a low level design and Function specification and proof of concepts\n<ol>\n<li>Push interface up and implementation down\n<ol>\n<li>i.\u00a0\u00a0\u00a0\u00a0\u00a0 Level 1 (high): accept user input<\/li>\n<li>ii.\u00a0\u00a0\u00a0\u00a0\u00a0 Level 2: taint check and normalize user input, and check for errors<\/li>\n<li>iii.\u00a0\u00a0\u00a0\u00a0\u00a0 Level 3: process user input according to business logic<\/li>\n<li>iv.\u00a0\u00a0\u00a0\u00a0\u00a0 Level 4 (low): store data<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<li>Separation of code and data\n<ol>\n<li>Wrap built-in functions and third-party library functions with your own wrapper functions<\/li>\n<li>Don\u2019t assume output formats<\/li>\n<li>Internal data should be in native format<\/li>\n<li>Operate on objects, not data structure<\/li>\n<\/ol>\n<\/li>\n<li>Test returned status for error conditions\n<ol>\n<li>Recover or fail \u201cgracefully\u201d : Robust programs should report an error message<\/li>\n<\/ol>\n<\/li>\n<li>\u201c<em>Premature optimization is the root of evil<\/em>\u201d (Optimize software only after it works correctly)<\/li>\n<li>Never rewrite code from scratch<\/li>\n<\/ol><p>I found this list on the internet, less formal but still very interesting :<\/p>\n<ul>\n<li>Found on a wall in a mechanical engineering shop. But many of these dicta apply just as well to software engineering.<\/li>\n<li>Engineering is done with numbers. Analysis without numbers is, at best, only an opinion.<\/li>\n<li>Design is an iterative process. The necessary number of iterations is one more than the number you have currently done. This is true at any point in time.<\/li>\n<li>Everything is linear if plotted log-log with a fat magic marker.<\/li>\n<li>When in doubt, estimate. In an emergency, guess. But be sure to go back and clean up the mess when real numbers come along.<\/li>\n<li>The odds are greatly against your being immensely smarter than everyone else in the field. If your analysis says your terminal velocity is twice the speed of light, the chances are better that you&#8217;ve screwed up than that you&#8217;ve invented warp drive.<\/li>\n<li>At the start of any design effort, the person who most wants to be team leader is least likely to be capable of it.<\/li>\n<li>In nature, the optimum is almost always in the middle somewhere. Distrust assertions that the optimum is at an extreme point.<\/li>\n<li>Not having all the information you need is never a satisfactory excuse for not starting the analysis.<\/li>\n<li>Your best efforts will inevitably wind up being useless in the final design. Learn to live with the disappointment.<\/li>\n<li>Sometimes, the fastest way to get to the end is to throw everything out and start over.<\/li>\n<li>There is never a single right solution. But there are always multiple wrong ones.<\/li>\n<li>Design is based on requirements. There&#8217;s no justification for designing something one bit &#8220;better&#8221; than the requirements dictate.<\/li>\n<li>&#8220;Better&#8221; is the enemy of &#8220;good&#8221;.<\/li>\n<li>The ability to improve a design occurs primarily at the interfaces. This is also the prime location for screwing it up.<\/li>\n<li>The previous people who did a similar analysis did not have a direct pipeline to the wisdom of the ages. There is therefore no reason to believe their analysis over yours. There is especially no reason to present their analysis as yours.<\/li>\n<li>The fact that an analysis appears in print has no relationship to the likelihood of its being correct.<\/li>\n<li>Past experience is excellent for providing a reality check. On the other hand, too much reality can doom an otherwise worthwhile design.<\/li>\n<li>A bad design with a good presentation is doomed eventually. A good design with a bad presentation is doomed immediately.<\/li>\n<li>Half of everything you hear in a classroom is crap. Education is figuring out which half is which.<\/li>\n<li>When in doubt, document. Documentation requirements will reach a maximum shortly after the termination of the project.<\/li>\n<li>It&#8217;s called a &#8220;Work Breakdown Structure&#8221; because the Work remaining will grow until you have a Breakdown, unless you enforce some Structure on it.<\/li>\n<li>The first 90 percent of the project takes 90 percent of the allotted time. The last 10 percent of the project takes the other 90 percent.<\/li>\n<\/ul><p><span style=\"text-decoration: underline;\">Programming books :<\/span><\/p>For programming, I don&#8217;t have a particular reference, apart &#8220;<a href=\"http:\/\/www.nr.com\/\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'http:\/\/www.nr.com\/', 'The numerical recipes']);\" title=\"Numerical Recipes website\">The numerical recipes<\/a> (in C)&#8221;\u00a0 (pdf\u00a0<a href=\"http:\/\/www2.units.it\/ipl\/students_area\/imm2\/files\/Numerical_Recipes.pdf\" onclick=\"_gaq.push(['_trackEvent','download','http:\/\/www2.units.it\/ipl\/students_area\/imm2\/files\/Numerical_Recipes.pdf']);\" title=\"Numerical Reciped in C - pdf\">here<\/a>) which is a reference if you want to find any particular type of algorithm (and that wouldn&#8217;t be otherwise coded in Matlab;-).\u00a0If you want to learn how to code, you should look at the many tutorials arund the web. To learn C#, I liked &#8220;<a href=\"http:\/\/www.amazon.com\/Microsoft-Visual-2010-Step\/dp\/0735626707\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'http:\/\/www.amazon.com\/Microsoft-Visual-2010-Step\/dp\/0735626707', 'C# step by step']);\" title=\"C# Step by Step - Amazon\">C# step by step<\/a>\u00bb. &#8220;<a href=\"http:\/\/en.wikipedia.org\/wiki\/The_Art_of_Computer_Programming\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'http:\/\/en.wikipedia.org\/wiki\/The_Art_of_Computer_Programming', 'The Art of Computer Programming']);\" title=\"The Art of computer programming - Wikipedia\">The Art of Computer Programming<\/a>&#8221; by<a href=\"http:\/\/en.wikipedia.org\/wiki\/Donald_Knuth\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'http:\/\/en.wikipedia.org\/wiki\/Donald_Knuth', ' D. Knuth']);\" title=\"Donald Knuth - Wikipedia\"> D. Knuth<\/a> is said to be a reference, but I haven&#8217;t read it\u00a0yet. Instead, you can take a look at the very comprehensive Jeff Erickson&#8217;s <a href=\"http:\/\/compgeom.cs.uiuc.edu\/~jeffe\/teaching\/algorithms\/\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'http:\/\/compgeom.cs.uiuc.edu\/~jeffe\/teaching\/algorithms\/', 'Algorithm']);\" title=\"Jeff Erickson's Algorithms\">Algorithm<\/a> website, full of very interesting lessons (I love the one of <a href=\"http:\/\/compgeom.cs.uiuc.edu\/~jeffe\/teaching\/algorithms\/notes\/02-fft.pdf\" onclick=\"_gaq.push(['_trackEvent','download','http:\/\/compgeom.cs.uiuc.edu\/~jeffe\/teaching\/algorithms\/notes\/02-fft.pdf']);\" title=\"FFT - Jeff Erickson's algorithms\"  target=\"_blank\">FFTs<\/a>;-)<\/p>It is not exactly programming, but I want to mention &#8220;<a href=\"http:\/\/mitpress.mit.edu\/sites\/default\/files\/titles\/content\/9780262514293_Creative_Commons_Edition.pdf\" onclick=\"_gaq.push(['_trackEvent','download','http:\/\/mitpress.mit.edu\/sites\/default\/files\/titles\/content\/9780262514293_Creative_Commons_Edition.pdf']);\" title=\"Streetfighting mathematics pdf\">Streetfighting Mathematics<\/a>&#8221; (free) by\u00a0Sanjoy Mahajan would tackle many mathematical problems, easing the implementation in a computer.<\/p><span style=\"text-decoration: underline;\">Signal processing books :<\/span><\/p>&#8220;<a href=\"http:\/\/www.amazon.fr\/Analyse-traitement-signaux-M%C3%A9thodes-applications\/dp\/2100524372\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'http:\/\/www.amazon.fr\/Analyse-traitement-signaux-M%C3%A9thodes-applications\/dp\/2100524372', 'Analyse et traitement des signaux : M\u00e9thodes et applications au son et \u00e0 l&#8217;image']);\" >Analyse et traitement des signaux : M\u00e9thodes et applications au son et \u00e0 l&#8217;image<\/a>&#8221; by E. Tisserand is a very nice book, with very good explanations and useful applications, while &#8220;<a href=\"http:\/\/www.amazon.fr\/Traitement-num%C3%A9rique-signal-9e-%C3%A9d\/dp\/2100582194\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'http:\/\/www.amazon.fr\/Traitement-num%C3%A9rique-signal-9e-%C3%A9d\/dp\/2100582194', 'Traitement num\u00e9rique du signal']);\" >Traitement num\u00e9rique du signal<\/a>&#8221; by M. Bellanger is boring and has few ready-made uses.<\/p>Talking about filters and Fourier, I really liked reading Roddier&#8217;s &#8220;<a href=\"roddier : http:\/\/www.amazon.fr\/Distributions-transformation-Fourier-physiciens-ing%C3%A9nieurs\/dp\/2704210047\/\">Distributions et transformation de Fourier : \u00e0 l&#8217;usage des physiciens et des ing\u00e9nieurs<\/a>&#8221; (hard to find), or Bracewell&#8217;s &#8220;<a href=\"http:\/\/www.amazon.fr\/Fourier-Transform-Its-Applications-Terman\/dp\/B001BX23YQ\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'http:\/\/www.amazon.fr\/Fourier-Transform-Its-Applications-Terman\/dp\/B001BX23YQ', 'Fourier Transform &amp; Its Applications']);\" >Fourier Transform & Its Applications<\/a>&#8221; (you can have a somewhat equivalent here :\u00a0<a href=\"http:\/\/see.stanford.edu\/materials\/lsoftaee261\/book-fall-07.pdf\" onclick=\"_gaq.push(['_trackEvent','download','http:\/\/see.stanford.edu\/materials\/lsoftaee261\/book-fall-07.pdf']);\" >pdf<\/a>)<\/p><span style=\"text-decoration: underline;\">Sources :<\/span><\/p><a href=\"http:\/\/net.tutsplus.com\/tutorials\/html-css-techniques\/top-15-best-practices-for-writing-super-readable-code\/\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'http:\/\/net.tutsplus.com\/tutorials\/html-css-techniques\/top-15-best-practices-for-writing-super-readable-code\/', 'http:\/\/net.tutsplus.com\/tutorials\/html-css-techniques\/top-15-best-practices-for-writing-super-readable-code\/\\n']);\" >http:\/\/net.tutsplus.com\/tutorials\/html-css-techniques\/top-15-best-practices-for-writing-super-readable-code\/<br \/>\n<\/a><a href=\"http:\/\/www.kmoser.com\/articles\/Good_Programming_Practices.php\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'http:\/\/www.kmoser.com\/articles\/Good_Programming_Practices.php', 'http:\/\/www.kmoser.com\/articles\/Good_Programming_Practices.php\\n']);\" >http:\/\/www.kmoser.com\/articles\/Good_Programming_Practices.php<br \/>\n<\/a><a href=\"http:\/\/www.homepages.ucl.ac.uk\/~ucappgu\/seminars\/good-practice.pdf\" onclick=\"_gaq.push(['_trackEvent','download','http:\/\/www.homepages.ucl.ac.uk\/~ucappgu\/seminars\/good-practice.pdf']);\" >http:\/\/www.homepages.ucl.ac.uk\/~ucappgu\/seminars\/good-practice.pdf<br \/>\n<\/a><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa260844(v=vs.60).aspx\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'http:\/\/msdn.microsoft.com\/en-us\/library\/aa260844(v=vs.60).aspx', 'http:\/\/msdn.microsoft.com\/en-us\/library\/aa260844(v=vs.60).aspx\\n']);\" >http:\/\/msdn.microsoft.com\/en-us\/library\/aa260844(v=vs.60).aspx<br \/>\n<\/a><a href=\"http:\/\/en.wikipedia.org\/wiki\/Best_Coding_Practices\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'http:\/\/en.wikipedia.org\/wiki\/Best_Coding_Practices', 'http:\/\/en.wikipedia.org\/wiki\/Best_Coding_Practices\\n']);\" >http:\/\/en.wikipedia.org\/wiki\/Best_Coding_Practices<br \/>\n<\/a><a href=\"http:\/\/arxiv.org\/abs\/1210.0530\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'http:\/\/arxiv.org\/abs\/1210.0530', 'http:\/\/arxiv.org\/abs\/1210.0530\\n']);\" >http:\/\/arxiv.org\/abs\/1210.0530<br \/>\n<\/a><a href=\"http:\/\/www.joelonsoftware.com\/articles\/fog0000000069.html\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'http:\/\/www.joelonsoftware.com\/articles\/fog0000000069.html', 'http:\/\/www.joelonsoftware.com\/articles\/fog0000000069.html\\n']);\" >http:\/\/www.joelonsoftware.com\/articles\/fog0000000069.html<br \/>\n<\/a><a href=\"http:\/\/www.joelonsoftware.com\/articles\/fog0000000043.html\" onclick=\"_gaq.push(['_trackEvent', 'outbound-article', 'http:\/\/www.joelonsoftware.com\/articles\/fog0000000043.html', 'http:\/\/www.joelonsoftware.com\/articles\/fog0000000043.html\\n']);\" >http:\/\/www.joelonsoftware.com\/articles\/fog0000000043.html<br \/>\n<\/a><a href=\"http:\/\/www.nws.noaa.gov\/oh\/hrl\/developers_docs\/General_Software_Standards.pdf\" onclick=\"_gaq.push(['_trackEvent','download','http:\/\/www.nws.noaa.gov\/oh\/hrl\/developers_docs\/General_Software_Standards.pdf']);\" >http:\/\/www.nws.noaa.gov\/oh\/hrl\/developers_docs\/General_Software_Standards.pdf<\/a><\/p><span style=\"color: #c0c0c0;\">Matlab ctrl+scroll, pixel registration<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes, I wonder &#8220;WWFD?&#8221; Here&#8217;s a collection of ideas and resources for scientific programming.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,14,16,9],"tags":[],"class_list":["post-659","post","type-post","status-publish","format-standard","hentry","category-english","category-projects","category-resources","category-science"],"_links":{"self":[{"href":"http:\/\/antoine.wojdyla.fr\/blog\/wp-json\/wp\/v2\/posts\/659","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/antoine.wojdyla.fr\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/antoine.wojdyla.fr\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/antoine.wojdyla.fr\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/antoine.wojdyla.fr\/blog\/wp-json\/wp\/v2\/comments?post=659"}],"version-history":[{"count":37,"href":"http:\/\/antoine.wojdyla.fr\/blog\/wp-json\/wp\/v2\/posts\/659\/revisions"}],"predecessor-version":[{"id":989,"href":"http:\/\/antoine.wojdyla.fr\/blog\/wp-json\/wp\/v2\/posts\/659\/revisions\/989"}],"wp:attachment":[{"href":"http:\/\/antoine.wojdyla.fr\/blog\/wp-json\/wp\/v2\/media?parent=659"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/antoine.wojdyla.fr\/blog\/wp-json\/wp\/v2\/categories?post=659"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/antoine.wojdyla.fr\/blog\/wp-json\/wp\/v2\/tags?post=659"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}