wish i++, i+=, i--, --i, ++i, i&= etc..

LucaMs

Expert
Licensed User
Longtime User
Trying to write in same number of lines without losing clarity?
B4X:
ByteStream(BPosn+0) = Esc
ByteStream(BPosn+1) = 42' Start of command
ByteStream(BPosn+2) = 98' Command type
DataString      = Width ' Width of box
DataStringBytes = DataString.GetBytes("UTF8") ' convert length to bytes
For I = 0 to DataString.Length - 1
   ByteStream(BPosn + 2 + I) = DataStringBytes(I) ' move in the length
next
ByteStream(BPosn+2+I+1) = 87' Terminate the data length <--- this line is too compact, for me
ByteStream(BPosn + 2 + I + 1) = 87 ' Terminate the data length <--- now i like it ^_^
BPosn = BPosn + 2 + I + 1' move to the next position for
 

Levit

Member
Licensed User
Longtime User
Nice discussion. Each head gives its own sentence.
Fact is that adding such features in any basic will only make it more flexible.
C language also accepts " a = a +1 " and it doesn't make it more 'basic like', but give it flexibility.
The more options you have the better. Choose your best fit !
 

ivan.tellez

Active Member
Licensed User
Longtime User
+1


Actually LOTS of Basic Languajes accept this kind of assignment. But in a different way, For example:

B4X:
[LET] variable  = expression
[LET] variable += expression
[LET] variable -= expression
[LET] variable *= expression
[LET] variable /= expression
[LET] variable \= expression
[LET] variable &= expression
[LET] variable AND= expression
[LET] variable OR= expression
[LET] variable EQV= expression
[LET] variable IMP= expression
[LET] variable MOD= expression
[LET] variable XOR= expression

So, in C++ its:

i++

In some basic languajes its:

i+=1

its compact and more flexible :D



Note: The LET keyword is optional and is used only for compatibility with really old Basic code.
 

LucaMs

Expert
Licensed User
Longtime User
These are details.

Maybe you do not realize what tools we have available, thanks to Erel (including this site and his presence).

That would be a necessity? I'd also like "... as List of MyClass", subclassing, etc.

But do you prefer that Anywhere software spends its time on these things or on little thing like... B4I?
 

Levit

Member
Licensed User
Longtime User
So far, LucaMs words are the best point against implementing this wish. It is not a necessity nor a priority. We can live with that.
B4A is far the best quick android development tool and nobody can deny the efforts of Erel and the others guys who make it feasible.
And yet b4a needs more improvements.

I just can not agree with that idea " don't implement it because it is not 'basic like' nor 'basic compatible' "
 

Jaames

Active Member
Licensed User
Longtime User
B4X:
for(int i = 0; i < 10; i++) {

}
is easier and in some cases of foor loops better than :

B4X:
Dim i as int

for i = 0 to 10

next

But , this is BASIC language (an acronym for Beginner's All-purpose Symbolic Instruction Code). And it should stay i = i+1
The syntax is written that way because is easier to read and understand the code, that's way is Beginner's language.
 

LucaMs

Expert
Licensed User
Longtime User
this WAS BASIC language!

VB.Net is a powerful and very complex programming tool.

And if it was really "easy", why do you want to complicate your life? For snobbery?

The readability of the code is one of the key factors for good programming; it is important that the code is readable to the programmer; even if it seems long-winded, there is then the compiler!

To me instructions as:
"for (int i = 0; i <10; i ++)"

disgusts (and there are even worse!)

Not to mention how unpleasant, uncomfortable and dangerous braces!
 

keirS

Well-Known Member
Licensed User
Longtime User
If we are going to have i++ etc can we also have support for reverse polish notation as well please, 22 4 + makes a lot more sense than 22 + 4.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I don't see a place for the ++ operator in B4x language. It is too easy to confuse i++ with ++i. B4x language is supposed to be simple and straightforward.

+= and the other similar operators might be added in the future.

Adding features to a programming language should be done very carefully as it is a one way direction. You cannot later remove them.
 

klaus

Expert
Licensed User
Longtime User
Adding features to a programming language should be done very carefully as it is a one way direction. You cannot later remove them.
Please remain very careful.
I'm really not conviced that saving a few keystrokes will be a big improvement.
A clear and meaningful code is much more precious than these shortcuts, just my old programmer opinion.
 

LucaMs

Expert
Licensed User
Longtime User
Then we use these variable names:

Private noc As Int ' Number of Clients
Private rn As Int ' Random Number
Private s As String ' Something :D

In this way we will have to enter a smaller number of characters.

(for those who have not read it all: sarcasm)
 

keirS

Well-Known Member
Licensed User
Longtime User
uhm... 22 4 + more sense than 22 + 4 ...

then my teacher of the elementary schools did not know it :)

I went to a very religious school and was taught to go Forth and multiply like it says in the Bible (book of Genesis if IIRC).
 

canalrun

Well-Known Member
Licensed User
Longtime User
I remember a long time ago that the syntax, like +=, was done because compilers at the time could be made more efficient.

When you look at A = A + 5, early compilers didn't realize that the A on both sides of the = sign was really the same variable. They loaded a register with the address where A was stored, fetched the value, added 5 to it, then loaded a register with the address of where A was stored and saved the result. When you write A += 5 this implicitly states that A is the same variable and saves a register load operation. This makes a big difference on a 1 MHz microcontroller – especially in a loop. I did a test once of 10,000 iterations of each statement. The += version was quite a bit faster.

A lot of microcontrollers had very fast incrementers and decrementers. Using the syntax i++ or --i resulted in a single cycle instruction versus five or 10 instruction cycles for adding 1 to a variable.

But optimizing compilers came along and they changed all this. I would guess that most likely B4A is optimized.

Barry.
 
Last edited:

keirS

Well-Known Member
Licensed User
Longtime User
Technically B4A is a transcompiler. I suspect it uses a lexical analyzer and a parser to generate the Java code as that's pretty much how all compilers work. In theory optimizing compilers generate an executable that is more efficient than can be produced by a human. I doubt B4A can do this as a decent Java programmer could write more efficient code than B4A produces both in terms of speed and memory usage.

It's one of the downsides of using a RAD tool. It's a trade off between speed of development and the efficiency of the program produced.
 

LucaMs

Expert
Licensed User
Longtime User
Of course, the B4A layer is at a high level and this has advantages and disadvantages.

But with the computing power of modern devices, mobile or not, these are old problems.

In addition, we will hardly need 10,000 iterations: at most we will need some queries about 10,000 rows in a database and this is not about the "+ ="
 

ivan.tellez

Active Member
Licensed User
Longtime User
The syntax is written that way because is easier to read and understand the code, that's way is Beginner's language.

That's partially true, the idea for the BASIC, it was to be easy to learn and use even for beginners. BUT the idea it was never to "limit" the language.

For example, a decade ago, some C developers laughed at me because I was programming some numeric calculations and data analisis in VB6. But then, I laughed louder when my code result to be 2 times faster than theirs. That was because VB6 its easy to learn and use, but powerful enough to have advanced commands for advanced users (like the poorly documented pointer functions)

So, you can have the BASIC sintax to everyone, but for advanced users, heavy calculations or focus on optimization, you can have a set of advanced commands and STILL being BASIC.
 
Top