#1
  1. Nihilistic Nerd
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2017
    Posts
    29
    Rep Power
    0

    Structured Programming Considered Harmful


    Okay, the title of the thread is intentional clickbait; but relevant nonetheless.

    While talking with a friend about industry-wide shifts in ideology and programming paradigms, I made a joke about combining all the ideas that were universally considered "bad" and pooling them into a single language that somehow managed to be "good". Among these was going back to goto-style programming. At first, it was laughable, but the more I thought about it, the more appealing it started to become. And here's why:

    • Most of the unstructured languages didn't have alphanumeric identifiers for labels; and much of the illegibility and tediousness can be attributed to jumping to line numbers. Adding alphanumeric labels can actually make the code easier to read and write. Some modern languages have even taken to allowing loop structures to be labeled.
    • Most of them also didn't have subroutines, which meant that you had to actively think hard about the organization of your code or you'd quickly end up with spaghetti code. Adding subroutines can eliminate most spaghetti code.
    • Not having structures doesn't mean there's no scope. It just means that everything declared inside of a subroutine is local to the subroutine; just like the function scoping in languages like Python and JavaScript.
    • All structural loops can be rewritten as anonymous functions, which is becoming increasingly common in newer functional languages.
    • Goto makes error handling much easier, because you can jump to a section that does cleanup without having to tinker with magic states.
    • Using goto can eliminate almost a dozen structural keywords from a language: break, continue, for(each), while, switch, case, default, try, catch, throw, and defer


    Despite the title (intended to parody "Goto Considered Harmful"), I'm not asserting that structured programming is actually harmful or bad in any way. It's just a different style of programming which is much more prominent these days. I think that there's some value in taking another look at unstructured programming given that there are a lot of new concepts that just didn't exist back then.
  2. #2
  3. Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    www.SimpleInstaller.net
    Posts
    17
    Rep Power
    0
    There is a good reason why unstructured languages have gone bye bye: bugs. Way too many bugs. Structured languages, especially those with strict type casting, have eliminated the cause of many bugs getting into a program. OOP has brought this to the latest state of writing a program with minimum bugs. I started programming a long time ago using Basic and goto statements. While many developers like different kinds of programming languages, I think trying to introduce a goto language would be a step backwards. That's just my opinion. It would be interesting to hear other opinions.
  4. #3
  5. Lord of the Dance
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Oct 2003
    Posts
    4,131
    Rep Power
    2011
    Originally Posted by Wajideus
    • Goto makes error handling much easier, because you can jump to a section that does cleanup without having to tinker with magic states.
    I can follow you on this one. I have been at situations where I think the code would be easier to read with a "goto error-handling" call.


    Originally Posted by Wajideus
    • Using goto can eliminate almost a dozen structural keywords from a language: break, continue, for(each), while, switch, case, default, try, catch, throw, and defer
    Goto needs to point to a place, but goto does not tell about where or why it is called to that place. This is where labels come in. What would we then called those labels? Break? Continue?
    As rfresh said, there is sometime a really good reason for where we are today: Improvement over time.
    Last edited by MrFujin; October 9th, 2017 at 03:52 PM.
  6. #4
  7. Nihilistic Nerd
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2017
    Posts
    29
    Rep Power
    0
    The format of my post made it very unclear, but I wasn't saying that structured programming should be replaced with goto.

    What I was saying was that there are new techniques such as:

    • lambda / anonymous functions
    • closures / captures
    • tail-call elimination / trampolines
    • iterators / coroutines


    That can allow for all of the same functionality and structure of existing languages, but simplifying the syntax and scope complexity by removing a lot of redundant functionality.

IMN logo majestic logo threadwatch logo seochat tools logo