Page 1 of 2

Test-keyword for single-line if-constructs

Posted: Wed Mar 04, 2009 12:27 pm
by eesau
My code is riddled with small if-constructs like this:

Code: Select all

If SomeVariable
  CallSomeProcedure()
Else
  CallOtherProcedure()
EndIf
To shorten the source code and to make it more readable, I suggest we have Test (or IIf?), True and False -keywords, so that the above code would shorten to this:

Test SomeVariable True CallSomeProcedure() False CallOtherProcedure()

We could even evaluate just True or False like this:

Test ResultFromSomeProcedure() False Result=#False
Test BreakFlag True Break

Posted: Wed Mar 04, 2009 12:33 pm
by ts-soft

Posted: Wed Mar 04, 2009 12:40 pm
by eesau
ts-soft wrote:you can use macros for this
I know, but they get messy, and need both truepart and falsepart. And parenthesis. I'd rather have a native solution.

Re: Test-keyword for single-line if-constructs

Posted: Wed Mar 04, 2009 12:48 pm
by PB
The suggestions you made are not Basic programming.

Re: Test-keyword for single-line if-constructs

Posted: Wed Mar 04, 2009 12:50 pm
by eesau
PB wrote:The suggestions you made are not Basic programming.
Why not?

Re: Test-keyword for single-line if-constructs

Posted: Wed Mar 04, 2009 1:02 pm
by PB
Have you seen the majority of Basic languages using your examples?

Posted: Wed Mar 04, 2009 1:09 pm
by eesau
No, but the features of other languages shouldn't be a reason to exclude features from PureBasic.

Re: Test-keyword for single-line if-constructs

Posted: Wed Mar 04, 2009 3:39 pm
by Trond
eesau wrote:Test SomeVariable True CallSomeProcedure() False CallOtherProcedure()
If SomeVariable : CallSomeProcedure() : Else : CallOtherProcedure() : EndIf
You'd save only two characters by doing it your way. What's the point?

Posted: Wed Mar 04, 2009 3:44 pm
by eesau
The point is readability.

And sexiness 8)

Posted: Wed Mar 04, 2009 4:30 pm
by Kaeru Gaman
readability:
I find "Test X True Y False Z" rather confusing in an BASIC environment.
... what is it, Perl or Lisp?

sexiness:
there are people out there (including me) who would prefer Aretha Franklin before Paris Hilton!

Posted: Thu Mar 05, 2009 9:21 am
by PB
> The point is readability

Maybe for you. I find it totally un-Basic to read. Just use Macros and be done.

Posted: Thu Mar 05, 2009 8:12 pm
by fsw
Maybe you mean something like:

IFF

The IFF Statement starts an IF FALSE test in an IF ... ENDIF block .

IFT

The IFT Statement starts an IF TRUE test in an IF ... ENDIF block .

IFZ

The IFZ Statement starts an IF ZERO test in an IF ... ENDIF block .

XBasic and XBlite have it for ages... how un-basic is that?
(btw XBasic is way older than PureBasic...)

Thinking of it, I mentioned it long time ago, but as usual nobody listen to me anyhow... :P

Here it is:
http://www.purebasic.fr/english/viewtop ... 20&start=0

Posted: Thu Mar 05, 2009 11:03 pm
by blueznl
Horrible idea, but feel free to put it in your own macros :-)

I'll stick to the cumbersome approach...

Code: Select all

If a = 1
  < do something >
Else
  < do something else >
Endif
Or...

Code: Select all

< do something else >
If a = 1 
  < do something >
Endif

Re: Test-keyword for single-line if-constructs

Posted: Tue Mar 03, 2015 8:05 pm
by uwekel
I could imagine, for a one-liner, to use the Then keyword like this:

Code: Select all

If a=1 Then b=3 Else c=5
And it is Basic-like :-)

Re: Test-keyword for single-line if-constructs

Posted: Wed Mar 04, 2015 11:43 am
by Dude
uwekel wrote:

Code: Select all

If a=1 Then b=3 Else c=5
But the above can already be done like this:

Code: Select all

If a=1:b=3:Else:c=5:EndIf
With just one single character difference in typing length. :twisted: