Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. In defense of spaghetti code. *ducks*

In defense of spaghetti code. *ducks*

Scheduled Pinned Locked Moved The Lounge
designhardwarehelpquestion
150 Posts 34 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Jeremy Falcon

    You're missing the point. Thus, this is going nowhere nor will it. It's just another pointless argument. I'm gonna go live my life now.

    Jeremy Falcon

    H Offline
    H Offline
    honey the codewitch
    wrote on last edited by
    #41

    Solid plan.

    To err is human. Fortune favors the monsters.

    J 1 Reply Last reply
    0
    • J Jeremy Falcon

      This is going nowhere. You have more time to argue than I have a desire to be here. Tootles.

      Jeremy Falcon

      H Offline
      H Offline
      honey the codewitch
      wrote on last edited by
      #42

      Hello? You're the one that started arguing with *me*. I'm simply defending my position. Not only that, you couldn't keep it to debate, and had to insult my professional abilities and experience.

      To err is human. Fortune favors the monsters.

      J 1 Reply Last reply
      0
      • H honey the codewitch

        Hello? You're the one that started arguing with *me*. I'm simply defending my position. Not only that, you couldn't keep it to debate, and had to insult my professional abilities and experience.

        To err is human. Fortune favors the monsters.

        J Offline
        J Offline
        Jeremy Falcon
        wrote on last edited by
        #43

        Nope. Wrong. And a senior should know better.

        Jeremy Falcon

        H 1 Reply Last reply
        0
        • J Jeremy Falcon

          Nope. Wrong. And a senior should know better.

          Jeremy Falcon

          H Offline
          H Offline
          honey the codewitch
          wrote on last edited by
          #44

          That doesn't even make any sense. You're seriously arguing that I'm the one that started arguing with you? :laugh: Okay man. Get on with your life.

          To err is human. Fortune favors the monsters.

          J 1 Reply Last reply
          0
          • G Gary R Wheeler

            I can make the argument that spaghetti code is the better solution in this case. Creating a general-purpose framework tends to hide the logic. At least when you came back at some future time you only have to understand the spaghetti, and not a framework as well. I think YAGNI and KISS both apply here. Obviously the answer is different if you're tailoring the spaghetti for multiple solutions.

            Software Zen: delete this;

            J Offline
            J Offline
            Jeremy Falcon
            wrote on last edited by
            #45

            To me spaghetti code is basically like a messy room you don't clean up. Doesn't mean you need to make a framework, but ya know... at least make the bed.

            Jeremy Falcon

            G 1 Reply Last reply
            0
            • H honey the codewitch

              That doesn't even make any sense. You're seriously arguing that I'm the one that started arguing with you? :laugh: Okay man. Get on with your life.

              To err is human. Fortune favors the monsters.

              J Offline
              J Offline
              Jeremy Falcon
              wrote on last edited by
              #46

              You're not stopping with the replies... you can have the last word if arguing online is that important to you.

              Jeremy Falcon

              H 1 Reply Last reply
              0
              • J Jeremy Falcon

                You're not stopping with the replies... you can have the last word if arguing online is that important to you.

                Jeremy Falcon

                H Offline
                H Offline
                honey the codewitch
                wrote on last edited by
                #47

                At this point I think you're here to troll. :~

                To err is human. Fortune favors the monsters.

                1 Reply Last reply
                0
                • H honey the codewitch

                  I ran into an issue recently on a professional embedded project, and that was this: In translating the flow diagrams to code, there were so many conditions around state changes and such that my options were to either abstract the flow with some sort of generalized framework, or cook some spaghetti code. I chose the latter. Why? Simple. The actual effort if anything would be about equal, or favor the spaghetti approach. More importantly, progress remains visible with the spaghetti approach rather than the abstract flow framework which requires a lot of up front design and work without progress visible to the client. Finally, this is embedded code, where a rewrite is maybe a grand or two $USD, on the outside, assuming not a lot of reuse. It would cost at least half that to develop a simple framework, which might make things more maintainable, but questionable in terms of how effortlessly one can make changes (whereas maintainability is more about stepping away for a month and being able to pick it up again, mostly - or someone else picking up your code). It's all a matter of robbing peter to pay paul. The bottom line here is that while we may chase perfect code, and "best practices" that's not always the most effective technique for keeping the lights on. Flame away.

                  To err is human. Fortune favors the monsters.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #48

                  To even admit that I would write spaghetti code knowingly is counter to every fibre in my being. I was the first in my company, way back when, to be asked what I thought of "structured programming"; i.e. no "go to's". I wrote the first "structured program" and never looked back.

                  "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

                  H 1 Reply Last reply
                  0
                  • L Lost User

                    To even admit that I would write spaghetti code knowingly is counter to every fibre in my being. I was the first in my company, way back when, to be asked what I thought of "structured programming"; i.e. no "go to's". I wrote the first "structured program" and never looked back.

                    "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

                    H Offline
                    H Offline
                    honey the codewitch
                    wrote on last edited by
                    #49

                    The spec was spaghetti, so my choice was to design directly to spec, or try to abstract it. I chose the former, and I'm pretty happy with the result. Including coming in under budget.

                    To err is human. Fortune favors the monsters.

                    L 1 Reply Last reply
                    0
                    • H honey the codewitch

                      I ran into an issue recently on a professional embedded project, and that was this: In translating the flow diagrams to code, there were so many conditions around state changes and such that my options were to either abstract the flow with some sort of generalized framework, or cook some spaghetti code. I chose the latter. Why? Simple. The actual effort if anything would be about equal, or favor the spaghetti approach. More importantly, progress remains visible with the spaghetti approach rather than the abstract flow framework which requires a lot of up front design and work without progress visible to the client. Finally, this is embedded code, where a rewrite is maybe a grand or two $USD, on the outside, assuming not a lot of reuse. It would cost at least half that to develop a simple framework, which might make things more maintainable, but questionable in terms of how effortlessly one can make changes (whereas maintainability is more about stepping away for a month and being able to pick it up again, mostly - or someone else picking up your code). It's all a matter of robbing peter to pay paul. The bottom line here is that while we may chase perfect code, and "best practices" that's not always the most effective technique for keeping the lights on. Flame away.

                      To err is human. Fortune favors the monsters.

                      J Offline
                      J Offline
                      jschell
                      wrote on last edited by
                      #50

                      honey the codewitch wrote:

                      More importantly, progress remains visible with the spaghetti approach

                      Of course. Ideals should not be applied blindly. They should be followed when they provide benefit.

                      honey the codewitch wrote:

                      but questionable in terms of how effortlessly one can make changes (whereas maintainability is more about stepping away for a month and being able to pick it up again, mostly

                      I really, really dislike the claim that abstractions make anything better when no one can provide any evidence at all that future needs of any sort will be needed. If requirements exist, or a roadmap is known or even if someone expressed a desire for a future feature then maybe consider it. But don't do it 'just in case'. Doing so it no better than gambling on the big wheel in a casino (one of the worst odds games in play.) It does not insure any economic future advantage but it does guarantee complexity which future programmers must then maintain (and so must be paid for.)

                      H E 2 Replies Last reply
                      0
                      • B Bruno van Dooren

                        I have the impression that OP interchanges 2 things: purpose built single use code, and code with horrible control flow and global data access. I've written code for running on DSPs, on the bare hardware, and everything was purpose coded with a thin hardware abstraction library I made. In my case I had only 16K program memory and 2K RAM. hardware limits aside, when you are programming close to bare metal, it starts to be less and less useful to implement generic frameworks.

                        N Offline
                        N Offline
                        Nelek
                        wrote on last edited by
                        #51

                        I have programmed a lot of PLCs and while I had a lot of more resources in hardware than you, my coding options were way smaller. Using JMP to control the flow of the program (IF-Else, Calls, partial returns...) was a must. There were no other options. But as you say, having to program like this, it doesn't mean that the code flow has to be ugly, weird or confusing. The different between clean or crappy programs depends mostly on the person programing it, not on the methodic or the language.

                        M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

                        1 Reply Last reply
                        0
                        • J jschell

                          honey the codewitch wrote:

                          More importantly, progress remains visible with the spaghetti approach

                          Of course. Ideals should not be applied blindly. They should be followed when they provide benefit.

                          honey the codewitch wrote:

                          but questionable in terms of how effortlessly one can make changes (whereas maintainability is more about stepping away for a month and being able to pick it up again, mostly

                          I really, really dislike the claim that abstractions make anything better when no one can provide any evidence at all that future needs of any sort will be needed. If requirements exist, or a roadmap is known or even if someone expressed a desire for a future feature then maybe consider it. But don't do it 'just in case'. Doing so it no better than gambling on the big wheel in a casino (one of the worst odds games in play.) It does not insure any economic future advantage but it does guarantee complexity which future programmers must then maintain (and so must be paid for.)

                          H Offline
                          H Offline
                          honey the codewitch
                          wrote on last edited by
                          #52

                          You covered something very well here that I was thinking about earlier regarding abstractions paying for themselves. :)

                          To err is human. Fortune favors the monsters.

                          1 Reply Last reply
                          0
                          • J Jeremy Falcon

                            honey the codewitch wrote:

                            They should be used as sparsely as possible and no sparser.

                            To use your wording with Ravi... you may wish to re-read what I said. It was in the context of having to do something not considered normal. Which clearly includes the scenario you referring to. That being said, I disagree with the premise of being too sparse with comments. I'm not a junior programmer. I don't have the time nor inclination to tell people comments like // assign variable x to y are bad. That should be a given for senior level chats. This is actually the reason I visit CP less and less these days if I'm being honest. If comments get stale, that's not the fault of comments but the developer. There reasons tools like doxygen and jsdoc exist. Again, if this is code that is for your personal use only, all of this is overkill. But when being paid for it, that tends to suggest it's not.

                            Jeremy Falcon

                            N Offline
                            N Offline
                            Nelek
                            wrote on last edited by
                            #53

                            Jeremy Falcon wrote:

                            If comments get stale, that's not the fault of comments but the developer.

                            The same with code. In the PLC world it is a wide extended practice to just add a "AND 0" at the beginning of a code segment to anulate it. That's even worst than commenting it out, because it appears in the cross references as well, commented code doesn't. I once refactored a program of the "Senior" that taught me whe I started, because it was a PITA to work with it.

                            M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

                            J 1 Reply Last reply
                            0
                            • N Nelek

                              Jeremy Falcon wrote:

                              If comments get stale, that's not the fault of comments but the developer.

                              The same with code. In the PLC world it is a wide extended practice to just add a "AND 0" at the beginning of a code segment to anulate it. That's even worst than commenting it out, because it appears in the cross references as well, commented code doesn't. I once refactored a program of the "Senior" that taught me whe I started, because it was a PITA to work with it.

                              M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

                              J Offline
                              J Offline
                              Jeremy Falcon
                              wrote on last edited by
                              #54

                              Nelek wrote:

                              The same with code.

                              100% agree.

                              Nelek wrote:

                              In the PLC world it is a wide extended practice to just add a "AND 0" at the beginning of a code segment to anulate it. That's even worst than commenting it out, because it appears in the cross references as well, commented code doesn't.

                              :laugh:

                              Nelek wrote:

                              I once refactored a program of the "Senior" that taught me whe I started, because it was a PITA to work with it.

                              For sure man. Not a big fan of titles and there are some that are "senior" but for them it really means they just spent more years not really learning. Buyer beware. Gotta find the good ones.

                              Jeremy Falcon

                              1 Reply Last reply
                              0
                              • H honey the codewitch

                                I ran into an issue recently on a professional embedded project, and that was this: In translating the flow diagrams to code, there were so many conditions around state changes and such that my options were to either abstract the flow with some sort of generalized framework, or cook some spaghetti code. I chose the latter. Why? Simple. The actual effort if anything would be about equal, or favor the spaghetti approach. More importantly, progress remains visible with the spaghetti approach rather than the abstract flow framework which requires a lot of up front design and work without progress visible to the client. Finally, this is embedded code, where a rewrite is maybe a grand or two $USD, on the outside, assuming not a lot of reuse. It would cost at least half that to develop a simple framework, which might make things more maintainable, but questionable in terms of how effortlessly one can make changes (whereas maintainability is more about stepping away for a month and being able to pick it up again, mostly - or someone else picking up your code). It's all a matter of robbing peter to pay paul. The bottom line here is that while we may chase perfect code, and "best practices" that's not always the most effective technique for keeping the lights on. Flame away.

                                To err is human. Fortune favors the monsters.

                                P Offline
                                P Offline
                                PIEBALDconsult
                                wrote on last edited by
                                #55

                                Define "spaghetti code".

                                H 1 Reply Last reply
                                0
                                • P PIEBALDconsult

                                  Define "spaghetti code".

                                  H Offline
                                  H Offline
                                  honey the codewitch
                                  wrote on last edited by
                                  #56

                                  Spaghetti code lacks an easily understandable flow to it. It jumps around in less than obvious ways, basically.

                                  To err is human. Fortune favors the monsters.

                                  1 Reply Last reply
                                  0
                                  • D Daniel Pfeffer

                                    I understand and mostly agree with your reasoning, but writing spaghetti code feels dirty, somehow.

                                    Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

                                    J Offline
                                    J Offline
                                    jmaida
                                    wrote on last edited by
                                    #57

                                    My grad school prof stressed "go to" less programming techniques to avoid spaghetti. Structured code and a few comments was the rule, even with Fortran (which was not easy). We also used PL/I, Ada, Pascal, C (C++ was in the early stages of use).

                                    "A little time, a little trouble, your better day" Badfinger

                                    1 Reply Last reply
                                    0
                                    • H honey the codewitch

                                      The spec was spaghetti, so my choice was to design directly to spec, or try to abstract it. I chose the former, and I'm pretty happy with the result. Including coming in under budget.

                                      To err is human. Fortune favors the monsters.

                                      L Offline
                                      L Offline
                                      Lost User
                                      wrote on last edited by
                                      #58

                                      I've never been over budget. I also don't accept ridiculous schedules. You can have it fast, cheap, and / or good. Pick 2.

                                      "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

                                      H M 2 Replies Last reply
                                      0
                                      • H honey the codewitch

                                        I ran into an issue recently on a professional embedded project, and that was this: In translating the flow diagrams to code, there were so many conditions around state changes and such that my options were to either abstract the flow with some sort of generalized framework, or cook some spaghetti code. I chose the latter. Why? Simple. The actual effort if anything would be about equal, or favor the spaghetti approach. More importantly, progress remains visible with the spaghetti approach rather than the abstract flow framework which requires a lot of up front design and work without progress visible to the client. Finally, this is embedded code, where a rewrite is maybe a grand or two $USD, on the outside, assuming not a lot of reuse. It would cost at least half that to develop a simple framework, which might make things more maintainable, but questionable in terms of how effortlessly one can make changes (whereas maintainability is more about stepping away for a month and being able to pick it up again, mostly - or someone else picking up your code). It's all a matter of robbing peter to pay paul. The bottom line here is that while we may chase perfect code, and "best practices" that's not always the most effective technique for keeping the lights on. Flame away.

                                        To err is human. Fortune favors the monsters.

                                        J Offline
                                        J Offline
                                        jmaida
                                        wrote on last edited by
                                        #59

                                        This spaghetti code topic sure stirred the pot, but it's a very worthy topic for all programmers, especially the new ones. Thanx.

                                        "A little time, a little trouble, your better day" Badfinger

                                        1 Reply Last reply
                                        0
                                        • B Bruno van Dooren

                                          I have the impression that OP interchanges 2 things: purpose built single use code, and code with horrible control flow and global data access. I've written code for running on DSPs, on the bare hardware, and everything was purpose coded with a thin hardware abstraction library I made. In my case I had only 16K program memory and 2K RAM. hardware limits aside, when you are programming close to bare metal, it starts to be less and less useful to implement generic frameworks.

                                          J Offline
                                          J Offline
                                          jmaida
                                          wrote on last edited by
                                          #60

                                          I agree, Bruno. If you need to build a shed, you don't use sky scrapper blue prints.

                                          "A little time, a little trouble, your better day" Badfinger

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups