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

Eduard

Active Member
Licensed User
Longtime User
I would really like to be able to use

B4X:
variable_name++
instead of having to use:
B4X:
variable_name = variable_name + 1
It just easier to read, shorter code, less bugs.
 

pleskina

Member
Licensed User
Longtime User
But is this not BASIC for Android? It is reasonable that syntax stays basic-compatible... :)
 

Eduard

Active Member
Licensed User
Longtime User
There are other BASIC variants that support unary operators such as i++, ==i as well. I used to program in KCML, which is BASIC, but has this build in.

Supporting this only makes it easier, since i = i+1 would also still work. It's extra.
 

Eduard

Active Member
Licensed User
Longtime User
I completely disagree with that. To my eyes, these shortcuts never made the code easier to read. It's exactly the contrary. Ask to a beginner what's the difference between --i and i--. It's not obvious or intuitive. I'm tired to see that in C and Java codes.

Different persons different opinions. You can always decide not to use it.:sign0089:
 

mc73

Well-Known Member
Licensed User
Longtime User
Oh well,
B4X:
a=a+1
and
B4X:
a++
differ in just 2 chars, while I tend to agree with Ιnformatix :)
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Difference in two characters? Maybe in that poor example.

What about when you are needing to fill an index

B4X:
Entry[Posn++] = Value
Entry[Posn++] = Value2
Entry[Posn++] = Value3
Entry[Posn++] = Value4

Becomes this pain in a butt

B4X:
Entry[Posn] = Value
Posn = Posn + 1
Entry[Posn] = Value2
Posn = Posn + 1
Entry[Posn] = Value3
Posn = Posn + 1
Entry[Posn] = Value4
Posn = Posn + 1

The second makes the code SO sloppie

++, --, +=, -= ALL these are really needed to make coding quicker and easier. I am forever having to remember to manually do the X=X+1 for filling entries in an array this cannot be done nicely using a loop

Normally I would not complain so much about this. But right now I am trying to draw rectangles and things on a printer using Bluetooth and I have to set all the individual bytes to things like ESC * b 12 W [hex values] and then right the bytes to the OutputStream. Being able to set the Bytes by doing
B4X:
ByteStream(BPosn++) = Esc
ByteStream(BPosn++) = 42 ' Start of command
ByteStream(BPosn++) = 98 ' Command type

DataString = Width ' Width of box
DataStringBytes = DataString.GetBytes("UTF8")  ' convert length to bytes

For I = 0 to DataString.Length - 1
      ByteStream(I + BPosn) = DataStringBytes(I) ' move in the length
next

BPosn += I  ' move to the next position for 

ByteStream(BPosn++) = 87 ' Terminate the data length

'-------------------------------------------------------------
' Now put in the data we want to draw
'-------------------------------------------------------------
 
Last edited:

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I completely disagree with that. To my eyes, these shortcuts never made the code easier to read. It's exactly the contrary. Ask to a beginner what's the difference between --i and i--. It's not obvious or intuitive. I'm tired to see that in C and Java codes.

I also disagree with Informatix on this. "Ask a beginner" so we should write code to handle the LOWEST person on the pole? You say it is NOT obvious or intuitive, well then they need to read the manual or take a real coding course. I am sure your eyes see and translate the code without a thought.
 

LucaMs

Expert
Licensed User
Longtime User
VB6 had not some ++, but VB.Net has += *= ...

Since it is recommended to use self-explanatory variable names and their length is not relevant to the overall weight of the application, write:

varASDGOIUASDOIUSGWK varASDGOIUASDOIUSGWK +1 =

is less practical:

varASDGOIUASDOIUSGWK + = 1

The fact remains that it is not a fatal issue!
 

Informatix

Expert
Licensed User
Longtime User
Difference in two characters? Maybe in that poor example.

What about when you are needing to fill an index

B4X:
Entry[Posn++] = Value
Entry[Posn++] = Value2
Entry[Posn++] = Value3
Entry[Posn++] = Value4

Becomes this pain in a butt

B4X:
Entry[Posn] = Value
Posn = Posn + 1
Entry[Posn] = Value2
Posn = Posn + 1
Entry[Posn] = Value3
Posn = Posn + 1
Entry[Posn] = Value4
Posn = Posn + 1

The second makes the code SO sloppie
It's a cumbersome way to fill an array. You should do instead (and that does not require to compute each index):
Dim Entry(20) As String = Array As String("Value1", "Value2", "Value3", etc.)
 

Informatix

Expert
Licensed User
Longtime User
I also disagree with Informatix on this. "Ask a beginner" so we should write code to handle the LOWEST person on the pole? You say it is NOT obvious or intuitive, well then they need to read the manual or take a real coding course. I am sure your eyes see and translate the code without a thought.
I don't think you really understood what I said, but it doesn't matter: I am not opposed to adding these operators to B4A.
For a few years, my job was to rewrite code made by others. Without a detailed documentation, it was usually a nightmare with some languages (especially C and C++. It seemed to me that every C programmer was trying to win a contest of the most compact application in the world. ;)) With this little experience, I made my opinion about some operators (++, -- *=, etc.). They can be convenient sometimes and we are so used to see i++ in a loop that another form would be surprising. BUT I don't think they are easier to read and IMHO they should be avoided. If you write only code for your eyes, I really don't care of what you use, of course.
When I mentioned beginners, I wanted to be nice. In fact, ask to many programmers the value of j and k in:
B4X:
int i = 2;
int j = 1;
int k = 3;
j *= i++;
k *= ++i;
and I'm quite sure they will need some time to give me the correct values.
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I somewhat agree that some coders can go overboard.

But even without these commands I would be willing to bet they will find a way. And I guess I am an offender a lot, because I love doing

On = TimeForOn >= OnTime ? True : False

I love the one line if statement command ? :

But the basic ++ -- makes a lot less typing I++ instead of I = I + 1 not only makes me feel dumb, but opens my code up to type-o errors (I'm 63 and my fingers can no longer keep up)

I believe what makes code easier to read is alignment and layout more than anything. One of the reasons I asked for an IDE option to replace tabs with spaces. So my code always looks the same no matter what editor I am using. I like this old animal called KEdit (came from the IBM mainframe world) and there are things I can do quicker in it that I cannot even do in other editors.

If my wife only used the subset of English that I do, she would have never raised to a EVP in the corp world.
 

LucaMs

Expert
Licensed User
Longtime User
unfortunately I can not translate everything perfectly (and despite this, I "put my mouth anywhere" :)).

Will the fact that I type faster with two hands, but I prefer less synthesis and more clarity in the code.

If I use the code written by other people and I find something like:

If A> B then dothis

then i change it to:

If A> B then
dothis
end If

it is a small example, but often it is advisable for the debugging phase
 

thedesolatesoul

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
BPosn = BPosn + 2 + I + 1' move to the next position for
 
Top