{"id":49,"date":"2019-06-17T16:06:57","date_gmt":"2019-06-17T16:06:57","guid":{"rendered":"https:\/\/esa.org\/students-preprod\/programming\/"},"modified":"2019-06-17T16:06:57","modified_gmt":"2019-06-17T16:06:57","slug":"programming","status":"publish","type":"page","link":"https:\/\/esa.org\/students\/programming\/","title":{"rendered":"Programming"},"content":{"rendered":"<div style=\"width: 386px\" class=\"wp-caption alignnone\"><img decoding=\"async\" src=\"https:\/\/static1.squarespace.com\/static\/533e0acce4b05289c3da32ce\/t\/5799aa122994ca29c7614117\/1469688340900\/computer.png?format=original\" alt=\"   (you should learn to communicate) -- computer   \" class=\"img-fluid\"><p class=\"wp-caption-text\">(you should learn to communicate) \u2014 computer<\/p><\/div>\n<p>\u00a0<\/p>\n<p><span style=\"font-size:12.8px\">Scientific insight demands crunching numbers. Managing and analyzing small and large datasets can be done with point-and-click software, but you will be limited. Coding your own computing scripts for managing and analyzing ecological data will set you apart from your colleagues and give you a technical skill that is transferable across sub-disciplines of ecology and beyond. This section provides suggestions and resources to help you learn and improve your programming skills.<\/span><\/p>\n<h2>Quick Links<\/h2>\n<ul>\n<li><a href=\"#etiquette_code\">Programming Etiquette<\/a><\/li>\n<li><a href=\"#troubleshoot_code\">Troubleshooting Code<\/a><\/li>\n<li><a href=\"#code_resources\">Coding Resources<\/a><\/li>\n<\/ul>\n<p>\u00a0<\/p>\n<hr>\n<p><strong id=\"etiquette_code\"><\/strong><\/p>\n<h1>ETIQUETTE IN COMPUTER PROGRAMMING<\/h1>\n<p>The point of maintaining etiquette when programming has most to do with writing understandable code. Ideally you will want others to use and build off the code you develop. You will also most likely be required to modify or utilize someone else\u2019s code. You will always run into messy code, but as long as the developers are self-consistent in their coding practices, then understanding the code will be easier. Best is to maintain certain standards for writing code, some of which are outlined below.<\/p>\n<p>\u00a0<\/p>\n<ul>\n<li><strong>Naming conventions: us yr wds<\/strong>\n<ul>\n<li>It is understandable to use variables or shortened names, but going back and forth between tens to thousands of lines of code to remember what <em>fd <\/em>means is maddening. Use descriptive names for uncommon variables, e.g. instead of <em>fd<\/em>, use <em>flight_dist<\/em>. There is no penalty for using longer names in terms of computer speed.<\/li>\n<li>When writing code for mathematical equations, use the standard variables or better yet, spell out what the variables describe, e.g. instead of <em>p<\/em>, use <em>density<\/em>.<\/li>\n<li><em>Foo <\/em>and its variants are common example variables, but better clarity can be obtained by using <em>\u2018trash_XX\u2019, \u2018temp_XX\u2019, or \u2018test_XX\u2019. <\/em>An additional benefit is that you can search, replace or delete all instances of such temporary or debugging variables rather easily.<\/li>\n<li>For variable names, use the underscore and capitalization liberally. Typing the underscore will become muscle memory and it will help clarify variable names, e.g. <em>primary_forest <\/em>and <em>secondary_forest<\/em> or <em>primaryForest <\/em>and <em>secondaryForest<\/em>. Many examples in R utilize the dot \u2018.\u2019 for extending variable names, but the underscore has no other interpretation in computer programming and it is therefore a safe practice. Care should be taken with using capitalization (in Single or BLOCK forms) for distinguishing variables because not all computer languages are case-sensitive.<\/li>\n<\/ul>\n<\/li>\n<li><strong>You are writing <em>hard <\/em>code<\/strong>\n<ul>\n<li>Even if you are writing code for a short-term project, develop the habit of writing flexible code, such that you may later easily change a parameter value and run the code again. Most generally, the fixed-value parameters in the code should be defined once at the top of the code, or in a separate \u2018header file\u2019<\/li>\n<li>Many times you will encounter situations in which multiple lines of code are repeated throughout your program. A simplifying procedure is to <em>refactor<\/em> multiple lines of code into a separate class or function, such that you replace multiple lines of code with a single line of code. The procedure creates variables that are passed into the function each time it is called. Many code editors contain functions in drop-down-like menus for refactoring code, and the automation is useful for learning how common blocks of code are compartmentalized and simplified.<\/li>\n<\/ul>\n<\/li>\n<li><strong>It\u2019s not obvious,<em> <\/em>Annotate everything<\/strong>\n<ul>\n<li>Add a comment above every line of code that is not hit-your-head obvious. Describe briefly what the next line of code does. Do this for each instance of the code, not just the first time it occurs as not everyone will need to read the code from the beginning \u2013 ever read through a publication with 20+ acronyms?<\/li>\n<li>Write descriptive comment blocks at the beginnings of important sections of code. Describe generally what the code block does, its inputs and outputs.<\/li>\n<li>Be generous with tabs and spaces when organizing your code and it will vastly improve the readability of your code.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong id=\"troubleshoot_code\"><\/strong><\/p>\n<h1>TROUBLESHOOTING CODE<\/h1>\n<ul>\n<li>You can cut it if you can hack it\n<ul>\n<li>Even expert programmers make liberal use of copy and paste to rework code from their own repositories or from others.<\/li>\n<li>Instead of going back to a particular project to view portions of code, e.g. to view how you coded a distance analysis in a spatio-temporal array, save unique code snippets in a repository to which you can easily search for important coding blocks. Start by saving important or new code blocks into separate files in a <em>scripts<\/em> folder on your computer. Better is to use a resource like GIT to store, share, and get feedback on improving your code.<\/li>\n<\/ul>\n<\/li>\n<li>Versioning and Coding Communities (GIT, Evernote)\n<ul>\n<li><a href=\"https:\/\/git-scm.com\/\">https:\/\/git-scm.com\/<\/a> \u2014 version control<\/li>\n<li><a href=\"https:\/\/codeshare.io\/\">https:\/\/codeshare.io\/<\/a> \u2014 share code in real-time; like google-docs but for code<\/li>\n<li><em>The wise person said, \u201cgoogle this \u2026\u201d<\/em><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong id=\"code_resources\"><\/strong><\/p>\n<h1>CODE RESOURCES<\/h1>\n<ul>\n<li>Online Compilers for 50+ programming languages\n<ul>\n<li><a href=\"http:\/\/www.tutorialspoint.com\/codingground.htm\">http:\/\/www.tutorialspoint.com\/codingground.htm<\/a> \u2014 fantastic resource for testing small sections of code.<\/li>\n<\/ul>\n<\/li>\n<li>Learn to Code\n<ul>\n<li><a href=\"https:\/\/scratch.mit.edu\/\">https:\/\/scratch.mit.edu\/<\/a>\u00a0 \u2014 simple to super advanced<\/li>\n<li><a href=\"https:\/\/www.madewithcode.com\/\">https:\/\/www.madewithcode.com\/<\/a> \u2014 google\u2019s effort for learning code, but clunky<\/li>\n<\/ul>\n<\/li>\n<li><em>a<\/em> Primer<em> <\/em>on R\n<ul>\n<li><a href=\"http:\/\/www.statmethods.net\/\">http:\/\/www.statmethods.net\/<\/a> \u2014 for the beginner, this is gold<\/li>\n<li><a href=\"https:\/\/cran.r-project.org\/doc\/contrib\/Paradis-rdebuts_en.pdf\">https:\/\/cran.r-project.org\/doc\/contrib\/Paradis-rdebuts_en.pdf<\/a><\/li>\n<li><a href=\"http:\/\/www.ats.ucla.edu\/stat\/r\/\">http:\/\/www.ats.ucla.edu\/stat\/r\/<\/a> \u2014 more resources<\/li>\n<\/ul>\n<\/li>\n<li>Data Visualization\n<ul>\n<li><a target=\"_blank\" href=\"http:\/\/shinyapps.org\/apps\/RGraphCompendium\/index.php\" rel=\"noopener noreferrer\">http:\/\/shinyapps.org\/apps\/RGraphCompendium\/index.php<\/a>\n<ul>\n<li>by far the best stand-alone resource for R code-snippet to the best of our knowledge<\/li>\n<\/ul>\n<\/li>\n<li><a target=\"_blank\" href=\"http:\/\/www.r-bloggers.com\/\" rel=\"noopener noreferrer\">http:\/\/www.r-bloggers.com\/<\/a>\u00a0\u2014 use the search tool<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u00a0<\/p>\n<ul>\n<li>Geospatial Data in R\n<ul>\n<li>You are still doing things in <em>Arc<\/em>? Try the package <em><a target=\"_blank\" href=\"https:\/\/cran.r-project.org\/web\/packages\/raster\/vignettes\/Raster.pdf\" rel=\"noopener noreferrer\">raster<\/a><\/em><\/li>\n<\/ul>\n<\/li>\n<li><!--[if !supportLists]--><!--[endif]-->For spatio-temporal data analysis, use netcdf file format \u2013 extremely compact\n<ul>\n<li>Learn the processing languages\n<ul>\n<li><a target=\"_blank\" href=\"http:\/\/nco.sourceforge.net\/#Definition\" rel=\"noopener noreferrer\">NCO<\/a>\n<ul>\n<li>netCDF operators is a software package with functions for managing netcdf files<\/li>\n<\/ul>\n<\/li>\n<li><a target=\"_blank\" href=\"https:\/\/code.zmaw.de\/projects\/cdo\/embedded\/index.html\" rel=\"noopener noreferrer\">CDO<\/a>\n<ul>\n<li>Originally developed for processing large spatio-temporal climate datasets, but code can be used to process many spatial and spatio-temporal datasets, including binary, geotiffs and plain-text files (ascii).<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u00a0<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 Scientific insight demands crunching numbers. Managing and analyzing small and large datasets can be done with point-and-click software, but you will be limited. Coding your own computing scripts for managing and analyzing ecological data will set you apart from your colleagues and give you a technical skill that is transferable across sub-disciplines of ecology and beyond. This section provides&#8230;<\/p>\n","protected":false},"author":9,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-49","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/esa.org\/students\/wp-json\/wp\/v2\/pages\/49","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/esa.org\/students\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/esa.org\/students\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/esa.org\/students\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/esa.org\/students\/wp-json\/wp\/v2\/comments?post=49"}],"version-history":[{"count":0,"href":"https:\/\/esa.org\/students\/wp-json\/wp\/v2\/pages\/49\/revisions"}],"wp:attachment":[{"href":"https:\/\/esa.org\/students\/wp-json\/wp\/v2\/media?parent=49"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}