JdV Active Member Licensed User Longtime User Mar 29, 2019 #1 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: Code: 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
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: Code: 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 Mar 29, 2019 #2 or if the return is not used it make a replace in the string, would also be good
DonManfred Expert Licensed User Longtime User Mar 29, 2019 #3 It is not a bug, it is a programming mistake. JdV said: Dim MyString As String MyString = "Hello world" MyString.Replace("world", "everyone") ' Replace returns a new String Log(MyString) Click to expand... Correct code Code: Dim MyString As String MyString = "Hello world" MyString = MyString.Replace("world", "everyone") Log(MyString)
It is not a bug, it is a programming mistake. JdV said: Dim MyString As String MyString = "Hello world" MyString.Replace("world", "everyone") ' Replace returns a new String Log(MyString) Click to expand... Correct code Code: Dim MyString As String MyString = "Hello world" MyString = MyString.Replace("world", "everyone") Log(MyString)
JdV Active Member Licensed User Longtime User Mar 29, 2019 #4 MarkusR said: or if the return is not used it make a replace in the string, would also be good Click to expand... That would work for string example but for the following code it's not obvious what to do with the result: Code: Dim b As Bitmap b.Initialize(File.DirAssets, "test.png") b.GetPixel(0,0)
MarkusR said: or if the return is not used it make a replace in the string, would also be good Click to expand... That would work for string example but for the following code it's not obvious what to do with the result: Code: Dim b As Bitmap b.Initialize(File.DirAssets, "test.png") b.GetPixel(0,0)
DonManfred Expert Licensed User Longtime User Mar 29, 2019 #5 JdV said: but for the following code it's not obvious what to do with the result Click to expand... Sure it is. https://www.b4x.com/android/help/drawing.html#bitmap_getpixel It returns the color of the pixel at the specified position. Code: Dim b As Bitmap b.Initialize(File.DirAssets, "test.png") dim pixel as int = b.GetPixel(0,0)
JdV said: but for the following code it's not obvious what to do with the result Click to expand... Sure it is. https://www.b4x.com/android/help/drawing.html#bitmap_getpixel It returns the color of the pixel at the specified position. Code: Dim b As Bitmap b.Initialize(File.DirAssets, "test.png") dim pixel as int = b.GetPixel(0,0)
MarkusR Well-Known Member Licensed User Longtime User Mar 29, 2019 #6 yes agree, a warning would be great in this case.
mangojack Expert Licensed User Longtime User Mar 29, 2019 #7 DonManfred said: It is not a bug, it is a programming mistake. Click to expand... 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 ...
DonManfred said: It is not a bug, it is a programming mistake. Click to expand... 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 ...
Erel B4X founder Staff member Licensed User Longtime User Mar 31, 2019 #8 There are many cases where the return value is not used and it is completely fine. A general warning for this will probably make more harm than good. I do agree that the mistake with string.Replace / Substring / ToLowerCase / ToUpperCase methods is common enough for it to justify its own warning.
There are many cases where the return value is not used and it is completely fine. A general warning for this will probably make more harm than good. I do agree that the mistake with string.Replace / Substring / ToLowerCase / ToUpperCase methods is common enough for it to justify its own warning.