{"id":1397,"date":"2009-06-10T17:02:02","date_gmt":"2009-06-10T16:02:02","guid":{"rendered":"http:\/\/www.walkingrandomly.com\/?p=1397"},"modified":"2009-06-11T15:53:50","modified_gmt":"2009-06-11T14:53:50","slug":"should-fortran-be-taught-to-undergraduates","status":"publish","type":"post","link":"https:\/\/walkingrandomly.com\/?p=1397","title":{"rendered":"Should Fortran be taught to Undergraduates?"},"content":{"rendered":"<p>Back in 1997 I was a 2nd year undergraduate of Physics and I was taught how to program in <a href=\"http:\/\/en.wikipedia.org\/wiki\/Fortran\">Fortran<\/a>, a language that has survived over 40 years due to several facts including<\/p>\n<ul>\n<li> It is very good at what it does.\u00a0 Well written Fortran code, pushed through the right compiler is screamingly fast.<\/li>\n<li>There are millions of lines of legacy code still being used in the wild.\u00a0 If you end up doing research in subjects such as Chemistry, Physics or Engineering then you will almost certainly bump into Fortran code (I did!).<\/li>\n<li>A beginner&#8217;s course in Fortran has been part of the staple diet in degrees in Physics, Chemistry and various engineering disciplines (among others) for decades.<\/li>\n<li>It constantly re-invents itself to include new features.\u00a0 I was taught Fortran 77 (despite it being 1997) but you can now also have your pick of Fortran 90, 95, 2003, and soon 2008.<\/li>\n<\/ul>\n<p>Almost everyone I knew hated that 1997 Fortran course and the reasons for the hatred essentially boiled down to one of two points depending on your past experience.<\/p>\n<ul>\n<li>Fortran was too hard!\u00a0 So much work for such small gains (First time &#8211; programmers)<\/li>\n<li>The course was far too easy.\u00a0 It was just a matter of learning Fortran syntax and blitzing through the exercises. (People with prior experience)<\/li>\n<\/ul>\n<p>The course was followed by a numerical methods course which culminated in a set of projects that had to be solved in Fortran.\u00a0 People hated the follow on course for one of two reasons<\/p>\n<ul>\n<li>They didn&#8217;t have a clue what was going on in the first course and now they were completely lost.<\/li>\n<li>The problems given were very dull and could be solved too easily.\u00a0 In Excel!\u00a0 Fortran was then used to pass the course.<\/li>\n<\/ul>\n<p>Do you see a pattern here?<\/p>\n<p>Fast forward to 2009 and I see that Fortran is still being taught to many undergraduates all over the world as their <strong>first ever introduction to programming<\/strong>.\u00a0 Bear in mind that these students are used to being able to get interactive 3D plots from the likes of Mathematica, Maple or MATLAB and can solve complex differential equations simply by typing them into <a href=\"http:\/\/www.wolframalpha.com\/examples\/DifferentialEquations.html\">Wolfram Alpha<\/a> on the web.\u00a0 They can solve problems infinitely more complicated then the ones I was faced with in even my most advanced Fortran courses with just a couple of lines of code.<\/p>\n<h3>Learn Fortran &#8211; spend a semester achieving not very much<\/h3>\n<p>These students study subjects such as physics and chemistry because they are interested in the subject matter and computers are just a way of crunching through numbers (and the algebra for that matter) as far as they are concerned.\u00a0 Despite having access to untold amounts of computational and visualisation power coupled with easy programming languages thanks to languages such as <a href=\"http:\/\/www.mathworks.co.uk\/\">MATLAB<\/a> and <a href=\"http:\/\/www.python.org\/\">Python<\/a>, these enthusiastic, young potential programmers get forced to bend their minds around the foibles of Fortran.<\/p>\n<p>For many it&#8217;s their <strong>first ever <\/strong>introduction to programming and they get forced to work with one of the most painful programming languages in existence (in my opinion at least).\u00a0\u00a0 Looking at a typical one-semester course it seems that by the time they have finished they will be able to produce command line only programs that do things like multiply <strong>matrices together (slowly)<\/strong>,<strong> solve the quadratic equation<\/strong> and <strong>find the mean and standard deviation of a list of numbers<\/strong>.<\/p>\n<p>Not particularity impressive for an introduction to the power of computation in their subject is it?<\/p>\n<p>Fortran syntax is rather unforgiving compared to something like Python and it takes many lines of code to achieve even relatively simple results.\u00a0 Don&#8217;t believe me?\u00a0 OK, write a program in pure Fortran that gives a plot of a Sin(n*x) for integer n and x ranging from -2*pi to 2*pi.\u00a0 Now connect that plot up to a slider control which will control the value of n.\u00a0 Done?\u00a0 Ok &#8211; now get it working on another operating system (eg if you originally used Windows, get it to work on Mac OS X).<\/p>\n<p>Now try the same exercise in Python or Mathematica.<\/p>\n<p>This is still a very basic program but it would give a much greater sense of achievement compared to finding the mean of list of numbers and could easily be extended for more able students (Fourier Series perhaps).\u00a0 I believe that many introductory Fortran programming courses end up teaching students that <strong>programming means &#8216;Calculating things the hard way&#8217;<\/strong> when they should be leaving an introductory course with the opposite impression.<\/p>\n<h3>Learn Fortran &#8211; and never use it again.<\/h3>\n<p>Did you learn Fortran at University?\u00a0 Are you still using it?\u00a0 If you answer yes to both of those questions then there is a high probability that you are still involved in research or that advanced numerical analysis is the mainstay of your job.\u00a0 I know a lot of people in the (non-academic) IT industry &#8211; many of them were undergraduates in Physics or Chemistry and so they learned Fortran.\u00a0 They don&#8217;t use it anymore.\u00a0 In fact they never used it since completing their 1st semester, 2nd year exam and that <strong>includes<\/strong> the computational projects they chose to do as part of their degrees.<\/p>\n<p>The fact of the matter is that most undergraduates in subjects such as Physics end up in careers that have nothing to do with their degree subject and so most of them will never use Fortran ever again.\u00a0 The &#8216;programming concepts&#8217; they learned might be useful if they end up learning Java, Python or something along those lines but that&#8217;s about it.\u00a0 Would it not be more sensible to teach a language that can support the computational concepts required in the underlying subject that also has an outside chance of being used outside of academia?<\/p>\n<h3>Teach Fortran &#8211; and spend a fortune on compilers<\/h3>\n<p>There are<a href=\"http:\/\/g95.org\/\"> free Fortran compilers<\/a> available but in my experience these are not the ones that get used the most for teaching or research and this is because the commercial Fortran compilers tend to be (or at least,they are perceived to be) much better.\u00a0 The problem is that when you are involved with looking after the software portfolio of a large University (and I am) then no one will agree on what &#8216;the best&#8217; compiler is.\u00a0 (Very) roughly paraphrased, here are some comments I have received from Fortran programmers and teachers over the last four years or so.<\/p>\n<ul>\n<li>When you teach Fortran, you MUST use the <a href=\"http:\/\/www.nag.com\/nagware\/np\/fortranbuilder.asp\">NAG Fortran compiler<\/a> since it is the most standards compliant.\u00a0 The site license allows students to have it on their own machines which is useful.<\/li>\n<li>When you teach Fortran, you MUST use the<a href=\"http:\/\/www.silverfrost.com\/11\/ftn95\/overview.asp\"> Silverfrost compiler<\/a> because it supports Windows GUI programming via Clearwin.<\/li>\n<li>We MUST avoid the Silverfrost compiler for teaching because it is not available on platforms such as Mac and Linux.<\/li>\n<li>We MUST avoid the NAG compiler for teaching because although it has a great user interface for Windows, it is command line only for Linux and Mac.\u00a0 This confuses students.<\/li>\n<li>If we are going to teach Fortran then we simply MUST use the<a href=\"http:\/\/software.intel.com\/en-us\/articles\/intel-fortran-compiler-for-linux-support-resources\/\"> Intel Fortran Compiler<\/a>.\u00a0 It&#8217;s the best and the fastest.<\/li>\n<li>We need the Intel Fortran Compiler for research because it is the only one compatible with <a href=\"http:\/\/www.simulia.com\/\">Abaqus<\/a>.<\/li>\n<li>A site license for <a href=\"http:\/\/www.absoft.com\/\">Absoft Fortran<\/a> is essential.\u00a0 It&#8217;s the only one that will compile &lt;insert application here&gt; which is essential for my group&#8217;s work.<\/li>\n<li>We should only ever use free Fortran compilers &#8211; relying on commercial offerings is wrong.<\/li>\n<\/ul>\n<p>I&#8217;m only getting started!\u00a0 Choose a compiler, any compiler &#8211; I&#8217;ll get back to you within the week with an advocate who thinks we should get a site license for it and another who hates it with a passion.\u00a0 Let&#8217;s say you had a blank cheque book and you gave everyone exactly what they wanted &#8211; your institution would be spending <strong>tens of thousands of pounds<\/strong> on Fortran compilers and you&#8217;d <strong>still<\/strong> be annoying the free-software advocate.<\/p>\n<p>Needless to say, most people don&#8217;t have a blank cheque book.\u00a0 At Manchester University (my workplace) we support 2 site-wide Fortran compilers<\/p>\n<ul>\n<li>The NAG Compiler &#8211; recommended for teaching.<\/li>\n<li>The Intel Fortran Compiler &#8211; recommended for research<\/li>\n<\/ul>\n<p>We have a truly unlimited site license for NAG (every student can have a copy on their own machine if they wish) which makes it perfect from a licensing point of view and many people like to use it to teach.\u00a0 The Widows version has a nice GUI and help system for example &#8211; perfect for beginners.\u00a0 There are Mac and Linux versions too and although these are command-line only, they are better than nothing.<\/p>\n<p>The Intel Fortran Compiler licenses we have are in the form of network licenses and we have a very limited number of these &#8211; enough to support the research of every (Windows and Linux) Fortran programmer on campus but nowhere near enough for teaching.\u00a0 To get enough for teaching would cost a lot.<\/p>\n<p>There are also pockets of usage of various other compilers but nothing on a site-wide basis.<\/p>\n<p>Of course, not everyone is happy with this set-up, and I was only recently on the receiving end of a very nasty email from someone because I had to inform him that we didn&#8217;t have the money to buy his compiler of choice.\u00a0 It&#8217;s not my fault that he couldn&#8217;t have it (I don&#8217;t have a budget and never have had) but he felt that I was due an ear lashing I guess and blamed <strong>all<\/strong> of his entire department&#8217;s woes on me personally.\u00a0 Anway, I digress&#8230;.<\/p>\n<p>The upshot is that Fortran compilers are expensive and no one can agree on which one(s) you should get.\u00a0 If you get them all to please (almost) everybody then you will be very cash poor and it won&#8217;t be long before the C++ guys start knocking on your door to discuss the issue of a commercial C++ compiler or three&#8230;.<\/p>\n<h3>Learn Fortran &#8211; because it is still very useful<\/h3>\n<p>Fortran has been around in one form or another for significantly longer than I have been alive for a very good reason.  It&#8217;s good at what it does.  I know a few High Performance Computing specialists and have been reliably informed that if every second counts in your code execution &#8211; if it absolutely, positively, definitely has to run as fast as humanly possible then it is hard to beat Fortran.  I take their word for it because they know what they are talking about.<\/p>\n<p>Organisations such as the <a href=\"http:\/\/www.nag.co.uk\/\">Numerical Algorithm&#8217;s Group<\/a> (NAG) seem to agree with this stance since their core product is a Fortran Library and NAG have a reputation that is hard to ignore.\u00a0 When it comes to numerics &#8211; they know their stuff and they work in Fortran so it MUST be a good choice for certain applications.<\/p>\n<p>If you find yourself using research-level applications such as <a href=\"http:\/\/www.simulia.com\/\">Abaqus<\/a> or <a href=\"http:\/\/www.gaussian.com\/\">Gaussian<\/a> then you&#8217;ll probably end up needing to use Fortran, just as you will if you end up having to modify one of the thousands of legacy applications out there.\u00a0 Fortran is a fact of life for many <strong>graduate<\/strong> students.\u00a0 It was a fact of life for me too once and I hated it.<\/p>\n<p>I <strong>know<\/strong> that it is used a lot at Manchester for research because ,as mentioned earlier, we have network licenses for Intel Fortran and when I am particularly bored I grep the usage logs to see how many unique user names have used it to compile something.\u00a0 There are many.<\/p>\n<p>I am not for a second suggesting that Fortran is irrelevant because it so obviously isn&#8217;t.\u00a0 It is heavily used in certain, specialist areas.\u00a0 What <strong>I am<\/strong> suggesting is that it is <strong>not the ideal language to use as a first exposure to programming<\/strong>.\u00a0 All of the good reasons for using Fortran seem to come up at a time in your career when you are a reasonably advanced programmer not when you first come across the concepts loops and arrays.<\/p>\n<p>Put bluntly I feel that the correct place for learning Fortran is in grad school and only if it is needed.<\/p>\n<h3>If not Introductory Fortran then Introductory what?<\/h3>\n<p>If you have got this far then you can probably guess what I am going to suggest &#8211; <a href=\"http:\/\/www.python.org\/\">Python<\/a>.\u00a0 Python is infinitely more suitable for beginner programmers in my opinion and with even just a smattering of the language it is possible to achieve a great deal.\u00a0 Standard python modules such as <a href=\"http:\/\/matplotlib.sourceforge.net\/\">matplotlib<\/a> and <a href=\"http:\/\/numpy.scipy.org\/\">numpy<\/a> help take care of plotting and heavy-duty numerics with ease and there are no licensing problems to speak of .\u00a0 It&#8217;s free!<\/p>\n<p>You can use it interactively which helps with learning the basics and even a beginner can produce impressive looking results with relatively little effort.\u00a0 Not only is it more fun than Fortran but it is probably a lot more useful for an undergraduate because they might actually use it.\u00a0 Its use in the computational sciences is growing very quickly and it also has a lot of applications in areas such as the web, games and general task automation.<\/p>\n<p>If and when a student is ready to move onto graduate level problems then he\/she may well find that Python still fulfills their needs but if they really do need raw speed then they can either hook into existing Fortran libraries using Python modules such as <a href=\"http:\/\/python.net\/crew\/theller\/ctypes\/\">ctypes<\/a> and <a href=\"http:\/\/www.scipy.org\/F2py\">f2py<\/a> or they can roll up their sleeves and learn Fortran syntax.<\/p>\n<p>Using Fortran to teach raw beginners is a bit like teaching complex numbers to kindergarten children before they can count to ten.\u00a0 Sure, some of them will need complex numbers <strong>one day <\/strong>but if it was complex numbers or nothing then a lot of people would really struggle to count.<\/p>\n<p>So, I am (finally) done.\u00a0 Do I have it all wrong?\u00a0 Is Fortran so essential that Universities would be short changing students of numerate degrees if they didn&#8217;t teach it or are people just teaching what they were taught themselves because that&#8217;s the way it has always been done?\u00a0 I am particularly interested in hearing from either students or teachers of Fortran but, as always, comments from everyone are welcome &#8211; even if you disagree with me.<\/p>\n<p>If you are happy to talk in public then please use the comments section but if you would prefer a private discussion then feel free to <a href=\"https:\/\/www.walkingrandomly.com\/?p=53\">email me<\/a>.<\/p>\n<p>(I am skating closer to my job than I usually do on this blog so here is the hopefully unnecessary disclaimer.\u00a0 These are my opinions alone and do not necessarily reflect the policy of my employer, The Univeristy of Manchester.\u00a0 If you find yourself coming to me for Fortran compiler support there then I will do the very best I can for you &#8211; no matter what my personal programming prejudices may be.\u00a0 However, if you are up for a <strong>friendly<\/strong> chat over coffee concerning this then feel free to drop me a line. )<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Back in 1997 I was a 2nd year undergraduate of Physics and I was taught how to program in Fortran, a language that has survived over 40 years due to several facts including It is very good at what it does.\u00a0 Well written Fortran code, pushed through the right compiler is screamingly fast. There are [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[34,7,31],"tags":[],"class_list":["post-1397","post","type-post","status-publish","format-standard","hentry","category-fortran","category-programming","category-python"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3swhs-mx","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/1397","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1397"}],"version-history":[{"count":14,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/1397\/revisions"}],"predecessor-version":[{"id":1413,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/1397\/revisions\/1413"}],"wp:attachment":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1397"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1397"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1397"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}