Please check for syntax that doesn't make ANY sense

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Blood
Enthusiast
Enthusiast
Posts: 161
Joined: Tue Dec 08, 2009 8:34 pm
Location: United Kingdom

Re: Please show all syntax errors

Post by Blood »

freak wrote:If anything, this could be a warning not an error.
Yes!
C provides the infinitely-abusable goto statement, and labels to branch to. Formally, the goto is never necessary, and in practice it is almost always easy to write code without it. We have not used goto in this book. -- K&R (2nd Ed.) : Page 65
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Please show all syntax errors

Post by skywalk »

I also agree with the warning.
I can't tell you how many logical warnings I must signal to users...the demands of a flexibile application. :wink:
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Please show all syntax errors

Post by Trond »

My wish refers only to internal functions such as Mid(), where ignoring the return value doesn't make any sense.
Computers are not particularly good at knowing when things make sense or not.
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Please show all syntax errors

Post by Little John »

freak wrote:
Little John wrote:
Trond wrote:And there are many functions where the return value is not always needed. What would you do about those?
My wish refers only to internal functions such as Mid(), where ignoring the return value doesn't make any sense. Implementing my wish will not cause any disadvantage to the PB programmer.
The compiler has to be consistent in its error reporting. Otherwise it just creates confusion.
Yes, I agree.
freak wrote:How is a beginner supposed to know that for function X the returnvalue is always needed and for function Y it can sometimes be ignored?
From the documentation, and from a proper error message.
freak wrote:For him it will just look like the compiler is missing an error.
Not necessarily. And I think the risk that this will happen is pretty small.
Error messages generated by the compiler could read like this:
The result of Mid() must be assigned or used.
The result of FindString() must be assigned or used.
etc ...
These error messages will be consistent, the user will always get the same message for the same error. And the message clearly tells to which function it refers. Actually, this principle is not new to PB, e.g.:

Code: Select all

NewMap x.i(1024)  ; OK
NewMap y.i()      ; OK
Dim z.i()         ; Syntax error
When using NewMap, specifying the number of slots is optional, as opposed to Dim, where specifying the number of elements is mandatory.
And e.g. when using OpenWindow(), assigning or using the result is optional, as opposed e.g. to Mid(), where assigning or using the result will be mandatory (according to my suggestion). So IMHO nothing that is strange to PureBasic or confusing will be introduced by this suggestion.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Please show all syntax errors

Post by Trond »

What about ReplaceString()?
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Please show all syntax errors

Post by Little John »

Trond wrote:What about ReplaceString()?
Using the result of ReplaceString() is optional.
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Please show all syntax errors

Post by Demivec »

Little John wrote:
Trond wrote:What about ReplaceString()?
Using the result of ReplaceString() is optional.
Quite the contrary. If the replace produces a new string (default option) the result must be used, if the replace is done in place (an option) the result must be ignored. So in neither case is it optional, it depends on the parameters. :mrgreen:
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Please show all syntax errors

Post by Little John »

Sorry, I'm not a native English speaker. With "optional" I mean: "Not always required."
Since it depends on the parameters, using the result of ReplaceString() is not always required.
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Please show all syntax errors

Post by PMV »

If you really plan to implement such a warning message, i hope you
make it optional. I does not need a compiler, who says to me what
is logical and what not ... it would be really annoying if there would
be always a warning where is nothing.

It is true, a perfect programmed code must use each result to check,
if there is an error or not. But PB is not supposed to be only for
clean code, it is used to create little fast results, too. :)

MFG PMV
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Please show all syntax errors

Post by Little John »

PMV wrote:... it would be really annoying if there would
be always a warning where is nothing.
I'm pretty sure you won't get always a warning, because you don't have always lines such as

Code: Select all

Mid(s$, 7)
FindString(a$, b$, 1)
in your code. :-)
And in case that is in the code: It's not nothing, but it's garbage.
PMV wrote:It is true, a perfect programmed code must use each result to check,
if there is an error or not.
Sorry, it seems you didn't get my point.
I'm not asking for using each result. But what is the purpose of using Mid() or FindString() and ignoring their results :?:
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: Please show all syntax errors

Post by Mistrel »

I really don't follow this post at all. It's the programmer's responsibility to not make a mistake like this. I certainly wouldn't want to waste precious seconds because the compiler wants to try and tell ME how to write my logic.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Please show all syntax errors

Post by blueznl »

For a change I see the point of the requester. Why not use the compiler's help to avoid stupid mistakes? We all make them... (Hell, I even am married!)

I would like it if the compiler would throw a warning if a statement is used which would not make sense if the return value isn't used for anything. Obviously only for those specific statements. If there is an alternate syntax (ReplaceString etc,) or if the statement could be used without the need for a return value (OpenWindow for example) then there's no warning to be thrown.

Again, whenever the language / compiler can help the programmer it is good, even programmers make mistakes! (Did I mention I also have kids?)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Please show all syntax errors

Post by PMV »

Little John wrote:
PMV wrote:It is true, a perfect programmed code must use each result to check,
if there is an error or not.
Sorry, it seems you didn't get my point.
I'm not asking for using each result. But what is the purpose of using Mid() or FindString() and ignoring their results :?:
I haven't done a mistake like this and i will not do it.
You shouldn't write programs while you are drunk. :mrgreen:

I get your point, but like i posted, i doesn't want a compiler who
says me what is logical and what not. If i need some from this sort,
i will use a (strikt) OOP-language. :lol:

That is my point, nothing more. :wink:

MFG PMV
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Please show all syntax errors

Post by Little John »

@blueznl:
Thanks for your post! I'm really happy that here are at least a few people who understand the problem. :-)
PMV wrote:I haven't done a mistake like this and i will not do it.
Then you will not notice any difference, when such an error check is built into the compiler. So what is your problem?
But for average people like me, such an error check can help to prevent bugs.
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Please show all syntax errors

Post by PMV »

Little John wrote:Then you will not notice any difference, when such an error check is built into the compiler. So what is your problem?
Bet i will. If fred adds such a warning for some cases, one case
will be a problem for me. He is only a human. Unbelievable,
of course for me too, but thats true. And thats the problem.
If this feature is deactivate able ... i have no problem. Thats what
i have written. :wink:

MFG PMV
Post Reply