B4J Question B4J IDE not detecting idiot coding error

JackKirk

Well-Known Member
Licensed User
Longtime User
Here is a real weird one which had me stumped for quite a while in a much more complex piece of code - the complexity hid the real idiot coding error.

I have netted it down to this:
B4X:
'Non-UI application (console / server application)
#Region Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
#End Region

Sub Process_Globals
  
End Sub

Sub AppStart (Args() As String)
  
    Private success_flag As Boolean = True
    Private junk As Long
  
    If success_flag = True Then

        junk = 1 Then
                                                          
    End If
  
End Sub

Spot the idiot error?

If you haven't: it is in the line "junk = 1 Then" - the "Then" should not be there.

But if you look at this under the B4J IDE there is no indication of an error (e.g. I would expect the "Then" to have an underline red squiggle and a red boo-boo message in the log).

If you attempt a Debug compile you get:
B4X:
B4J Version: 9.10
Parsing code.    (0.00s)
    Java Version: 11
Building folders structure.    (0.00s)
Compiling code.    (0.00s)
Compiling layouts code.    (0.00s)
Organizing libraries.    (0.00s)
Compiling generated Java code.    Error
B4J line: 18
junk = 1         Then
src\b4j\example\main.java:70: error: ';' expected
_junk = (long) (1)} };
                  ^
1 error
in the "Compile and Rapid Debug" window - which isn't real helpful.

If you change the "code" to:
B4X:
'Non-UI application (console / server application)
#Region Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
#End Region

Sub Process_Globals
  
End Sub

Sub AppStart (Args() As String)
  
    Private success_flag As Boolean = True
    Private junk As Long
  
    If success_flag = True Then

        junk = 1
       Then
                                                          
    End If
  
End Sub

Then everything works as you would expect and the bug is readily apparent.

As I said at the start my real life code was much more complex - and the complexity hid the error.

Does this rank as an IDE bug?
 

aeric

Expert
Licensed User
Longtime User
Unlike some programming languages, language like Basic handles whitespace differently. When we want to continue to next line, we need to use an underscore. I am actually very comfortable with this approach. Languages like JavaScript or PHP can be “minified” by removing redundant whitespaces. Language like Python respects tab. For me, I always scan through my codes several times after every time I added some new codes. Especially when it involves IF-ELSE, I always make sure the codes are well indented and the keyword stay at the right indentation levels. That’s why I always slow.

eg.
B4X:
If condition = True Then value = 1 Else value = 0
Vs
B4X:
If condition = True Then 
value = 1
Else value = 0 ‘ error
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
Does this rank as an IDE bug?
Yeah, maybe, depending on where you draw the definition lines, I suppose. Or at least a case where the linter could be improved.

Not that it would help. You know what they say: Build something more idiot-proof and the universe builds a better idiot. 😉
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
There is a simple workaround: don't write things so badly wrong 😄
Agree, it was a stupid error but it put me in a "whaaaa" state for some time. It is this sort of stupid that the IDE should catch in my view.

In some ways it is because the B4X IDEs are so good that you get lulled into a sense of security that only gets punctured occasionally by weirdos like this.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Agree, it was a stupid error but it put me in a "whaaaa" state for some time. It is this sort of stupid that the IDE should catch in my view.

In some ways it is because the B4X IDEs are so good that you get lulled into a sense of security that only gets punctured occasionally by weirdos like this.
As I understand it is "simply" an "oversight" of the parser.

I suppose with a little work (I don't know how easy / difficult) Erel will be able to fix it. But let's not forget that the things he has to do are certainly hundreds and despite the fact that he has at least 8 brains and 16 arms 😄 ...!
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Fixed:

1655631884281.png
 
Upvote 0
Top