Goto bad Spooktober tale:  Counting goto in the Linux kernel - Page 1
Forum section: electronics / general

author: RoGeorge
author_rank: Super Contributor
timestamp: October 29, 2023, 07:31:47 am
content: Current version of the Linux kernel athttps://www.kernel.org/is 6.5.9, download and unpack:Code:wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.5.9.tar.xztar -xvf linux-6.5.9.tar.xzCount all linesCode:find ./linux-6.5.9 -name '*.c' | xargs cat | wc -l23174856Count the goto linesCode:find ./linux-6.5.9 -name '*.c' | xargs cat | grep -c 'goto '193266Save them in a file for further inspectionCode:find ./linux-6.5.9 -name '*.c' | xargs cat | grep 'goto ' > goto.txtMost of them are for treating errorsCounting again, without goto err/out/failCode:find ./linux-6.5.9 -name '*.c' | xargs cat | grep 'goto ' | egrep -vc 'goto err|goto out|goto fail'73786

author: Siwastaja
author_rank: Super Contributor
timestamp: October 29, 2023, 07:37:46 am
content: goto is a normal part of C and trying to avoid using it for political reasons leads to less readable spaghetti code. This is well known but some beginners still misunderstand some old tongue-in-cheek articles taken out of context.Now for C++, amount of goto will be less as there are other ways for error handling (arguably better, arguably worse), but goto has its uses even in C++.

author: DiTBho
author_rank: Super Contributor
timestamp: October 29, 2023, 09:26:50 am
content: What's the point here?The linux kernel is not a good reference neither about programming style, nor about how a kernel should be written.Linux is a kernel developped in the 90s that practically "works", and it "works" because there are a lot of people who follow it and are willing to fix it, just look at how many interactions there are every time you go into regression.Linux v6 stopped correctly booting on PPC-G4 and G5 PowerMacs, and dozens of messages have been raining into the mailing lists for 5 months every single day... and this is precisely the correlation between writing software with lots of gotos and that approach, or writing software with a completely different approach: the first difference you notice is the number of iterations necessary to solve a bug.Linux is certainly not written well from this point of view as it barely passes the level DO178B level E, which I remind you must be read in terms of "software life cycle" and "resources necessary for development, maintenance and bug fixing". It does not practically matter for the final user, especially for mainstream platforms (x86, amd64, arm, arm64) due to the mechanism with which it is supported by large communities, but things change dramatically when you are alone developing something or solving a problem.

author: DiTBho
author_rank: Super Contributor
timestamp: October 29, 2023, 09:45:17 am
content: Quote from: Siwastaja on October 29, 2023, 07:37:46 amI've never read anything so funny considering that it shows that it's quicker to write just any bullshit (political reasons ? LOL) than to waste time explaining things well: why waste time on a forum when the typical hourly Windirver consulting rate for DO178B/Level A is 100/hr at least? The fewer people know how to do it, the more opportunities you have to bring home wheelbarrows of gold.

author: magic
author_rank: Super Contributor
timestamp: October 29, 2023, 09:55:26 am
content: IMO by far the biggest problem with Linux code is very little documentation (which also suggests the distressing possibility that there may be very little design to it as well).It's like those assholes have never heard of comments.Of course I can read the code and see what it does, but the problem is that usually I'm reading code because it's doing something it shouldn't be doing, and good luck guessing what's the intended operation of every little part and which of those parts is wrong.I couldn't care less about goto.

author: DiTBho
author_rank: Super Contributor
timestamp: October 29, 2023, 10:06:56 am
content: Quote from: magic on October 29, 2023, 09:55:26 amYup, I often see people who don't understand why there are no comments in the code and have to ask and discuss.It's another aspect of this approach to software.

author: Karel
author_rank: Super Contributor
timestamp: October 29, 2023, 10:08:20 am
content: Based on static analysis defect density, in the 2013 report, we found that open source code outpaced commercial code in quality.This trend continues in 2014;Defect density (defects per 1,000 lines of code) of open source code and commercial code has continued to improve since 2013:When comparing overall defect density numbers between 2013 and 2014, the defect density of both open source code and commercialcode has continued to improve. Open source code defect density improved from 0.66 in 2013 to 0.61 in 2014,while commercial code defect density improved from 0.77 to 0.76.Linux continues to be a benchmark for open source quality.By leveraging the Scan service,Linux has reduced the average time to fix a newly detected defect from 122 days to just 6 days.Since the original Coverity Scan Report in 2008, scanned versions of Linux have consistently achieveda defect density of less than 1.0. In 2013, Coverity scanned more than 8.5 million lines of Linux codeand found a defect density of .61https://news.synopsys.com/2014-04-15-Coverity-Scan-Report-Finds-Open-Source-Software-Quality-Outpaces-Proprietary-Code-for-the-First-Timehttps://news.synopsys.com/2015-07-29-Coverity-Scan-Open-Source-Report-Shows-Commercial-Code-Is-More-Compliant-to-Security-Standards-than-Open-Source-Code

