The Power of B4X

I don't know if anyone made statistics regarding how many percent of a language we use.
I remember "upgrading" my Sinclair Spectrum computer to the Atari XE. The hardware was fabulous, but the built-in Atari Basic ruined it for me after the incredibly intelligent Sinclair Basic.
Then came the Atari ST with GFA Basic, which was another very intelligently written language.
Then Delphi, which is also a clean language, but there the programmer started drowning in it. There were endless discussions about the language itself, rather than the tasks it was supposed to make easier.
VB.NET is also friendly, but there again the ocean of a language is more in focus than it should be.
What makes a language, as a tool, good?
It seems to me that in a good language we can achieve the same task as in a worse language, with fewer commands and in a more consistent wording. That is, if you can combine your building blocks in more flexible ways, you don't need so many of them. You use them more often, in more situations.
And this is where Sinclair, GFA and B4X shine. The number of keywords and possible syntactical expressions is "limited", yet we can perform everything that the other languages can, in a simpler way.
B4X's automatic casting, duck typing, the simple List and Map objects can do everything. Simple constants are better than setting up things like:

What we don't need:
  [Flags]

   enum MultiHue : short

   {

      None = 0,

      Black = 1,

      Red = 2,

      Green = 4,

      Blue = 8

   };

Yup, this is how to make a simple definition of five constants dramatic and bombastic without gaining much. Does the above monster make my life really easier? Would I ever miss it from B4X? Not me.
However, a "limited" language can only succeed if its keywords, syntax and solutions are well chosen. This is where science meets art. Nothing can substitute human intelligence, experience and attitude here. Erel is not peppering his creation with useless features that we will never use or use 1% of the time. We don't need to concentrate on the language, but on the job to do with it. And when a new feature finds its way into B4X, it is there to be used often and solve a lot of problems at once. Erel has an enormous talent and just the right attitude to come up with language features sparingly, but in a way that keeps his language attractive, friendly and powerful. This is a unique gift to be admired.

And that is why B4X can be learned by almost anyone, in just a few days(or hours) - and there is nothing it cannot do. I'd rather resort to using JavaObjects on the rare occasion when something extra has to be done than deal with a vast language, 80% of which I will never utilize.

And it makes every B4X program simpler to understand, easier to read(and write) and therefore more pleasant to the eye.

A powerful language like this can shape the programmer's attitude, too. It can keep him on track to concentrate on WHAT he wants to achieve rather than HOW he wants to do it.

That is the power of B4X.
 

LucaMs

Expert
Licensed User
Longtime User
I agree on everything except the single constants.
Being able to group them in a single list (like .Net Enums) allows you to refer to them more easily, by typing the name of the Enum and the dot - as well to "categorize" them, of course.

Surely it's not an indispensable feature; you can (and I do) give the single constants names a prefix suitable for "grouping" them:
B4X:
Public Const CLR_BLACK As...
Public Const CLR_WHITE As...
 

Heuristx

Active Member
Licensed User
Longtime User
I agree on everything except the single constants.
Being able to group them in a single list (like .Net Enums) allows you to refer to them more easily, by typing the name of the Enum and the dot - as well to "categorize" them, of course.

Surely it's not an indispensable feature; you can (and I do) give the single constants names a prefix suitable for "grouping" them:
B4X:
Public Const CLR_BLACK As...
Public Const CLR_WHITE As...

The thing is, everyone will miss something, and if the language added all of those, it would become a mess.

I was using Enum heavily myself. Here you can group them by putting them in a static code module, so they will be like enumerations:
Db.TransactionStarted

and so on. But the example I gave was an enum "decorated" with [Flags]. So you can combine them. Which you could simply do with constants by Bit.Or(...) and test them with If Bit.And(v1, v2) > 0. Or, as of now, Return IIf(Bit.And(Flags, AConstant) > 0, Value1, Value2)!

And I like this simplicity better and better. I guess if we did this in VB.NET, people would start criticizing us like "it's not the professional way! Why didn't you define an Enum with Flags?" As if "professional" meant that you always have to define some very specific construct instead of just doing the job.
 

LucaMs

Expert
Licensed User
Longtime User
The thing is, everyone will miss something, and if the language added all of those, it would become a mess.

I was using Enum heavily myself. Here you can group them by putting them in a static code module, so they will be like enumerations:
Db.TransactionStarted

and so on. But the example I gave was an enum "decorated" with [Flags]. So you can combine them. Which you could simply do with constants by Bit.Or(...) and test them with If Bit.And(v1, v2) > 0. Or, as of now, Return IIf(Bit.And(Flags, AConstant) > 0, Value1, Value2)!

And I like this simplicity better and better. I guess if we did this in VB.NET, people would start criticizing us like "it's not the professional way! Why didn't you define an Enum with Flags?" As if "professional" meant that you always have to define some very specific construct instead of just doing the job.
Using a code module that "acts as Enum" is a great idea, I hadn't thought about it.
 

Heuristx

Active Member
Licensed User
Longtime User
This language gives us a lot of solutions to small problems.
I myself miss inline initialization like Private AList As List = List.Initialize.
But I must admit that I can survive quite well without it.
 

William Lancee

Well-Known Member
Licensed User
Longtime User
I have been using "inline" initialization for B4X lists, maps, and stringbuilders for years. I don't use the following construct for anything else, but...

Code:
Dim sb as stringbuilder: sb.Initialize

Dim aList as list: aList.Initialize

Dim aMap as Map: aMap.Initialize

It works and I do like it.
 

William Lancee

Well-Known Member
Licensed User
Longtime User
Be aware there is no intellisense or autocomplete when using the multiline code ":". However that doesn't affect me much, and I only use it for these three constructs.
 

Heuristx

Active Member
Licensed User
Longtime User
Well, sure, I used that in very old Basic dialects, but I didn't know that it existed in B4X. Is there a GoTo, too? :p
 

LucaMs

Expert
Licensed User
Longtime User
Is there a GoTo, too? :p
spaghetti-al-pomodoro-768x512.jpg


P.S. "Ammazza, che fame!"
 

William Lancee

Well-Known Member
Licensed User
Longtime User
Thankfully, NO. But a very useful related tool is calling Subs by their string name, CallSub(Me,"thisOne") I use it to delegate various operations, instead of a Select construct.
 

Heuristx

Active Member
Licensed User
Longtime User
In GFA Basic Frank Ostrowski added the GoTo statement(together with a Label: x statement because of course there were no line numbers), and then wrote a very lengthy article about how people should avoid it at any cost.

I use the CallSub for custom sorting lists. It seems slow, though, in a big list. Maybe just because of the debugger.
What's wrong with spaghetti? Anyway, you can write spaghetti code without GoTo, I've seen many. And the comments were in macaroni language!
 

Heuristx

Active Member
Licensed User
Longtime User
I had to look it up.
life←{↑1 ⍵∨.∧3 4=+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂⍵}
I think ufg uywefgiwi!
 

LucaMs

Expert
Licensed User
Longtime User
I use the CallSub for custom sorting lists. It seems slow, though, in a big list. Maybe just because of the debugger.
Do you need custom sorting list? Why? Use lst.SortType.

What's wrong with spaghetti? Anyway, you can write spaghetti code without GoTo, I've seen many. And the comments were in macaroni language!
WRONG!!! These are "maccheroni":
maccheroni.jpg
:
 

Heuristx

Active Member
Licensed User
Longtime User
But what if it's a class, not a type?
What if it has to call a function to get a value?

This pasta is good for programming, we can follow every piece to the end. Macaroni language is when the commenst are in mixed languages.
 
Top