Wish Warnings for code that won't do anything

JdV

Active Member
Licensed User
Longtime User
Hi

It would be good if the IDE could report warnings for code that won't anything and which doesn't cause any errors.

For example, the 'MyString.Replace' doesn't replace the word 'world' with 'everyone' in the following piece of code:

B4X:
Dim MyString As String
MyString = "Hello world"
MyString.Replace("world", "everyone")
Log(MyString)

These warnings could be similar to the way that the IDE reports variables that are never assigned values or subs that are never called.

Regards

Joe
 

MarkusR

Well-Known Member
Licensed User
Longtime User
or if the return is not used it make a replace in the string, would also be good
 

DonManfred

Expert
Licensed User
Longtime User
It is not a bug, it is a programming mistake.

Dim MyString As String
MyString = "Hello world"
MyString.Replace("world", "everyone") ' Replace returns a new String
Log(MyString)

Correct code
B4X:
Dim MyString As String
MyString = "Hello world"
MyString = MyString.Replace("world", "everyone")
Log(MyString)
 

JdV

Active Member
Licensed User
Longtime User
or if the return is not used it make a replace in the string, would also be good

That would work for string example but for the following code it's not obvious what to do with the result:
B4X:
Dim b As Bitmap
b.Initialize(File.DirAssets, "test.png")
b.GetPixel(0,0)
 

DonManfred

Expert
Licensed User
Longtime User

MarkusR

Well-Known Member
Licensed User
Longtime User
yes agree, a warning would be great in this case.
 

mangojack

Expert
Licensed User
Longtime User
It is not a bug, it is a programming mistake.
Don .. on this occassion @JdV is not suggesting it is a bug ... He is just posting a wish for an IDE Warning on the 'not ideal code' ...
as suggested Here ...

Just saying ... :)
 
Top