author: DiTBho
author_rank: Super Contributor
timestamp: October 29, 2023, 10:14:45 am
content: I mysefl seen on IRC a hacker create from scratch all the support for the IP30 platform on his own around the 2.6.17 kernel, then he lost the interest and disappeared from the scene and it took more than 15 years!!! to understand what the hell he had done because his code was not only very cryptic and without any comment, but it was also very low level.(not only gotos, also asm inlines, strange pointer arithmetic, and really bizarre things, all undocumented)It took us all this time because the IP30 is a very complex platform, there was/is little interest in the platform, and let's get back to the topic... Linux works when it is followed by many people.

author: magic
author_rank: Super Contributor
timestamp: October 29, 2023, 10:15:36 am
content: Article summary:Quote

author: DiTBho
author_rank: Super Contributor
timestamp: October 29, 2023, 10:27:08 am
content: Quote from: Karel on October 29, 2023, 10:08:20 amWhat I see, and what this is probably about, is the new approach of automatic 'bots operating in parallel on BiSect to find the one which commit introduced the defect, every time we see a regression.git| git| git| git| git| git| git| git| git| git| git| ... gitcompile| compile| compile| compile| compile| compile| compile| compile| compile| compile| compile| ... compiletest| test| test| test| test| test| test| test| test| test| test| ... test|report| report| report| report| report| report| report| report| report| report| report| ... report|(a cluster of nodes, doing this, in parallel, each on a commit between point A and point B of the Git history, moving from A to B)Yes, this helps. But this is not the point, also because the number of regressions is increasing.Or do you mean that this "instrumental" approach is better?

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: October 29, 2023, 10:36:37 am
content: I have no knowledge of Linux' internals & how goto is used, but..The problem with the philosophical argument that "Goto == bad" is that the real world has error conditions. Dealing with scenarios where errors can occur at any stage in a long and convoluted process while trying to be neat and structured can be a nightmare, and make code far less understandable.However multiple "If (error) go direcly to here because I don't care what happens after that but I do need to deal with it sanely" is reliable and understandable.

author: Siwastaja
author_rank: Super Contributor
timestamp: October 29, 2023, 11:02:22 am
content: Quote from: mikeselectricstuff on October 29, 2023, 10:36:37 amA quick example for those who are not familiar with the pattern:Code:int do_thing(){turn_relay_on();if(!good_to_go){turn_relay_off();return FAILURE_1;}if(asdf != 123){turn_relay_off();return FAILURE_2;}do_rest_of_stuff();turn_relay_off();return SUCCESS;}vs.Code:int do_thing(){int rc = FAILURE_TO_DESCRIBE_FAILURE;turn_relay_on();if(!good_to_go){rc = FAILURE_1;goto DONE;}if(asdf != 123){rc = FAILURE_2;goto DONE;}do_rest_of_stuff();rc = SUCCESS;DONE:turn_relay_off();return rc;}In latter case, one cannot accidentally forget to turn relay off when they add another error check. For this simple case, manual bookkeeping of restoring state is possible, but once you have to undo more than one thing in the opposite order, and how far you initialized (and thus, where to begin uninitializing) depends on error condition, gotos are very handy:Code:init1();if(error) goto DEINIT1;init2();if(error) goto DEINIT2;init3();if(error) goto DEINIT3;DEINIT3: deinit3();DEINIT2: deinit2();DEINIT1: deinit1();In C++, one is supposed to use the exception system for the same result. Building something similar on top of C would likely get into territory of overengineering. Goto is simple and clear, and labels are documentative.

author: DiTBho
author_rank: Super Contributor
timestamp: October 29, 2023, 11:04:27 am
content: Quote from: mikeselectricstuff on October 29, 2023, 10:36:37 amYes, this is the only acceptable use with DO178B level from A to C, but if and only if you don't abuse and if you segregate the modules that use goto into in directory or with a prefix/suffix/whatever that at least makes it clear that it is necessary to analyze how any allocated resources are managed in the event of a jump to the point of failure.All deallocated? partially deallocated can hide resource leackaging on goto error.All ignored as the firmware is going to invoke panic() or reboot()?The VxWorks kernel is a good example here, and you can use goto in this case even for your kernel drivers, if your gotos are properly documented for the attention of both the QA team and the testing squads.Basically: does the module contain goto? If yes, it must also contain the proper documentation, point by point, as it will be properly inspected and tested. Abuses and neglects will be... punished with "code rejected".Windriver's approach

author: Psi
author_rank: Super Contributor
timestamp: October 29, 2023, 11:10:06 am
content: This reminds me of that language, what was it, the one that does not have a 'goto' command, and instead has the reverse. a 'come from' command.That's right, it was C-INTERCAL

