BBC BASIC
« Re: The better string editor function (Tool) »

Welcome Guest. Please Login or Register.
Jan 20th, 2018, 6:02pm


Cross-platform BBC BASIC (Win32, Linux x86, Android, Mac OS-X, Raspberry Pi)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Re: The better string editor function (Tool)  (Read 371 times)
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 689
xx Re: The better string editor function (Tool)
« Thread started on: Apr 4th, 2016, 11:30am »

on Apr 4th, 2016, 08:54am, michael gallup wrote:
FN_editstr(message$,location,string$)

I'm puzzled by the conditions used at the start of these statements:

Code:
      IF whatstring$="" THEN .....
      IF LEN(whatstring$)>0 THEN .....
      IF LEN(whatstring$)>0 THEN .....
      IF whatstring$="" THEN ..... 

Why is the test for the string being empty made directly, but the test for the string not being empty done by looking at its length? This seems to be designed to confuse!

Surely the method used for the tests should be consistent, so either:

Code:
      IF whatstring$="" THEN .....
      IF whatstring$<>"" THEN .....
      IF whatstring$<>"" THEN .....
      IF whatstring$="" THEN ..... 

or:

Code:
      IF LEN(whatstring$)=0 THEN .....
      IF LEN(whatstring$)>0 THEN .....
      IF LEN(whatstring$)>0 THEN .....
      IF LEN(whatstring$)=0 THEN ..... 

Of course this all begs the question of why multiple tests are being performed in the first place. Superficially it would seem much easier (and certainly faster) to do the test just once:

Code:
      IF whatstring$="" THEN
        rightword$=RIGHT$(stringtomodify$,rightlength%)
        finalword$=leftword$+rightword$
      ELSE
        rightword$=RIGHT$(stringtomodify$,rightlength%+1)
        finalword$=leftword$+whatstring$+rightword$
      ENDIF 

And then it becomes apparent that the two finalword$ calculations are exactly the same (so could be taken outside the IF clause)!

My view is that a routine offered as being a 'tool' (for example with the intention of it possibly being included in a library) ought to be carefully designed. Shared code deserves more attention than just being cobbled together.

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Donate $6.99 for 50,000 Ad-Free Pageviews!


This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls