3 line parsing bug

BlitzMax Forums/BlitzMax Programming/3 line parsing bug

Najdorf(Posted 2008) [#1]
b=1
 If (1>2) Then a=1 ;b=2;
Print b


returns 1 while it should return 2. Tested on blitzmax 1.28 on windows and mac.

Apparently the problem lies in separating with ";" after conditional statements.


Floyd(Posted 2008) [#2]
b=1
 If (1<2) Then a=1 ;b=2;
Print b



SebHoll(Posted 2008) [#3]
I don't really see this as a bug, more of an extremely useful feature - I use it all the time (although I agree it can be counter intuitive at first).

Any statements after an If on a line, will be executed if the condition is true. It saves having to type code blocks if you only want to conditionally execute a few simple statements. You wouldn't believe how much neater this makes code... ;-)


Brucey(Posted 2008) [#4]
Yuck!

Neater? I don't think so.
If you prefer "neatness" to the detriment of readability, then fair enough.


SebHoll(Posted 2008) [#5]
Neater? I don't think so.
If you prefer "neatness" to the detriment of readability, then fair enough.

You're quite right - readability and neatness are two different things... You can make a room neat by hiding stuff away in drawers and cupboards, but it doesn't mean that you are making it accessible/readable.

Yes, some would say that it's harder to see straight away what is executed from an If statement - but if you want to do that, you are free to use an If/EndIf block. Also, you could argue that...

If (1<2) Then a=1 ;b=2;
...isn't very readable either. Unless you're a die-hard C Programmer!

I've got to admit however, in C programming, it looks tidy with only one statement. However, it's such a pain when, say for example, you needed to add a DebugStop/Print statement to debug some code - you have to start moving chunks of code around and adding EndIfs. With BlitzMax's current behaviour, just tack a new statement before or after on the same line and be done with it. It can be just as easily removed as it can be added and it's usually these one liner If statements that increment/decrement values and so may be quite frequently debugged.

That's my argument anyway (and the fact that most of my existing code will no longer work if this is changed ;-))...


TomToad(Posted 2008) [#6]
Not a bug. The docs themselves say that BMax uses classic one-line style if statements. Every variant of basic I've used will skip the entire line if the expression is false.

I guess it could be a little confusing if you've never used older variants of BASIC before. The docs could be a little clearer on that.


JazzieB(Posted 2008) [#7]
As TomToad says, it is not a bug. You're using the one line version of the If statement. I'm guessing that you're trying to use some shortened version of the If..Then..Else clause, so your code should be...

b=1
 If (1>2) Then a=1 Else b=2
Print b

Also, it may be worth pointing out that although you can miss the Then keyword out, you cannot miss out the Else keyword, whether it be the single or multiple line version of this clause.