author: SiliconWizard
author_rank: Super Contributor
timestamp: October 30, 2023, 01:23:49 am
content: Of course people will keep blabbering about how goto is good while it has been flagged as very bad for decades. Mostly people not actually understanding what is bad about it and why we still use it in C, mostly for error handling, for lack of better constructs. Any other use of it in C *is* generally a very bad idea.(Quick note: sorry to say that your "egrep -vc 'goto err|goto out|goto fail'" is not really evidence that goto is ever used for anything else than error handling in the Linux kernel code.)Note that behind this common use case, error handling, the idea is to factor sections of code instead of making them redundant, which is arguably much worse.There is a well known construct that happens to factor code just fine, and it's called a function. Yes, in many cases you can implement error handling more cleanly writing error handling functions rather than jumping up and down inside a function. With any modern compiler (I mean, younger than 25 years or so), it will even have a very minimal performance impact, if any. Except possibly in very tight loops, for which hand-optimizing further is warranted. You may argue that this approach is not really workable if the error handling part of a given function can have other paths than directly return from said function once the clean-up has been done. In which case, the idea of using goto with not just one code path (error handling/clean-up/return from function) but several is preciselyt what quickly becomes atrocious. The famous spaghetting syndrome.Now of course, if you resort to a function, that means you'll have to pass some context around, which is not fun. We are lazy.So with that said, do I still use goto in C on a regular basis for error handling? Yeah. Sure. But I know why I do. I don't do it just because it looks cool to be the programming kiddo that knows better, or to make YT videos with tens/hundreds of thousands of views. And, pointing out that there are other ways to skin the cat, often almost as efficient and much cleaner.Also, I agree about the fact Linux is not a particularly good example of code style and code quality. But most of it at least looks like C written by people who have a good command of it, so that's already something.It is, however and IMO, an example of particularly good project management, which is the number 1 reason, again IMO, for its success and longevity.All in all, that's some kind of false debate that just keeps on going, as again it's used for lack of better constructs in C and similar languages. Not that I take it as an example, but since it's been pretty hyped in the past few years, has anyone heard of using "goto" in Rust? Why keep venting about it?

author: floobydust
author_rank: Super Contributor
timestamp: October 30, 2023, 03:55:10 am
content: In a computing science course assignment, used GOTO to bust out of a few nested levels of loops. I think was a Dykstra's shortest path algo.Asked the prof and he said "no prob" GOTO is sometimes necessary and required, so it exists. So does BRA in assembler.Like anything it can get abused but I haven't seen that since the days of BASIC, when people did not learn structured programming and could drift towards spaghetti using it. Anybody quickly learns how to code better after getting boxed in, creating a dog's breakfast.Instead of demonizing necessary programming constructs, what about that old 1970 programming language that still is shit for buffer overruns and array indexes into lala land...

author: Siwastaja
author_rank: Super Contributor
timestamp: October 30, 2023, 06:20:03 am
content: Quote from: SiliconWizard on October 30, 2023, 01:23:49 amSo does this imply you use other constructs, for exampleforloop, because it looks cool? If not, how does it make any sense to mention thatgotois used for... a specific technical purpose, and possibly harmful for others? I mean, isn't that true for nearly every construct in nearly any language?Same can be asked from DiTBho:Quote from: DiTBho on October 29, 2023, 11:04:27 amWat? So if you do not use goto, but instead, for example, create a messed up if-else spaghetti, then there is no need for documentation, no inspections and no tests? Is this what you mean? If yes, I'm horrified. If no, and if documentation, tests and rationale for choices are needed in all cases, what do you mean by the above, it makes no sense to me."goto considered harmful" mindset seems to stick hard in some of us, to the point of requiring weird mental acrobatics and "ohIknow how to use it, BUT..." type rationalizations. I find it hilarious. It's just one feature of the language amongst others, and specifically C is full of much more dangerous features than that. I mean, integer promotion related bugs is actually a "thing". No one knows a concept of "goto bugs".

author: magic
author_rank: Super Contributor
timestamp: October 30, 2023, 07:17:56 am
content: Quote from: Siwastaja on October 30, 2023, 06:20:03 amThis is how government works, so I would expect some of this attitude to leak into government regulated industries too

author: Siwastaja
author_rank: Super Contributor
timestamp: October 30, 2023, 07:52:20 am
content: Quote from: magic on October 30, 2023, 07:17:56 amIt never stops amazing me how supposedly safety-critical fields (like aviation) are governed by practices like "using goto is forbidden, now your code passes as it does not use goto" (for example, about half of MISRA actually reduces code quality and increases risk of bugs, while another half might have a slight positive effect which hopefully compensates, for net zero end result). I'm so glad I don't have to work in such setting where using safety-increasing common sense (and known good practices from "standard commercial" software development) on the other handhasto be used so that I could sleep well, but on the other hand is made very difficult to use due to the red tape requiring more dangerous practices, so it's a fine balancing act between the regulations and actual safety.

