[Gambas-user] usage of too much GOTO can be bad pracitce or make influence in the code?

Fernando Cabral fernandojosecabral at ...626...
Sun Jun 25 19:43:06 CEST 2017


>
> On Sun, 25 Jun 2017, PICCORO McKAY Lenz wrote:
> > this are poor ilustrated to most of users here in the list due i think
> > nobody here know (in experience) code in assemble like me..
>
> Lenz, I think you should pay attention to what Tobi has said. Very
instructive and comprehensive (although succinct).
In Assembly, yes, GOTOs are used abundantly. That has to do with the lower
level progamming required by the machine language. But, avoiding machine
language was, perhaps, the main reason why high-level language were
invented in the fifities (BASIC was created in 1964). The newer and the
higher-level the language, the less your programming should require GOTOs.

When you say you have 4.000+ lines of code inside a IF THEN, and 4.000+
more after the ELSE, I would guess your code is very hard to read and
understand. Perhaps you could benefit from some reorganization. For
instance, breaking it down into smaller functions (or subroutines) you can
call as needed.

The more you break it down (up to a point), the easier it is to know what
your are doing at each stage.

On the other hand, functionality and efficacy come first. Performance comes
next. That's because - no matter how fast your program is - if it is not
doing what it is supposed to do, it is useless.

Even in higher-level language, GOTO could be theoretically faster. But we
would be talking about gains of very tyne fractions of milliseconds. Will
it make any difference:  I doubt it. It is hard to think and code
bottleneck could be solved with GOTOs. If it is inefficient, it will
continue to be so even if you spread GOTOs all over.

Many of us consider GOTOs to be an unecessary and confusing command. But If
you feel that using GOTO is your way to go, by all means, use it.

Regards

-fernando




>
> Oh wow, that's a high footstool you're sitting on.
>
> > so i'm very frustrating due when i try to use gambas in professional way
> > (due are very promisess and usefully) many questions require spend of
> time
> > due situations like that... please users.. dont make conjetures of things
> > that not known, causes spend of time of otheers
> >
>
> What most people talked about were the usual readability concerns which
> are the first thing that's brought forward in every one of the countless
> "GOTO considered harmful" essays out there. Supposing you asked a general
> question about good practices regarding GOTO (which you were, just look
> at your opening message!) they also said that it was up to personal
> preference in the end. Therefore I don't see the too many inconsistencies
> you speak of.
>
> The only one who said anything about performance, which you bring up above,
> was nando:
>
> > Sometimes GOTO is needed...especially if you want your code to run
> faster.
>
> and here I agree with you. The last part is certainly debatable and depends
> on the platform (using goto in C is wildly different from using GOTO in
> Gambas, see below). *The* standard example, and *perhaps* what he thought
> of, is jumping out of 4 nested loops without GOTO. You can do it but at
> least the obvious two solutions introduce new functions (i.e. calls and
> returns) or some more IFs, both of which are forms of jumps.
>
> > i case of gambas analizing the code seems are not the same.. due gambas
> > fist make their own bycode that runtime inderstand and then that runtime
> > pass to object mahine.. so many things change and its not the same... in
> > easy words..
> >
>
> Exactly, so why do you think your concerns about pipelining and branch
> prediction at the C -> machine level are relevant at all in Gambas?
> The program execution loop in the interpreter is a gigantic jump table.
> The execution of every instruction in a Gambas program involves at
> least two goto's in C, while the actual Gambas GOTO instruction is
> implemented as an arithmetic operation on the program counter!
>
> And no, I'm not conjecturing this; it's right there in the source code.
> It should be natural that you read it if you require a deeper understanding
> for your professional tasks than what others can provide. Your time is
> not more precious than anyone else's on this list.
>
> On a tangent I'm surprised nobody took the opportunity to scold Benoit
> in this thread yet :-) Have you never tried modifying one of his parsers,
> e.g. gb.markdown:
>
>   $ cd ~/src/gambas3/comp/src/gb.markdown/.src
>   // Count non-empty, non-comment lines
>   $ egrep -cv "^[ ]*'|^[ ]*$" Markup.module
>   798
>   // Count labels, GOTO and GOSUB lines which are not commented out
>   $ egrep -i ":[ ]*$|GOTO|GOSUB" Markup.module | grep -cv "^[ ]*'"
>   75
>   // Percentage of directly GOTO-related lines in the markdown parser
>   $ pcalc 100*75/798
>         9.398496240601503       0x9                     0y1001
>
> Regards,
> Tobi
>
> --
> "There's an old saying: Don't change anything... ever!" -- Mr. Monk
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>



-- 
Fernando Cabral
Blogue: http://fernandocabral.org
Twitter: http://twitter.com/fjcabral
e-mail: fernandojosecabral at ...626...
Facebook: f at ...3654...
Telegram: +55 (37) 99988-8868
Wickr ID: fernandocabral
WhatsApp: +55 (37) 99988-8868
Skype:  fernandojosecabral
Telefone fixo: +55 (37) 3521-2183
Telefone celular: +55 (37) 99988-8868

Enquanto houver no mundo uma só pessoa sem casa ou sem alimentos,
nenhum político ou cientista poderá se gabar de nada.



More information about the User mailing list