Sign in to follow this  
Followers 0
FaridAgl

Odd but working syntax

13 posts in this topic

Check the following example:

#cs
    This:
    If (conditon) Then
        (do this...)

    To:
    (condtion) And (do this...)

    Example:
    (True) And MsgBox(0, "", "")
#ce

#cs
    This:
    If (Not condtion) Then
        (do this...)

    To:
    (Not condition) Or (do this...)

    Example:
    (False) Or MsgBox(0, "", "")
#ce

;--------------------------------------------------

;This
If (FileExists(@ScriptFullPath)) Then
    MsgBox(0, "Standard", "Exist")
EndIf

;To
(FileExists(@ScriptFullPath)) And MsgBox(0, "Short", "Exist")

;This
If (Not IsAdmin()) Then
    MsgBox(0, "Standard", "You are not admin")
EndIf

;To
(IsAdmin()) Or MsgBox(0, "Short", "You are not admin")
2 people like this

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This is not odd - this is boolean algebra.  ;)

Have a look here -> http://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Examples

Checkout the return values of each functions and compare it with the boolean table for and ()/ or().

 

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Well, I know about Boolean algebra, I had passed Boolean algebra in Discrete Mathematics in my previous term!

I call it odd because I didn't see anyone using this syntax, however in my opinion it's clear, simple and useful.

Also noticed that this kind of syntax usually got used in PHP.

Edited by D4RKON3

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I allowed it with one of the commits some time ago while I was active in development. It's a side affect which needed later proper evaluation.

edit: Are you asking for some help about it or what?

Edited by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Oops no, just wanted to share it with the community as I never seen anyone do this before.

Now that you are here, do you know anything about any performance issues with this syntax? As I remember, there was a little different in speed of one line If () Then ... and the Standard If () Then ... EndIf statements.

Edit:

 

I allowed it with one of the commits some time ago while I was active in development.

It seems like there is a sign of you everywhere! ;)

Edited by D4RKON3

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

hey, look at that:

$iTimer = TimerInit()
For $i = 0 To 10000000
    If True Then $something=$i
Next
ConsoleWrite(TimerDiff($iTimer) & @CRLF)

$iTimer = TimerInit()
For $i = 0 To 10000000
    If True Then
        $something=$i
    EndIf
Next
ConsoleWrite(TimerDiff($iTimer) & @CRLF)

output:

19146.2078164728
10066.2411395331

That seems to be a significant difference.

Edited by jdelaney
1 person likes this

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Here we go:

Global $something

$iTimer = TimerInit()
For $i = 0 To 10000000
    If True Then $something = $i
Next
ConsoleWrite(TimerDiff($iTimer) & @CRLF)

$iTimer = TimerInit()
For $i = 0 To 10000000
    If True Then
        $something = $i
    EndIf
Next
ConsoleWrite(TimerDiff($iTimer) & @CRLF)

$iTimer = TimerInit()
For $i = 0 To 10000000
    (True) And $something = $i
Next
ConsoleWrite(TimerDiff($iTimer) & @CRLF)
12924.9980183691
7313.35217241744
9594.36602411256
1 person likes this

Share this post


Link to post
Share on other sites

My CPU on this comp is a little low, as you can compare from our results :)


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

That's not the same. The code with funny syntax does different things than other two. That expression is stateless (google for definition if not familiar) as opposed to stateful nature of other two:

Local $something
Local $i = 34

(True) And $something = $i

ConsoleWrite($something & @CRLF)

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

It's not ignored, it's evaluated and the result is False. I told you it's stateless.

Right side means "is $something equal to $i", it doesn't mean "assign $something to value of $i". Get it?


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Yeap, that's clear now.

Thanks.

Edited by D4RKON3
1 person likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0