author: DiTBho
author_rank: Super Contributor
timestamp: October 30, 2023, 11:39:40 am
content: Quote from: floobydust on October 30, 2023, 03:55:10 amoh sht

author: DiTBho
author_rank: Super Contributor
timestamp: October 30, 2023, 11:43:28 am
content: Quote from: Siwastaja on October 30, 2023, 07:52:20 amyes, why don't you go and play with arduino? Do yourself a favor

author: DiTBho
author_rank: Super Contributor
timestamp: October 30, 2023, 12:14:20 pm
content: Quote from: Siwastaja on October 30, 2023, 06:20:03 amQuote from: Siwastaja on October 30, 2023, 06:20:03 amcognitive problems?Nobody said that! It's always under DO178B, therefore normal procedures are applied; I only underlined that is Windriver's approach to add an extra layer as the modules containing "goto"must be reported for further inspections, and theremust be documented, otherwise the code won't pass.edit: to be more clear. necessary condition, not sufficient!This does not mean that there will not be the normal testreport vectors, on the contrary, it means that the testing team will have the opportunity to better understand how to test the various error cases, a typical situation in which gotos are used.It also means that this type of test report cannot be assisted by A.I., as the comments are written in human language.So, this approach also helps plan activities.Note, that's very different from trying to ridicule what I wrote, as I said "goto" is accepted, and explained when it's accepted, and how it is managed.Quote from: Siwastaja on October 30, 2023, 06:20:03 amPerplexed. Like giving pearls to pigs.

author: Siwastaja
author_rank: Super Contributor
timestamp: October 30, 2023, 12:48:50 pm
content: Quote from: DiTBho on October 30, 2023, 12:14:20 pmSounds like typical regulatory BS, the usual mischief that if you do X then you get extra chores so that practically you won't be doing X, even when doing X would be the best option, and then you do bullshit like add weird and complex temporary variables and their conditions in the loop termination definition just to avoid goto (and maybebreak, too) and the related extra chores.Maybe I'm too simple-minded, but I think best would be that all safety-critical code must go through the same level of scrutiny with the goal of proving the correctness as far as humanly possible. I fail to see what issospecial in goto that it requires a complete separate extraprocess.QuoteQuite sadly, ChatGPT is well capable of generating human language reasoning which sounds very convincing to managers. Probably the only way is to know your staff and only hire responsible, competent people who are proud of what they are doing. Having a system where usage of "goto" triggers another layer of red tape drives the culture to the opposite direction.Quote from: DiTBho on October 30, 2023, 11:43:28 am"go play with Arduino" - embedded engineers' way of saying "fuck you". I hear youQuite typical - I'm discussing my concerns regarding safety regulations and their effectiveness, and what I get is an ad hominem attack. Fair enough, but don't forget - reality is on my side - arrogance and safety DON'T PLAY ALONG, this is the key finding during aircraft accident investigations in 1970's and 1980's that triggered design ofcockpit resource management. We need similar thought patterns (allowing questions and disagreements, reasoning instead of name-calling) in safety critical engineering*, instead of calling those who disagree to fuck off.*) which I have done, just on a field that was so new that it didn't have regulatory standardization at the time (and still probably does not) so went under much more generic set of regulations, prompting forown thinking.

author: DiTBho
author_rank: Super Contributor
timestamp: October 30, 2023, 01:35:09 pm
content: Quote from: Siwastaja on October 30, 2023, 12:48:50 pmIf we have to be assholes, then what are your skills? last time you said that you deal with "home automation", yet up hereyou deliberately allowed yourself to distort what I wrote in order to insult, once again, an entire category of workers.Quote from: Siwastaja on October 30, 2023, 12:48:50 pmOh SHT, againDo you even have the qualifications to shit in our shoes? ChatGPT is well capable ... I do not think so, and I don't even care, I'd sooner ignore you than waste any more time.Quote from: Siwastaja on October 30, 2023, 12:48:50 pmOk, Quite typical, enjoy my ignore list, this time is permanent.

author: Siwastaja
author_rank: Super Contributor
timestamp: October 30, 2023, 01:51:35 pm
content: Interesting how emotional some people can get over a simple language featureIn any case, I don't recall insulting any workers, and despite re-reading my posts a few times, can't find anything that even remotely resembles that. Maybe some mental mixup between threads or something?edit: oh shit, he meant I insultedthe regulators. Being an engineering forum where we are usually not the ones to write the regulations, but to obey them, that perspective didn't pop to my mind, but maybe I was a bit harsh for those who make the rules. After all, rules are like words of God; they can't be disagreed with.

author: magic
author_rank: Super Contributor
timestamp: October 30, 2023, 03:37:41 pm
content: This guy always sounds like somebody bringing home wheelbarrows of gold thanks to his advanced knowledge of safety critical software development on obsolete hardwareVery happy with his job, no doubt.

author: Siwastaja
author_rank: Super Contributor
timestamp: October 30, 2023, 04:03:36 pm
content: I have absolutely nothing against him, although many of his ideas I find pretty weird, but weird in agoodway; I don't prefer to sit in an echo chamber. I also disagree with some ideas such as hiding pointer-ness behind a type and naming convention instead of using language built-in syntax to convey that information, but ultimately such things are also matter of taste, and if he finds hiding pointerness and not using gotos help him writing safer code, what can I say? It doesn't work for me but probably works for others. I don't understand the personal attack on projects. Me working on building automation systems doesn't mean I'm not allowed to evendiscusssafety critical software any more than himself having worked on embroidery machine control project.

author: Nominal Animal
author_rank: Super Contributor
timestamp: October 30, 2023, 05:48:31 pm
content: Pointing out that the Linux kernel usesgotois like pointing at someone using a leg prosthesis, and shoutingHa ha! Look at that stupid peg leg!Me, I don't trust standards and regulations, not even ISO or POSIX C or MISRA-C or DO-178B. I highly appreciate the principles and the reasoning behind them, and try to abide by those –– especially security, robustness, reliability, and maintainability ––depending on my needs, but practice trumps theory.Always.Arguments like this one, especially when they get personal, make me go.Some of you argue based on DO-178B, the others do freestanding/hosted development under review-based quality control. They're not the same environment!Define your own context, basis of argument and environment, before getting caught up in the argument. Yes, it leads to over-long posts like mine, but at least then you have a chance of arguing about the same thing, instead of a similar thing in wildly different contexts. Apples and pineapples.One related case that I recently thought about is the fact that in ISO C, binary right shift of negative values is implementation defined. This means that a particular C compiler could choose to "optimize" code by having any right shift of a negative value do nothing. If anyone complains, they can simply point to the standard and point out – correctly – that they're fully compliant already.Me,Iam only interested in compilers that generate an arithmetic right shift on negative two's complement integers, i.e.(-29) >> 1 == -15. Generating anything else is just silly and anti-useful on the architectures I use, from 8-bit AVRs to 64-bit AMD64/x86-64 and ARM64.Thus, my code is not strictly portable in the ISO C standard sense. Yet, in practice, my code tends to be quite portable, with just a set of notes and restrictions one can test.This means that if anyone asks me if>>on anintN_torint_fastN_t-type expression is safe in C, my answer depends on the context (but I often assume one, rightly or wrongly, based on the names/labels the asker used). Or I explain the standard stance and my attitude towards it.Similarly, I need to see a particular case ofgotouse (including the project context), to even have an opinion about it.To have an opinion aboutgotouse in the Linux kernel, without showing superior C constructs that yield the same or better machine code on all architectures, is just shouting "Ha-ha!". Not useful, not informative; just juvenile.

author: DiTBho
author_rank: Super Contributor
timestamp: October 30, 2023, 06:39:00 pm
content: Quote from: magic on October 30, 2023, 03:37:41 pmThis is another one of those things that annoys me, but note that almost none of my colleagues ever talk about what they do for work, each of us has spent ~50K euro and 10 years on training, in open source you don't find any of this, and yet, instead of appreciating, you do nothing but making fun of my category, when the concept that "we would be" trained "monkeys" who "follow orders" is even conveyed.Sorry, I really don't think I will ever say anything else in this forum.

