The new Editor

Jeremy Leach

Senior Member
I've been thinking about the new editor code and how it works.

Does we need to use chips with updated firmware to run?

If not then are we saying that the encancements to the Picaxe BASIC language make no difference to the underlying tokenisation of the code? So high-level structures like 'Select Case' are translated to lower-level'If then' type language before being tokenised and downloaded to the Picaxe?

Just trying to understand.
 

hippy

Ex-Staff (retired)
That's right, the new commands translate down to existing IF-THEN and GOTO constructs, so all new commands work with all PICAXE variants no matter what their Firmware version.
 

Jeremy Leach

Senior Member
Ah ..so that's why you made the comments you did in Beaniebot's aquarium controller thread the other day.

So in terms of optimisation there's little (if anything) to be gained by using the new structures.
 

hippy

Ex-Staff (retired)
I think it depends on how you look at that question.

For most users there is potential for auto-optimised improvement, because the new commands avoid some unoptimised constructs which may otherwise get created, such as the commonly seen ...

- WaitForPinHigh:
- IF pin0 = 1 THEN GotPinHigh
- GOTO WaitForPinHigh
- GotPinHigh:

The ...

- DO
- ' Nothing
- LOOP UNTIL Pin0 = 1

gives the best optimised solution without any effort of ...

- WaitForPinHigh:
- IF pin0 <> 1 THEN WaitForPinHigh

The IF-THEN-ELSE-ENDIF construct can also handle inverting conditionals for optimising which could otherwise be a little difficult to fathom ...

- IF pin0 = 0 AND pin1 = 1 THEN
- ' Do this
- END IF

To be optimised well without extraneous GOTO's has to become ...

- IF pin0 = 1 OR pin1 = 0 THEN SkipThis
- ' Do this
- SkipThis:

For those who don't optimise or don't have the experience to do it, the new block structures offer benefits.

In some cases though, helping a programmer express themselves with clarity in the high level may run counter to producing compact code. The ON-GOSUB statement is a particular case in point, and SELECT-CASE isn't as optimised as a long sequence of IF-THEN's could be. That's also been the case in the past, such as CALIBFREQ with a negative number.

The one benefit everyone gets from the enhanced compiler is better optimisation of 'LET var=number' and 'LET var=var' assignments which occur fairly frequently in most code. This makes the ( visually horrible and limited ) trick of using a FOR without a NEXT as a shorter assignment than LET redundant.

The bottom line is, in my opinion, that, for those skilled at optimising and needing optimisation, the new block structured commands offer nothing beyond more clarity and speed in writing code with a need to keep watch on the code in case it un-optimises.

In that case ( which is what I your question asks ); it's probably better to write hand-optimised code using old constructs, then convert to block structured for readability if it doesn't impact, but even then, it may be worth paying a small price if nested IF's make code so much easier to write and understand.

For most cases though, using the new structures won't have a negative impact on code size, may give some optimisations for zero effort, and the benefits in clarity and ease of coding should outweigh any counter-optimisation effects.
 

Jeremy Leach

Senior Member
Thanks Hippy for spelling it out ;-)

Don't get me wrong - I think the new language features are fantastic. I'm a keen advocate of code-clarity and ease of use so they really help.
 

BeanieBots

Moderator
What I can confirm, is that simply putting the old code into the new editor did give quite a few bytes back without making any changes at all.
By the way guys, thanks to your helpful tips, I managed to get an extra three menus implemented without resorting to any hardware changes. I intend to start again from scratch with an X2 device and will use external I2C to implement a menu command type language, a little bit along the lines of the tread "self-hosted development platform" but at a lower more simplistic level.
 
Top