Test-keyword for single-line if-constructs

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
eesau
Enthusiast
Enthusiast
Posts: 589
Joined: Fri Apr 27, 2007 12:38 pm
Location: Finland

Test-keyword for single-line if-constructs

Post 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
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
eesau
Enthusiast
Enthusiast
Posts: 589
Joined: Fri Apr 27, 2007 12:38 pm
Location: Finland

Post 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.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

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

Post by PB »

The suggestions you made are not Basic programming.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
eesau
Enthusiast
Enthusiast
Posts: 589
Joined: Fri Apr 27, 2007 12:38 pm
Location: Finland

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

Post by eesau »

PB wrote:The suggestions you made are not Basic programming.
Why not?
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

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

Post by PB »

Have you seen the majority of Basic languages using your examples?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
eesau
Enthusiast
Enthusiast
Posts: 589
Joined: Fri Apr 27, 2007 12:38 pm
Location: Finland

Post by eesau »

No, but the features of other languages shouldn't be a reason to exclude features from PureBasic.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

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

Post 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?
eesau
Enthusiast
Enthusiast
Posts: 589
Joined: Fri Apr 27, 2007 12:38 pm
Location: Finland

Post by eesau »

The point is readability.

And sexiness 8)
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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!
oh... and have a nice day.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> The point is readability

Maybe for you. I find it totally un-Basic to read. Just use Macros and be done.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post 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
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post 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
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
uwekel
Enthusiast
Enthusiast
Posts: 740
Joined: Sat Dec 03, 2011 5:54 pm
Location: Oldenburg (Germany)

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

Post 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 :-)
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

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

Post 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:
Post Reply