Page 3 of 3 FirstFirst 123
Results 81 to 85 of 85

Thread: GOSUB - Is it really bad?

  1. #81
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    996

    Re: GOSUB - Is it really bad?

    IF you KNOW what you're doing, IF you UNDERSTAND the implications of what you're doing, AND you're willing to deal with the consequences, AND you understand what is happening and why,
    You mean people write code that they don't understand? Whow! I'm absolutely amazed and flabbergasted. Surely not.

    Actually not quite true or perhaps you are too young to remember. Windows was originally a "cooperative multi-tasking" O/S before I think 3.51 where it was actually required for you to give up the CPU. Proper preemptive scheduling only came later.
    The Windows 3.x/9x etc versions that were based upon MS_DOS were co-operative multi-tasking. If you processed a windows message and didn't return control to the OS - or took a long time to return control, nothing else was responsive! It was the NT series (confusingly also called 3.x then 4, 2000 etc) that had 'proper' pre-emptive scheduling. That's why there were many issues with early Windows 3.x programs as the early programmers didn't understand all of this - until Petzold (Programming Windows 3.1) when he explained it all.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  2. #82
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: GOSUB - Is it really bad?

    Eh. I don't think you should ever use DoEvents(), but I say this from the platform of VB .NET where there are at least 3 usable patterns for writing asynchronous code. If it's hard to coordinate multithreaded code in VB6, I could accept that as a reason to use DoEvents().

    But as has been stated, it creates nasty situations where code you didn't think can be interrupted can be interrupted. The rules for using DoEvents() safely are very similar to the rules for synchronizing multiple threads. The problem is that takes some thoughtful design up-front, and most people seem to try retrofitting asynchronous behavior as a maintenance task. You can't do that half as easily. The rule of thumb for professional development should be like what guided MS when designing the WinRT APIs: "If it can take >250ms, it should be asynchronous."

    I think this propagates somewhat innocently. If a newbie asks how to open/parse a file, you're not going to show a solution that involves asynchronous code. It doesn't make any sense to show a more complex solution than the synchronous one, and the newbie would likely be distracted. But then they go and reveal it's a 700MB file that takes 10 minutes to parse, and they'd like to do other things while it happens. This is when something distinctly "internet help" happens.

    The right answer is to start talking about asynchronous code. But someone's going to post a solution using DoEvents(). It might have problems. It won't matter. Their solution doesn't involve another tutorial so it's automatically "right" in the eyes of a newbie. It doesn't matter if the newbie has the issues you warn them about: this is "less code" so it's "more right" in their eyes. I've lost that argument so many times I don't bother posting even 25% as much as I used to.

    UWP, built on WinRT, gets this part right because it follows the rule of thumb. Because file I/O can take a long time, the only methods that do it are asynchronous. So you can't show the newbie how to do it without discussing asynchronous code. That renders the DoEvents() approach useless, and also means the "most right" answer is also the "most obvious".

    But MS can't pay people to use that, and we're in the VB6 section of the forum so we don't have those tools anyway. It still doesn't make DoEvents() the right first tool, in my opinion.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  3. #83
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: GOSUB - Is it really bad?

    Quote Originally Posted by 2kaud View Post
    It was the NT series (confusingly also called 3.x then 4, 2000 etc) that had 'proper' pre-emptive scheduling.
    David Cutler and a team of prior Digital Equipment Corp folk joined MS to school them on how to write a proper multi-tasking OS back in 1988.

    I miss my VAX...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  4. #84
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: GOSUB - Is it really bad?

    Related article: Psychology of Code Readability

    There is an illustration at the end of the article that explains the idea of "To reduce complexity, add classes"



    5 inter-dependent classes are reduced to groups of 3 inter-dependent classes by *adding* 2 more classes. These 2 new classes wrap 4 previous classes from the original left mesh.

    cheers,
    </wqw>

  5. #85
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    996

    Re: GOSUB - Is it really bad?

    Quote Originally Posted by szlamany View Post
    David Cutler and a team of prior Digital Equipment Corp folk joined MS to school them on how to write a proper multi-tasking OS back in 1988.

    I miss my VAX...
    Me too. And the PDP-11. Those were the good old days......
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Page 3 of 3 FirstFirst 123

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width