author: ejeffrey
author_rank: Super Contributor
timestamp: October 30, 2023, 07:05:17 pm
content: Basically goto is like the C preprocessor. It's a low level construct that can be very powerful, but also can cause a lot of problems.I don't think it's quite fair to say "they can be abused just like any other language construct" I think fundamentally both of them should be considered as dangerous to use and best to be avoided, but there are a lot of particular use cases that cover shortcomings of the language that are better implemented with those features that without. If I were to design a C/C++ like language, I would be happy to include both, but would strive to make sure that the core language covered as many known use cases as possible so that nobody wanted or needed to use them.Error handling is the most common case in C where goto is often really the best solution. But C++ has RAII which generally covers most if not all of those cases. As a bonus, it can do so more efficiently -- goto error approaches often require tests for each possible resource to be cleaned up since you don't know where you jumped in from, while RAII automatically invokes exactly the required cleanup handlers. Usually a trivial difference, but might make sense in some situations.Exiting a nested for loop is another common use of goto. It's a bit more controversial since there is an often superior alternative which is to factor the loop into a function and use return, but it's still a core feature that C doesn't have: targeted break/continue.If C had clean support for registering function level cleanup expressions and targeted break/continue, probably 99% of uses of goto would go away. And that doesn't mean the other 1% are bad uses, but there would be a lot fewer to consider on a 1-off basis.The preprocessor is the same way. Very old compilers didn't support inlining well, so macros were used for optimization, even though it had problems with parse confusion and side effects. Now compilers are good at inlining and that use is now pretty much obsolete. C doesn't support polymorphic functions, so macros can be (carefully) used for that purpose -- although C11 introduced generic functions that are better to use when they work. C doesn't allow even constant variables to be used for initialization, so preprocessor macros have to be used for that. The list goes on. Even "standard use case" is something that should be considered for making a dedicated language feature.So people categorically labeling these structures as bad without caveat ignores the fact that they are being used as real solutions for shortcomings of the language. Suggestions they be replaced with more complex code to achieve some abstract purity are not helpful.And of course, the cure isn't always better than the disease. C++ templates let you do a lot of powerful generic programming that would otherwise be done by the preprocessor, and do so in a type safe manner, but abuse of the template system can be as bad as the preprocessor macros it replaces.

author: DiTBho
author_rank: Super Contributor
timestamp: October 30, 2023, 07:41:57 pm
content: Quote from: Nominal Animal on October 30, 2023, 05:48:31 pmThat's precisely why I mentioned the Windriver's approach!It's not that I was describing something on a theoretical level, I made precisely the practical discussion, because someone cited the linux kernel to argue that "gotos are fine", and I pointed out that it would be better to look at WxWorks, simply because if there is no documentation on linux (and frankly I often struggle to understand what exactly the code does in case of error propagation), everything is documented on WxWorks!I then mentioned DO178B to underline that the Windriver's approach is a kind of simplified subset, which is good even when you are part of a small team and you have to deal with a lot of work(1) to do and with many things to verify. Thanks to Windriver, you have a simplified rule-set where "goto" are allowed for error-handling and have documentation (mandatory), which help to understand how to manage the test-reports!Again, it's not something on a personal level, otherwise I would have told you that in my-c language *any goto* is always forbidden, and here I would have started to mention how I have already solved the whole "goto thing" on both theoretical and experimental levels.(1) which is mandatorily required by the life cycle watertight compartmentalization procedures described by these regulations.

author: Nominal Animal
author_rank: Super Contributor
timestamp: October 30, 2023, 09:33:39 pm
content: Quote from: DiTBho on October 30, 2023, 07:41:57 pmNo, actually you didn't. Reread your first two posts,reply #2andreply #3. You'll understand how the discussion derailed. Reply #3 was, intended or not, just yelling "Ha-ha! Look at that peg leg!"If you had instead constructed a reply along the lines youintended, sayQuoteand then maybe add a bit about your experiences/opinion working on both, and what this means when one gets paid to work under MISRA-C or DO-178B rules, the thread would have continued very, very differently.Iknowthat's very much along the lines of what you intended (we've discussed similar details and Linux kernel wonkiness elsewhere); it just came out wrong. All this mess is just a communications issue, worth fixing, but not something to get irritated over.I like you and Siwastaja both; I sometimes agree, sometimes disagree with both of you. I like to argue with you both (and SiliconWizard and RoGeorge and others; I like you too!), as we keep it tothingsand don't usually let it go personal. When it does, it needs to be fixed, because otherwise many useful and interesting future arguments will be lost, not-had at all.In this particular case, I chose to step in (and in this way), because I know you know I myself struggle a LOT with communication, and we've discussed elsewhere about the approaches that work better, and our own typical failure patterns. Simply put, I can see myself doing exactly the same error here, and I'd like the error to be fixed, so we can go back to arguing about the interesting stuff instead. Tough love, if you like.Perhaps I should have done this via PM instead, but didn't because DiTBho didn't start the thread, and mywas more directed at RoGeorge for starting the thread in the first place and everyone else equally for arguing, well, about thestatisticsof goto use!Thus, I suppose I too failed in my communication attempt here. I apologise.

author: nctnico
author_rank: Super Contributor
timestamp: October 31, 2023, 12:31:03 am
content: Quote from: Siwastaja on October 29, 2023, 07:37:46 amYou can just as easely argue using goto leads to unreadable code due to jumping to other parts of a function which makes it hard to follow a function (and where it actually exits). But the same can be argued about using return somewhere in the middle of a function and break and continue in for/while loops. I'd say using a goto is typically an indication of problems getting the code structured in a way that the code is easy to follow.In the Linux kernel using goto is typically done for an on-exception-exit pattern. Most of the drivers use gotos in their init section where depending on how far the process gets, dynamically allocated memory gets unallocated in case the driver initialisation fails. IMHO this is one of the very few good uses of goto in the C language: crude exceptions.

