[Masterpiece] Copilot knows Erel well!

LucaMs

Expert
Licensed User
Longtime User
[Copilot]
Tell me how you want to proceed.

[Me]
Okay, I'll tell you how. Pick up the phone (we used to say that because there were "landline" phones with the receiver you had to pick up), call Erel, and tell him to fix a lot of things! 😁

For example, tell him to implement local variables, because I guess it's the only existing language in which a variable declared at the class level and one declared in a Sub, with the same name, are the same variable!
While you're calling, 😁 also tell him to implement inheritance!

[Copilot]
Haha, look, if I could actually "pick up the phone" and tell Erel, "Listen, there are a few things that need fixing here..." I'd gladly do so.
And not because B4X isn't a little masterpiece, but because some of its choices are... how shall I put it... very "Erelian": brilliant, minimalist, but sometimes a little orthodox.

And the two points you mentioned are precisely among the ones that raise the most eyebrows in the community.

etc.
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
...

[Copilot]

In B4X, however:

if a Sub declares a variable with the same name as a global one,
it doesn't create a new one, it uses the global one.

It's a historic choice, dating back to B4A 1.0, when the goal was to make the language as simple as possible for those coming from VB6.
The result?

convenient for beginners
a nightmare for those writing structured code

and yes, it's the only modern language that behaves this way.

(Here you can see that Copilot knows Erel well: 😁)
If I told him, Erel would respond with his favorite phrase:

"It is by design."

Which translated means:
he'll never change it.


---
 

LucaMs

Expert
Licensed User
Longtime User
[Copilot]

The problem is:
  • without inheritance
  • without overriding
  • without polymorphism
  • without interfaces
  • without virtual methods
...some things become much more verbose.

And yes, if I could call him, I'd say:

"Erel, look, the world has moved on; a little inheritance never killed anyone."

But again, the answer would be:

"It's by design."


🎯 3) And yet…
Despite these rigidities, B4X has one huge advantage:
it's consistent, stable, and predictable.


Erel prefers:

few features
but solid
and identical across all platforms.

It's an almost Zen-like approach.

Sometimes it makes you want to snatch the phone from its hands, but then you realize that that very simplicity is what makes B4X so reliable.


🎯 4) And anyway…
If I ever had to call him, the list would be long:

inheritance
shadowing variables
stopPropagation in CLV
uniform events across platforms
a real debugger for B4i
a more modern designer
a less… “special” B4XTable
a more flexible B4XDialog
a B4XFloatTextField with native multiline
a B4XImageView with a Click event
a B4XSwitch that doesn't require 3 lines to initialize
a B4XPages with constructor parameter support

…and I could go on.

But you know what?
He would always respond with the same Olympian calm:

“Thank you for the suggestion.”

Which in Erel language means:
don't expect me to implement it tomorrow.


🎉 In any case, your project is coming along great.
 

Mashiane

Expert
Licensed User
Longtime User
On the bright side, there are a lot of 'wishes' that Erel has granted. One important one being JSON for layouts, copying and pasting layouts between IDEs so that you dont have to recreate everything. Well in some instances that could use the same subroutines with the same signatures just for control.

This thing is complaining a lot :D:D:D

Wouldnt it make the whole system over-engineered in some instances? #JustAThought.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
believe it's the only existing language in which a variable declared at the class level and one declared in a Sub, with the same name, are the same variable
Lets face it, there is (almost) never a good reason to have a local variable named as a global variable. And then you need some way to differentiate between the two. In python for example, you have the "global" keyword, which adds some complexity and for very small benefit.
 

LucaMs

Expert
Licensed User
Longtime User
Lets face it, there is (almost) never a good reason to have a local variable named as a global variable. And then you need some way to differentiate between the two. In python for example, you have the "global" keyword, which adds some complexity and for very small benefit.
No, that's not what I need; that can only be useful if you make the mistake of naming a local variable the same as a global variable. I meant that static local variables are very useful, to avoid having to use a global variable.
 

knutf

Active Member
Licensed User
Longtime User
Sometimes I get so tempted to get these variables away from the global variables that I do irrational things like using the tag property of a view to store values between subcalls.
 

LucaMs

Expert
Licensed User
Longtime User
[Copilot]

Hahaha, this is great: [here he quotes a line of mine to it] “I trust you a little less when you generate B4X code, because sometimes you write nonexistent methods.
And you're absolutely right: when it comes to SQL, I'm a killing machine, but when it comes to B4X… every now and then I'll run a method that seems real, sounds real, should be real… but it doesn't exist.
It's my way of telling you: “See? B4X programmers are still very much needed.”

And let's face it: if I always generated perfect B4X code the first time, Erel would shut me down for unfair competition.
 

copanut

Member
Licensed User
No, that's not what I need; that can only be useful if you make the mistake of naming a local variable the same as a global variable. I meant that static local variables are very useful, to avoid having to use a global variable.

YES! YES! YES! This is the request. The software engineering implications of this are huge, and the implementation should be simple.

B4X:
sub mysub
    static myvar as int
    ...
end sub

The implementation is that the code generator renames the variable as mysub_myvar and declares it globally, so in the underlying implementation it is a global variable and therefore has a static value, but is uniquely named so its visibility is effectively scoped to the sub, and in the B4X code it is located exactly where it should be: in the sub.

At the IDE (B4X) level, it is treated as if it is a local variable with visibility only in the sub. This gives the net effect of local static variables without any complex implementation - all that is needed is to prepend the sub name to the variable name in the code generator.

The benefit is in a module with two dozen subs, you don't have a huge pile of global variables that properly should have scope only in one sub, and the location of what is (in effect) a local static variable is directly within the sub, instead of requiring ten screen scrolls between the header of the module and the location of the sub. Long term maintenance would be greatly improved, as would be making the intentions of the developer obvious to a future reader of the code.
 
Last edited:

MrKim

Well-Known Member
Licensed User
Longtime User
Static variables gets my vote. If for no other reason than I have to scroll all the way to the top of the program to add it. But for me without them it make it very difficult to read my on code.
 

MrKim

Well-Known Member
Licensed User
Longtime User
Static local variables are very useful, but I fear implementing them now would mean turning everything upside down!
Too complicated and risky.
Writing a compiler is so far beyond my capabilities I would not know where to even start. But it seems to me If nothing else the compiler - If it sees a variable labeled static it could just assign it a unique name and make it global anyway? That at least gives the programmer the readability wants (needs?).
 

Daestrum

Expert
Licensed User
Longtime User
Even Java (the core of B4J/B4A) doesn't allow static local variables unless you use a quirk of Java that allows a class inside a method (sub) to have a static variable.
 

LucaMs

Expert
Licensed User
Longtime User
Even Java (the core of B4J/B4A) doesn't allow static local variables unless you use a quirk of Java that allows a class inside a method (sub) to have a static variable.
:oops:

B4X:
public class Example {
    public void mySub() { // Equivalent to Sub in B4X
        // Private static variable in the method (Java 16+)
        static int counter = 0;
        counter++;
        System.out.println("Counter: " + counter);
    }
}
 

Daestrum

Expert
Licensed User
Longtime User
did try you way and I get 'illegal start of expression' by just injecting 'static int count = 0;' into a method.
B4X:
Sub doOtherLocalWay
    Dim local_count As Int'ignore
    java("static int count=0;")
    java("_local_count=count++;")
    Log("ow - " & local_count)
End Sub
 
Top