Page 1 of 2
Please allow '(' in string operations
Posted: Fri Mar 01, 2013 7:58 pm
by Little John
"Classic" way of concatenating a string and a numeric expression:
Code: Select all
x = 7
res$ = "Result: " + Str(x + 2)
Debug res$ ; -> 9
Since PB 5.10 we can do without Str(), but get a different result in this case:
Code: Select all
x = 7
res$ = "Result: " + x + 2
Debug res$ ; -> 72
So please allow the following (which currently raises a syntax error):
Code: Select all
x = 7
res$ = "Result: " + (x + 2)
Debug res$ ; -> 9
As Danilo wrote, this is also allowed in some other languages.
Re: Please allow '(' in string operations
Posted: Fri Mar 01, 2013 8:22 pm
by freak
Re: Please allow '(' in string operations
Posted: Fri Mar 01, 2013 8:38 pm
by jassing
I'm with you -- Use Str() -- even tho I can use numbers and strings together, I prefer to use Str() still -- I find it more readable, and easier to verify what is being done. I hate auto-casting in general, as it leads to problems, like this...
Re: Please allow '(' in string operations
Posted: Wed Mar 06, 2013 10:50 pm
by BorisTheOld
jassing wrote:I prefer to use Str() still -- I find it more readable, and easier to verify what is being done. I hate auto-casting in general, as it leads to problems, like this...
I agree completely. Auto-casting is a disaster waiting to happen.
I've learned the hard way that clarity should have precedence over brevity, and I happily use long variable names, lots of comments, and strict coding standards.
Non-rigorous coding practices are why most of today's software is bugridden rubbish. Check out most software forums and you'll find comments like, "For this month's release we fixed about 240 bugs" - as if that's something to be proud of.
Auto-casting, and similar "programming aids", should not be part of PB
Re: Please allow '(' in string operations
Posted: Wed Mar 06, 2013 11:14 pm
by IdeasVacuum
clarity should have precedence over brevity, and I happily use long variable names, lots of comments, and strict coding standards
Agreed -a basic requirement to underpin good code and the autocasting simply isn't necessary at all in this case.
Re: Please allow '(' in string operations
Posted: Thu Mar 07, 2013 12:10 am
by rsts
BorisTheOld wrote:
Auto-casting, and similar "programming aids", should not be part of PB
+1
Re: Please allow '(' in string operations
Posted: Thu Mar 07, 2013 12:40 am
by skywalk
+1
The "cat is out of the bag", so this request seems to solve the issue of "x" + 1 + 2 <> "x" + (1+2).
Re: Please allow '(' in string operations
Posted: Thu Mar 07, 2013 12:48 am
by jassing
[sarcasm]Next some request will be for interpreting strings as numeric values so we can really have code that is hard to follow...[/sarcasm]
Re: Please allow '(' in string operations
Posted: Thu Mar 07, 2013 12:59 am
by BorisTheOld
And for those of you wondering why auto-casting is so bad, it's because the compiler will happily accept code that might otherwise be flagged as an error. And in such a situation the compiled code will most certainly not work correctly.
Unfortunately, the failure may not manifest itself until much later when the program is in production. Not only are such bugs very difficult to find, but the defective code might have been slowly destroying valuable data without showing any signs of failure. Or, worse case, it might be putting someone's life at risk.
That's why I said that auto-casting is a disaster waiting to happen. Far better to spend a little extra time writing bullet proof code, than have the compiler make assumptions about what you actually wrote.
Re: Please allow '(' in string operations
Posted: Thu Mar 07, 2013 3:58 am
by Little John
Some people wrote here that they don't like auto-casting in PB.
I'm aware of problems that auto-casting can cause, that's why I created the thread
Cave when doing without Str()!.
There seems to be a misunderstanding: I did not request here to introduce auto-casting into PB, it is already there. E.g.
does already work.
So why don't you make a separate feature request for disallowing this in PB?
Re: Please allow '(' in string operations
Posted: Thu Mar 07, 2013 4:43 am
by BorisTheOld
I know auto-casting is already in PB - I was just warning against the hazards of its existance.
My own coding practices are such that I won't run afoul of it. All our code is automatically created from application specifications, using templates that are known to generate valid code.
If the users of PB want to have auto-casting, then it's up to PB's authors whether such a feature is included. But if it were my choice I would get rid of it before too much damage is done.
Re: Please allow '(' in string operations
Posted: Thu Mar 07, 2013 5:21 am
by Little John
BorisTheOld wrote:I know auto-casting is already in PB - I was just warning against the hazards of its existance.
As I already pointed out, the purpose of this thread is
not a general discussion about auto-casting.
Feel free to make a separate feature request for removing any auto-casting from PB.
Re: Please allow '(' in string operations
Posted: Thu Mar 07, 2013 1:51 pm
by BorisTheOld
Little John wrote:As I already pointed out, the purpose of this thread is not a general discussion about auto-casting.
Seems to me that all of the above comments, not just mine, are saying that your suggestion is not such a good one.
Explaining why is, I hope, of use to others in deciding the merits of your proposal.
Re: Please allow '(' in string operations
Posted: Thu Mar 07, 2013 2:17 pm
by Little John
BorisTheOld wrote:Explaining why is, I hope, of use to others in deciding the merits of your proposal.
There wasn't much "explaining why" regarding anything about '(' in string operations. There mainly were comments against auto-casting in general.
And:
Little John wrote:I did not request here to introduce auto-casting into PB, it is already there.
Little John wrote:BorisTheOld wrote:I know auto-casting is already in PB - I was just warning against the hazards of its existance.
As I already pointed out, the purpose of this thread is
not a general discussion about auto-casting.
Actually shouldn't be too hard to understand.
Re: Please allow '(' in string operations
Posted: Thu Mar 07, 2013 5:26 pm
by Tenaja
+1 for little John's request.
If PB is going to allow the auto-cast, it should allow the parens.