Question

In the spirit of the latest podcast where Joel mentioned he'd like some simple questions with possibly interesting answers ...

In the environments we have to programme in today we can't rely on the order of execution of our langauage statements. Is that true? Should we be concerned?

Will 30 GOTO 10 always go to 10?*

*I didn't use 20 on purpose ;)

[edit] for the four people voting for closure of this question ...

"Runtime compilers use profiling information to help optimize the code being compiled. The JVM is permitted to use information specific to the execution in order to produce better code, which means that the compiling method M in one program may generate different code than compiling M in another"

(from Java concurrency in practice, 2006, Goetz et al)

.. have a look at "monomorphic call transformation"

[edit]

and another edit, your processor is allowed to swap the order of execution of statements ...

Was it helpful?

Solution

No, it will not. But it will always behave as if it did. One of the basic rules in compiler design is the "as if" rule. Your compiler can make whatever changes it likes, as long as the result is going to behave as if you'd followed the language rules.

GOTO 10 may decide to jump to some other location, as long as the compiler can guarantee that it won't change the outcome of the program.

So no, it shouldn't worry you.

OTHER TIPS

Not if you've got

40 COMEFROM 30

somewhere in your code.

alt text

Well, it won't if it doesn't execute, for example if there's a 20 GOTO 40.

In BASIC, yes. In other languages, it will generate a compile error.

What are you trying to say? Anyone claiming to be a programmer should know (especially after your hint) that it depends on what's on lines 10 and 20, and anyone who's been on SO for longer than a week should realize that this question doesn't seem to add much.

We should rely on the code doing exactly what we tell it to. If we tell it to GOTO 10 on line 30, but also tell it to skip line 30, we shouldn't be the least surprise when line 30 is skipped. We told the program to.

True, if you consider multi-core CPUs executing a BASIC program, one of the cores might accidentally miss the GOTO (hint: "TLB Bug") and continue as if it weren't there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top