Page 2 of 4
Re: Please show all syntax errors
Posted: Tue Oct 12, 2010 4:11 pm
by Blood
freak wrote:If anything, this could be a warning not an error.
Yes!
Re: Please show all syntax errors
Posted: Tue Oct 12, 2010 4:57 pm
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.

Re: Please show all syntax errors
Posted: Tue Oct 12, 2010 5:15 pm
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.
Re: Please show all syntax errors
Posted: Tue Oct 12, 2010 7:38 pm
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.
Re: Please show all syntax errors
Posted: Tue Oct 12, 2010 7:54 pm
by Trond
What about ReplaceString()?
Re: Please show all syntax errors
Posted: Tue Oct 12, 2010 8:02 pm
by Little John
Trond wrote:What about ReplaceString()?
Using the result of
ReplaceString() is optional.
Re: Please show all syntax errors
Posted: Tue Oct 12, 2010 11:51 pm
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.

Re: Please show all syntax errors
Posted: Wed Oct 13, 2010 6:47 am
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.
Re: Please show all syntax errors
Posted: Wed Oct 13, 2010 2:39 pm
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
Re: Please show all syntax errors
Posted: Wed Oct 13, 2010 2:46 pm
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
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

Re: Please show all syntax errors
Posted: Wed Oct 13, 2010 3:24 pm
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.
Re: Please show all syntax errors
Posted: Wed Oct 13, 2010 4:40 pm
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?)
Re: Please show all syntax errors
Posted: Wed Oct 13, 2010 5:10 pm
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.
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.
That is my point, nothing more.
MFG PMV
Re: Please show all syntax errors
Posted: Wed Oct 13, 2010 5:35 pm
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.
Re: Please show all syntax errors
Posted: Wed Oct 13, 2010 6:46 pm
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.
MFG PMV