Just wondering again.....

BlitzMax Forums/BlitzMax Programming/Just wondering again.....

BBUser48(Posted March) [#1]
Is there a way to concatenate a code to make easier to program or not?
Like say glColor3f(blah,blah,blah) and glVertex3f(blah,blah,blah) into one line? What to you suggest?


xlsior(Posted March) [#2]
Use semi-colons top separate multiple commands:

glColor3f(blah,blah,blah) ;  glVertex3f(blah,blah,blah)



Brucey(Posted March) [#3]
I'm not sure how putting multiple statements onto one physical line can makes things clearer/easier to program.

To me, it's just clutter.


skidracer(Posted March) [#4]
Think about it, you only have to write half as many lines of code!


Brucey(Posted March) [#5]
Heh ;-)


TomToad(Posted March) [#6]
Actually, the semicolon is optional
SuperStrict For Local i:Int = 0 To 10 Print i Next



Brucey(Posted March) [#7]
Indeed, that makes the code *much* clearer!


FireballStarfish(Posted March) [#8]
It is most of the time, but not always.
Print
Print
will work and print two empty lines,
Print Print
will give you an error.

Also note that If-statements are really weird and work differently than anything else in the language. If the "Then" keyword (or the condition, in case you omit the "Then") is followed by a statement on the same line, even with a semicolon inbetween, then it is interpreted as a single-line If. And a single-line If can not be terminated by anything other than a line break - anything that follows on the same line is considered part of the Then-"block". Same goes for the Else-"block".
In other words, you cannot do this
If True Then; Print "yes"; End If
and if you do this
If c Then Print "yes" Else Print "no"; Print "!"
then you'll only get the exclamation mark if c was false.

Possible errors aside, putting multiple statements on the same will not usually make your code more clear or readable. Sometimes it does, but these cases (no pun intended) are exceptions; most of the time it'll rather do the opposite.


TomToad(Posted March) [#9]
Yeah, I think semicolons should've been mandatory as it can create ambiguities without them. Notice how the single line version of the code below behaves differently than the three lines.



skidracer(Posted March) [#10]
That ambiguity is what my logical mind likes most about BlitzMax but I am surprised Strict allows unsemicoloned rambling.


BBUser48(Posted March) [#11]
Thanks for the quick replies folks! I will remember that always.