{"action":"created","issue":{"url":"https://api.github.com/repos/Fortran-FOSS-Programmers/Best_Practices/issues/15","repository_url":"https://api.github.com/repos/Fortran-FOSS-Programmers/Best_Practices","labels_url":"https://api.github.com/repos/Fortran-FOSS-Programmers/Best_Practices/issues/15/labels{/name}","comments_url":"https://api.github.com/repos/Fortran-FOSS-Programmers/Best_Practices/issues/15/comments","events_url":"https://api.github.com/repos/Fortran-FOSS-Programmers/Best_Practices/issues/15/events","html_url":"https://github.com/Fortran-FOSS-Programmers/Best_Practices/issues/15","id":184432200,"number":15,"title":"goto, is to be or not (used)?","user":{"login":"szaghi","id":1661942,"avatar_url":"https://avatars.githubusercontent.com/u/1661942?v=3","gravatar_id":"","url":"https://api.github.com/users/szaghi","html_url":"https://github.com/szaghi","followers_url":"https://api.github.com/users/szaghi/followers","following_url":"https://api.github.com/users/szaghi/following{/other_user}","gists_url":"https://api.github.com/users/szaghi/gists{/gist_id}","starred_url":"https://api.github.com/users/szaghi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/szaghi/subscriptions","organizations_url":"https://api.github.com/users/szaghi/orgs","repos_url":"https://api.github.com/users/szaghi/repos","events_url":"https://api.github.com/users/szaghi/events{/privacy}","received_events_url":"https://api.github.com/users/szaghi/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Fortran-FOSS-Programmers/Best_Practices/labels/help%20wanted","name":"help wanted","color":"159818"},{"url":"https://api.github.com/repos/Fortran-FOSS-Programmers/Best_Practices/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":{"login":"certik","id":20568,"avatar_url":"https://avatars.githubusercontent.com/u/20568?v=3","gravatar_id":"","url":"https://api.github.com/users/certik","html_url":"https://github.com/certik","followers_url":"https://api.github.com/users/certik/followers","following_url":"https://api.github.com/users/certik/following{/other_user}","gists_url":"https://api.github.com/users/certik/gists{/gist_id}","starred_url":"https://api.github.com/users/certik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/certik/subscriptions","organizations_url":"https://api.github.com/users/certik/orgs","repos_url":"https://api.github.com/users/certik/repos","events_url":"https://api.github.com/users/certik/events{/privacy}","received_events_url":"https://api.github.com/users/certik/received_events","type":"User","site_admin":false},"assignees":[{"login":"certik","id":20568,"avatar_url":"https://avatars.githubusercontent.com/u/20568?v=3","gravatar_id":"","url":"https://api.github.com/users/certik","html_url":"https://github.com/certik","followers_url":"https://api.github.com/users/certik/followers","following_url":"https://api.github.com/users/certik/following{/other_user}","gists_url":"https://api.github.com/users/certik/gists{/gist_id}","starred_url":"https://api.github.com/users/certik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/certik/subscriptions","organizations_url":"https://api.github.com/users/certik/orgs","repos_url":"https://api.github.com/users/certik/repos","events_url":"https://api.github.com/users/certik/events{/privacy}","received_events_url":"https://api.github.com/users/certik/received_events","type":"User","site_admin":false},{"login":"zbeekman","id":279612,"avatar_url":"https://avatars.githubusercontent.com/u/279612?v=3","gravatar_id":"","url":"https://api.github.com/users/zbeekman","html_url":"https://github.com/zbeekman","followers_url":"https://api.github.com/users/zbeekman/followers","following_url":"https://api.github.com/users/zbeekman/following{/other_user}","gists_url":"https://api.github.com/users/zbeekman/gists{/gist_id}","starred_url":"https://api.github.com/users/zbeekman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zbeekman/subscriptions","organizations_url":"https://api.github.com/users/zbeekman/orgs","repos_url":"https://api.github.com/users/zbeekman/repos","events_url":"https://api.github.com/users/zbeekman/events{/privacy}","received_events_url":"https://api.github.com/users/zbeekman/received_events","type":"User","site_admin":false},{"login":"jeffhammond","id":406118,"avatar_url":"https://avatars.githubusercontent.com/u/406118?v=3","gravatar_id":"","url":"https://api.github.com/users/jeffhammond","html_url":"https://github.com/jeffhammond","followers_url":"https://api.github.com/users/jeffhammond/followers","following_url":"https://api.github.com/users/jeffhammond/following{/other_user}","gists_url":"https://api.github.com/users/jeffhammond/gists{/gist_id}","starred_url":"https://api.github.com/users/jeffhammond/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeffhammond/subscriptions","organizations_url":"https://api.github.com/users/jeffhammond/orgs","repos_url":"https://api.github.com/users/jeffhammond/repos","events_url":"https://api.github.com/users/jeffhammond/events{/privacy}","received_events_url":"https://api.github.com/users/jeffhammond/received_events","type":"User","site_admin":false},{"login":"LadaF","id":730129,"avatar_url":"https://avatars.githubusercontent.com/u/730129?v=3","gravatar_id":"","url":"https://api.github.com/users/LadaF","html_url":"https://github.com/LadaF","followers_url":"https://api.github.com/users/LadaF/followers","following_url":"https://api.github.com/users/LadaF/following{/other_user}","gists_url":"https://api.github.com/users/LadaF/gists{/gist_id}","starred_url":"https://api.github.com/users/LadaF/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LadaF/subscriptions","organizations_url":"https://api.github.com/users/LadaF/orgs","repos_url":"https://api.github.com/users/LadaF/repos","events_url":"https://api.github.com/users/LadaF/events{/privacy}","received_events_url":"https://api.github.com/users/LadaF/received_events","type":"User","site_admin":false},{"login":"szaghi","id":1661942,"avatar_url":"https://avatars.githubusercontent.com/u/1661942?v=3","gravatar_id":"","url":"https://api.github.com/users/szaghi","html_url":"https://github.com/szaghi","followers_url":"https://api.github.com/users/szaghi/followers","following_url":"https://api.github.com/users/szaghi/following{/other_user}","gists_url":"https://api.github.com/users/szaghi/gists{/gist_id}","starred_url":"https://api.github.com/users/szaghi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/szaghi/subscriptions","organizations_url":"https://api.github.com/users/szaghi/orgs","repos_url":"https://api.github.com/users/szaghi/repos","events_url":"https://api.github.com/users/szaghi/events{/privacy}","received_events_url":"https://api.github.com/users/szaghi/received_events","type":"User","site_admin":false},{"login":"milancurcic","id":4133310,"avatar_url":"https://avatars.githubusercontent.com/u/4133310?v=3","gravatar_id":"","url":"https://api.github.com/users/milancurcic","html_url":"https://github.com/milancurcic","followers_url":"https://api.github.com/users/milancurcic/followers","following_url":"https://api.github.com/users/milancurcic/following{/other_user}","gists_url":"https://api.github.com/users/milancurcic/gists{/gist_id}","starred_url":"https://api.github.com/users/milancurcic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/milancurcic/subscriptions","organizations_url":"https://api.github.com/users/milancurcic/orgs","repos_url":"https://api.github.com/users/milancurcic/repos","events_url":"https://api.github.com/users/milancurcic/events{/privacy}","received_events_url":"https://api.github.com/users/milancurcic/received_events","type":"User","site_admin":false},{"login":"rnelias","id":4390078,"avatar_url":"https://avatars.githubusercontent.com/u/4390078?v=3","gravatar_id":"","url":"https://api.github.com/users/rnelias","html_url":"https://github.com/rnelias","followers_url":"https://api.github.com/users/rnelias/followers","following_url":"https://api.github.com/users/rnelias/following{/other_user}","gists_url":"https://api.github.com/users/rnelias/gists{/gist_id}","starred_url":"https://api.github.com/users/rnelias/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rnelias/subscriptions","organizations_url":"https://api.github.com/users/rnelias/orgs","repos_url":"https://api.github.com/users/rnelias/repos","events_url":"https://api.github.com/users/rnelias/events{/privacy}","received_events_url":"https://api.github.com/users/rnelias/received_events","type":"User","site_admin":false},{"login":"francescosalvadore","id":4660289,"avatar_url":"https://avatars.githubusercontent.com/u/4660289?v=3","gravatar_id":"","url":"https://api.github.com/users/francescosalvadore","html_url":"https://github.com/francescosalvadore","followers_url":"https://api.github.com/users/francescosalvadore/followers","following_url":"https://api.github.com/users/francescosalvadore/following{/other_user}","gists_url":"https://api.github.com/users/francescosalvadore/gists{/gist_id}","starred_url":"https://api.github.com/users/francescosalvadore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/francescosalvadore/subscriptions","organizations_url":"https://api.github.com/users/francescosalvadore/orgs","repos_url":"https://api.github.com/users/francescosalvadore/repos","events_url":"https://api.github.com/users/francescosalvadore/events{/privacy}","received_events_url":"https://api.github.com/users/francescosalvadore/received_events","type":"User","site_admin":false},{"login":"jacobwilliams","id":6483379,"avatar_url":"https://avatars.githubusercontent.com/u/6483379?v=3","gravatar_id":"","url":"https://api.github.com/users/jacobwilliams","html_url":"https://github.com/jacobwilliams","followers_url":"https://api.github.com/users/jacobwilliams/followers","following_url":"https://api.github.com/users/jacobwilliams/following{/other_user}","gists_url":"https://api.github.com/users/jacobwilliams/gists{/gist_id}","starred_url":"https://api.github.com/users/jacobwilliams/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacobwilliams/subscriptions","organizations_url":"https://api.github.com/users/jacobwilliams/orgs","repos_url":"https://api.github.com/users/jacobwilliams/repos","events_url":"https://api.github.com/users/jacobwilliams/events{/privacy}","received_events_url":"https://api.github.com/users/jacobwilliams/received_events","type":"User","site_admin":false},{"login":"nncarlson","id":7231327,"avatar_url":"https://avatars.githubusercontent.com/u/7231327?v=3","gravatar_id":"","url":"https://api.github.com/users/nncarlson","html_url":"https://github.com/nncarlson","followers_url":"https://api.github.com/users/nncarlson/followers","following_url":"https://api.github.com/users/nncarlson/following{/other_user}","gists_url":"https://api.github.com/users/nncarlson/gists{/gist_id}","starred_url":"https://api.github.com/users/nncarlson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nncarlson/subscriptions","organizations_url":"https://api.github.com/users/nncarlson/orgs","repos_url":"https://api.github.com/users/nncarlson/repos","events_url":"https://api.github.com/users/nncarlson/events{/privacy}","received_events_url":"https://api.github.com/users/nncarlson/received_events","type":"User","site_admin":false}],"milestone":null,"comments":50,"created_at":"2016-10-21T08:51:19Z","updated_at":"2016-10-26T08:27:41Z","closed_at":null,"body":"Dear all, I am very sorry for my long silence...\r\n\r\n`OT`\r\n> I am preparing four (yes 4) applications to public open calls for a stable research position (2 written proofs and 1 oral defense for each call that are on different field... a lot to study) that are very important (give me a *good luck* even if I am not competitive at all, but *miracles* could happen...), then there were the official work for the payed salary, the family... forgive me, but you are always in mind too\r\n\r\n`/OT`\r\n\r\nCurrently, I have hinged into a nice debate on [google group about Fortran](https://groups.google.com/forum/#!topic/comp.lang.fortran/6uROcAIvPcQ%5B1-25%5D) into which the discussion soon diverged (maybe due to my comments, my apologizes) from the original OP request and it focused on the `goto` usage (in particular computed goto, but for brevity I use simply goto hereafter). Perhaps some of you have already read this google discussion (even I do not see your comments there), but I try to summarize some points here. Aside some *harsh* comments I obtained, the discussion was interesting for me. All originates from a sharp (for me) sentence of a very experienced and distinguished Fortraner, his name is  Terence (pay careful to put only one 'r' :smile:), that stated:\r\n\r\n> Mind you, I still prefer a computed GOTO over CASE anyway, since this is usually compiled as a faster selection.\r\n\r\nTo me sentence is too much *sharp* because it entails a vague *general significance* that could let newbies who are learning Fortran (like me) to prefer `goto` because it is supposed to be faster than other Fortran constructs. In particular, the case debated was about branching-flow approaches: the OP has a (possible) long list of cases like the following:\r\n\r\n```fortran\r\nselect case(keyword)\r\ncase(key1)\r\n  call worker1(keyword)\r\ncase(key2)\r\n  call worker2(keyword)\r\n...\r\ncase(keyN)\r\n  call workerN(keyword)\r\nendselect\r\n```  \r\n\r\nThe OP was wondering if there was a more concise/easy way to handle the branching in particular concerning the situation where new keywords were added (he struggled with the stuff to add new cases). \r\n\r\nAside the peculiar OP question, after the Terence's sentence my attention was captured by the supposed `goto` better performance. \r\n\r\n**I did not thrust Terence advice**, thus I created some benchmarks [here](https://github.com/szaghi/DEFY). \r\n\r\nIn my opinion the following considerations hold:\r\n\r\n1. `goto` is now considered obsolescent for good reasons, among which I like to remember:\r\n  + `goto` branching is not readable: `goto` can jump everywhere, no ensure is provided on the sequential bias, using `goto` you must rely on the discipline of the developer;\r\n  + `goto` needs labels, a lot of labels in the OP scenario, that hinges again with readability and maintainability;\r\n  + `goto`-based branching-flow is not *expressive*; citing the words of great Ian Harvey: `goto (1,2,3,4,5,6,7,8,9,10), keyword` tells me that execution is going somewhere, based on the value of `keyword`, but tells me nothing about why execution is branching, or the nature of the branch;\r\n  + `goto` is error-prone more than `if elseif` or `select case`;\r\n  + `goto` is spaghetti-code-prone;\r\n2. `goto` supposed higher performance is a *myth* for the *architectures* (meaning hardware+compiler) at our disposal nowadays:\r\n  + my tests (that are not to be considered quantitative or accurate, but only *indicative*) show that `goto`-based branching has very similar speed compared to equivalent `if elseif` or `select case` branching-flow approaches; as a matter of fact, all the 3 branching mechanisms are often compiled into the same low level machine-code, e.g. jump-table or constants-array;\r\n  + `goto` prevents further optimization like the exploitation of multi-threading, thus we actually say *good bye* to the supposed better performance.\r\n\r\nConsidering also that `if elseif` and `select case` are more general than `goto` (that works with only integer) allowing for not only integers comparison.\r\n\r\nIn the google thread I was almost alone (FortranFan is probably the only other reader thinking like me): essentially the common culture considers `goto` still the **fastest in the west**. Indeed, some of the readers supporting this concept are focused on the old-good-days where `goto` was really faster because `select case` was just born (or even the only available options, e.g. pre F77/F90 days), but I do not consider much more relevant those applications: we are leaving in 2016, hopefully pre F77 and F77/F90 should be considered *old*, at least F95+ should be the *mainstream* standard, although it has more 20 years now... Obviously, I am referring to the development of **new** codes (as in OP request), I am not saying to convert all old codes written by means of `goto` that are still in use.\r\n\r\nIn my opinion `goto` is **bad practice** and should be discouraged. However, I am often wrong, thus your opinions are much more than welcome. I'll use your opinions for another little step of this guidelines.\r\n\r\nMy best regards.\r\n\r\n# Guideline Proposal (WIP, feel free to directly amend my proposal)\r\n\r\n## <a name=\"goto\"></a> Structured is better than *unStRUcturED*, avoid as much as possible `goto`\r\n\r\nIn some circumstances, the *algorithm-flow* can be simplified by means of *jump statements*, e.g. `return`, `exit`, `cycle` and `goto`. While the former set generates *structured flow* where the algorithm is allowed to flow in **only in one direction**, the `goto` statement allows to jump **elsewhere** and generates often unstructured flows that are difficult to read and to maintain. As a matter of fact, `goto` could be very error-prone often leading to the so called *spaghetti-code*.  \r\n \r\n> + It is recommended to avoid, as much as possible, `goto` statement:\r\n>    + in almost all cases `goto` can be replaced by means of structured-safe constructs **without** any performance penalty while **greatly improving** readability and maintainability;\r\n> + but exceptions should be allowed for very *corner* cases that, anyhow, should be in *the hands* of **experts**.\r\n\r\n\r\n> put here examples and references, **to be completed**"},"comment":{"url":"https://api.github.com/repos/Fortran-FOSS-Programmers/Best_Practices/issues/comments/256282048","html_url":"https://github.com/Fortran-FOSS-Programmers/Best_Practices/issues/15#issuecomment-256282048","issue_url":"https://api.github.com/repos/Fortran-FOSS-Programmers/Best_Practices/issues/15","id":256282048,"user":{"login":"szaghi","id":1661942,"avatar_url":"https://avatars.githubusercontent.com/u/1661942?v=3","gravatar_id":"","url":"https://api.github.com/users/szaghi","html_url":"https://github.com/szaghi","followers_url":"https://api.github.com/users/szaghi/followers","following_url":"https://api.github.com/users/szaghi/following{/other_user}","gists_url":"https://api.github.com/users/szaghi/gists{/gist_id}","starred_url":"https://api.github.com/users/szaghi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/szaghi/subscriptions","organizations_url":"https://api.github.com/users/szaghi/orgs","repos_url":"https://api.github.com/users/szaghi/repos","events_url":"https://api.github.com/users/szaghi/events{/privacy}","received_events_url":"https://api.github.com/users/szaghi/received_events","type":"User","site_admin":false},"created_at":"2016-10-26T08:27:40Z","updated_at":"2016-10-26T08:27:40Z","body":"@jeffhammond \r\n\r\nDear Jeff, indeed I am very sorry, but I follow you until a certain point (mainly due to my bad English skill). I was not aware of the (very very) interesting paper of Knunth, thank you very much. \r\n\r\nAnyhow, I am **not** sure if you want to *re-focus* my draft-proposal on a more appropriate *issue* or you like it as is. \r\n\r\nPreliminaries: I am not a Software Engineer nor a C programmer, I *use* Fortran as *carpenter* use a *planer*... I am focused on the Navier-Stokes eq. solution rather on how better exploit my hardware. (Indeed, I think there are much more *oompa loompa* Fortraners like me than really *Willy Wonka* as you, thus as Fortran guidelines are concerned, I think my view is quite *common*.) That said just for emphasize that my main concern is almost never *premature optimization*. Surely, I like to be as efficient as possible: when I read Damian's book I thought \"Wow... is it really possible with Fortran?\" and then \"probably yes, but it should dramatically slow\" and *then-then* I tested with my hands that the overhead is there, but much *less* with respect the great improvement in flexibility/conciseness/clearness... At the end, I think that for newbies Fortraners (the possible target of these guidelines), is much more important to learn some-sane *discipline* on how write clear code, rather how to be the fastest as possible: I think that the number of Fortraners developing (part of) Linux Kernel or MPICH is low (probably all of such Fortraners are here, I am thinking to Vladimir and some others like you :-)). I totally agree with you: `goto` is not (always) necessary (I never stop to search for a case where it is really necessary), but for very low-level applications it could be very useful. I think that this view is shared with you, but I like to be clear because my bad English often drives my into wrong understandings when *informal dialogues* are concerned.\r\n\r\nNow, the part that I am **not** sure to understand into your last comment. Was I wrong focusing on the *structured programming against the unstructured one*? I'll study the Knuth's paper soon, but for now I cannot say if my proposal is in agreement or not with what Knuth stated. In my (probably wrong) vision, `goto` is not the evil *per se*, rather because it likely drives Fortraners to develop **unstructured** code that *flows chaotically as the flight of a butterfly*.\r\n\r\nI'll add all your references and examples soon into the proposal.\r\n\r\nCheers."}}
{"actor":{"display_login":"szaghi"}}