author: Siwastaja
author_rank: Super Contributor
timestamp: October 31, 2023, 07:32:55 am
content: Quote from: nctnico on October 31, 2023, 12:31:03 amQuite obviously, but I chose not to reiteratethatviewpoint because it seems to be very very very commonly known and discussed already. (The very reason why people do stuff like grep goto on linux kernel.)The two typical uses for goto in C are as you mention exception handling during initializations, which I demonstrated above with code, and in some cases, for breaking out of a 2D loop without having to resort to unintuitive temporary variables.And no, 2D loops are not evil per se. For example, if you process a 2D image then x and y loops make perfect sense and it would be confusing to refactor into a function call (loop_row() or what?) just to get rid of one level. And C doesn't have named loops and break only breaks one level, so goto fixes both: it adds labels and allows breaking two levels.Now one could argue that most if nearly all good uses ofgotoalways jumpforward, but I'm sure someone can come up with a good example where jumping backwards is better than the alternatives, but this would be a rarity. Personally I have done that when handling exceptional error cases where I just want to "start over" instead of "giving up", as a quick fix for the edge case instead of spending a lot of time figuring out how to refactor the whole thing so that this edge case handles "more elegantly".We were taught in university how goto is bad becauseyou can jump anywhere, including other functionsbut that obviously was a lie and tells a lot about the level of understanding in the academic world.

author: nctnico
author_rank: Super Contributor
timestamp: November 01, 2023, 12:55:27 am
content: I wouldn't call it a lie but rather an over-simplified model. I'm from the period when universities started teaching Pascal in order to make students think about structuring their software in an elegant way. Quite usefull until the point some people start to have the crazy idea you can write real software in Pascal

author: DC1MC
author_rank: Super Contributor
timestamp: November 01, 2023, 07:26:34 am
content: Quote from: Siwastaja on October 31, 2023, 07:32:55 amWhy no one is discussing animore aboutsetjmpandlongjmpin CCheers,DC1MC

author: DiTBho
author_rank: Super Contributor
timestamp: November 01, 2023, 09:17:11 am
content: Quote from: Nominal Animal on October 30, 2023, 09:33:39 pmCan you see how frustrating this forum is?I said in orderLinux is not a good reference. Is it? you confirmed it's notthen I mentioned PPC because it's what I am working at the moment and it's happening right now that we have 5 months of regression, Linus himself is complainingso, Linux is not a good reference, not even for looking at how gotos are usedat that point someone suggested that a big problem is documentation, and I confirmed itlittle anecdote about how the "cowboy to the console" approach to the wild west of Linux, can even create absurd situations where if nobody understands absolutely nothing about the code then it's a big problem for development. It was full of gotos, in many point it was abused, strange pointer arithmetic, inline assembly and all kinds of shenanigans, and to understand how the code worked, thousands of hours of work were needed, practically rewriting everything from scratchthen I pointed out that if there are no precise regulations you end up having little projects that only stand up if there are a lot of people following them, just like Linux, or worse still, just like linux in my anecdoteat that point I suggested looking elsewhere, pointing out that where there are regulations, things are much better both understandable and manageable, even by small teamsI mentioned VxWorks, and the discussion derailed *HERE* when I pointed out Windiriver's approach, and note why it derailed: because some "troll" willfully misunderstood what I wrote in order to ridicule those who do competent workAnd frankly it bothers me a lot that people who don't even have the competence to speak (for example about DO178, someone here called it "bullshit for trained monkeys"), and this is because they have never done anything mission critical, often allow themselves to start a reply with the "it's bullshit", as happened in the topic of cyclomatic complexity.Even worse when what they call "bullshit" often has serious reasons behind it, sometimes reasons of an organizational and not just technical nature.And this because "practice" means "organize people doing software" as important as "design software" as well as "find a resonable way to allocate resources to test software".All points that have continued to be repeated for years, and you explain it and every damn time we always come back to the same points, over and over, which makes me realize that arguing in this forum is a total waste of my time.So, sorry, but no.

author: Siwastaja
author_rank: Super Contributor
timestamp: November 01, 2023, 11:48:52 am
content: Or, maybe you just take someone calling a practice "bullshit" (A) personally, (B) too seriously? I mean, it's notthatstrong of a word. It just means whoever said that does not believe the practice is good at all. More important is to lookwhythey think the practice is bullshit. And don't get hurt on behalfof a process.I don't remember seeing that "trained monkey" thing you refer to, and it's nasty language I admit that. I have never ever name-called professionals working on the regulated fields you mention, and have no reason to do that. If you read what I wrote, you will see it's the opposite; I'm happy I can create software more freely and still sleep well, not being on their shoes; and I'm happy I can stilldiscusswhatIthink about safety critical software, but it seemsyouare not happy about me discussing it.But whatever. I think your fundamental issue on this forum is in anger management and poor communication. You are not the only one, I can say from personal experience of having the exact same issue. But in reality, others are not as stupid as you may think. Give us a chance.

author: DiTBho
author_rank: Super Contributor
timestamp: November 01, 2023, 07:31:33 pm
content: Quote from: Siwastaja on November 01, 2023, 11:48:52 am... well, about that, it's you who that, misunderstanding what I wrote, thought that we must be really *very stupid to accept*(1) - according to your interpretation - that it is enough to make Chatgpt(1) write some random documentation in the code to pass a piece of code by the QA team, who is composed by professionists!I didn't specify what it was "necessary condition, not sufficient", my fault there, I edited my post, but how many times have I repeated how things really work? How many? So, before starting with "I'm horrified", didn't you even have any doubts? no, because in your opinion we only do bullshit! It takes you very little to brand things as "bullshit" (like in the Cyclomatic topic, where I simply ignored some of your bad statements), and it costs me too much time to explain it to you, and then what? See, you didn't even get the concept!Damn, this is the common pattern here in this forum(2), and it's really frustrating!Among other things, if I have always underlined that developers and testers should never talk to each other except through specific documents, the Windriver's approach creates a shortcut that allows, through mandatory documentation, to better describe both the code and the various doubts about how to write and test it, which is brilliant "extension" because it reduces the numer of iteractions and helps people growing up "team building"!It seems like something within everyone's reach, because everyone can start describing the code, obviously in a concise and targeted way; Windriver pays some professionists with skills in being concise and targeted way, and QA guys have the same skill, so here OpenSource guys have to learn to do it well, but it's a true benefit and it's feasible, if not mandatory, it should at least become a habit!(1) precisely here I saw the offense to the entire category

author: Siwastaja
author_rank: Super Contributor
timestamp: November 01, 2023, 07:56:44 pm
content: I merely commented on your claim that AI cannot be used to cheat "because it's in natural language". Don't take it out of context. I totally agree with what younowwrite; that competency in management is what prevents such cheating.You(!!) are the one who mentioned cheating with AI, as if it would happen if the document were not in natural language!Youwere the one whose descriptions about these regulated fields made me horrified. You are the one giving bad picture about "your" field. You fail to communicate because you are arrogant and write quicker than you think when angry.And while I trust a lot of safety critical software (otherwise, I would not board an airplane), I still have my doubts about how the arrogance you show affects your work.Now can you do us all a favor and start actually ignoring people you claim to ignore and therefore stop derailing threads? Thank you in advance.

author: thm_w
author_rank: Super Contributor
timestamp: November 01, 2023, 10:31:16 pm
content: Quote from: Siwastaja on October 29, 2023, 11:02:22 amYou can write it this way instead:Code:int do_thing(){turn_relay_on();if(!good_to_go)result = FAILURE_1;else if(asdf != 123)result = FAILURE_2;else{do_rest_of_stuff();result = SUCCESS;}turn_relay_off();return result;Anything that relies on copy pasting required steps in multiple locations is generally bad code. Regardless of having goto's or not.

author: cfbsoftware
author_rank: Regular Contributor
timestamp: November 01, 2023, 11:39:05 pm
content: Quote from: DiTBho on November 01, 2023, 07:31:33 pmI believe it would help let off steam in this forum if we could just mark a message as "Say No Thanks" instead of "Say Thanks" and then move on.

author: SiliconWizard
author_rank: Super Contributor
timestamp: November 02, 2023, 05:46:24 am
content: Quote from: cfbsoftware on November 01, 2023, 11:39:05 pmThat's not a bad idea indeed.

author: Siwastaja
author_rank: Super Contributor
timestamp: November 02, 2023, 11:21:27 am
content: That idea has been discussed before and while on surface it looks like a good idea, it quickly becomes stack overflow / reddit type "downvote into oblivion" system. "Thank you" thing might be unnecessary, but at least it's mostly positive (even that is used in a nasty way, "thanking" some users from very low-quality contributions just because they disagreed with someone with "wrong" opinion, but that use pattern is at least complex and thus not too common, compared to direct downvoting).Users already have a way "to move on". Everyone posts here at their free will. Being able to be negative against people in a yet another (and easier!) way only results in more negativity, not "moving on".

author: metertech58761
author_rank: Frequent Contributor
timestamp: November 20, 2023, 02:30:51 pm
content: When I started learning C++, I too was told "GOTO bad. VERY BAD. Here your dunce cap. Stand in corner!"After stewing on that a while, I came up with a different take; I write the code as I please, then go back and say "How many GOTO can I take out and still understand what's going on?"

author: Karel
author_rank: Super Contributor
timestamp: November 20, 2023, 04:02:52 pm
content: In the poll, I'm missing the option:Linus and his lieutenants know what they are doing