Page 3 of 3
Re: Please improve examples
Posted: Sat Mar 07, 2020 10:43 pm
by Little John
Hello Andre, Tenaja, davido,
thank you for your kind reactions
Anyway, I am somewhat tired ...
- ... of discussions, where some "experts" reply to messages which they did never read, and/or post stuff that is completely off-topic in the respective thread. This happens often here on the forum. When it's a thread that was started by me, I feel the need to set things right. This is nothing but a waste of time and energy from my point of view.
- ... of running against walls in the heads of other people. And I'm not going to offer my commitment, my ideas, my knowledge and my experience as if they were sour beer.
I'll maintain my contributions (if necessary), though.
And every now and then I'll maybe have a coding question or bug report.
Re: Please improve examples
Posted: Sun Mar 08, 2020 1:47 am
by Fangbeast
My main suggestion was/is, not to use '0' everywhere in an example where it is technically possible, but to use meaningful named constants instead.
+100
Once I realised years ago that I could replace all the 0's with my own constants, I did just that and my code is so much more readable, meaningful and a hell of a lot easier to debug as I read it line by line.
E.g. If DatabaseQuery fails, you can always get the results of a database error but if I substitute the generic 0 for a failed query with my own #DatabaseQueryFail, it makes sense to me that it failed and went to my handler.
Code: Select all
#DatabaseQueryFail = 0
SetDatabaseString(Databasehandle, 0, "1")
SetDatabaseString(Databasehandle, 1, "1")
If DatabaseQuery(Databasehandle), "UPDATE db_addresses SET locked = ? WHERE recordid = ?") <> #DatabaseQueryFail
; "Do something here
Else ; Query failed, constant is now obvious too so we get here
Debug DatabaseError()
EndIf
Re: Please improve examples
Posted: Sun Mar 08, 2020 4:06 am
by TI-994A
Andre wrote:I agree here, the UserGuide is probably the best place for this more expanded descriptions and examples.
This was also the reason for me, to start the following thread in the PB forum:
viewtopic.php?f=7&t=45842
Absolutely, Andre. The explanations and examples there conform pretty much to what's being suggested here, demonstrating syntactical and contextual applications and implementations.
Perhaps this thread would be better served if merged there.
Re: Please improve examples
Posted: Sun Mar 08, 2020 3:27 pm
by DK_PETER
Little John wrote:Mijikai wrote:I would also 'force' EnableExplicit
In the beginning i never used it and though i dont need it... obviously a mistake

Now i always use it (i also use End btw.).
I think it would be a good thing to have it only as check box option in the compiler settings that by default is always on.
This doesn't have got much to do with what I wrote in the first post of this thread.
Feel free to start a discussion about that in a separate thread, but don't hijack this one
Denis wrote:+1
EnableExplicit by default will be good.
Maybe someone is interested in the fact, that I (deliberately!) never wrote that ...
This is a different discussion. Feel free to discuss that in your own thread, but don'*t hijack this one
Little John wrote:Another improvement of example codes would be, to
make them ready for usage with EnableExplicit. So I actually would write the respective examle code like this:
Code: Select all
Prototype.i ProtoMessageBoxW(Window.i, Body.p-unicode, Title.p-unicode, Flags.i = 0)
Define MsgBox.ProtoMessageBoxW
#Library = 0
If OpenLibrary(#Library, "User32.dll")
MsgBox = GetFunction(#Library, "MessageBoxW")
MsgBox(0, "Hello", "World")
EndIf
There is no
EnableExplicit at all in that code. But the trick is:
That code runs with
EnableExplicit on or off, so it is always usable!
In contrast, the following code (similiar to that one in the help)
Code: Select all
Prototype.i ProtoMessageBoxW(Window.i, Body.p-unicode, Title.p-unicode, Flags.i = 0)
#Library = 0
If OpenLibrary(#Library, "User32.dll")
MsgBox.ProtoMessageBoxW = GetFunction(#Library, "MessageBoxW")
MsgBox(0, "Hello", "World")
EndIf
only runs with
EnableExplicit off, but not with
EnableExplicit on.
DK_PETER wrote:Is it really that hard to write
or
?
Extremely redundant request...

I never requested that, and this has nothing got to do with what I wrote in my original post here.
However, it's old news hat some people like to post offtopic stuff in other people's threads ...
@Little John
Your post was already hijacked and my response wasn't to you..
Re: Please improve examples
Posted: Sun Mar 08, 2020 3:42 pm
by Little John
DK_PETER wrote:@Little John
Your post was already hijacked and my response wasn't to you..
I didn't say that it was you who hijacked my thread. I just wanted to make things clear.
Re: Please improve examples
Posted: Sun Mar 08, 2020 3:48 pm
by DK_PETER
Little John wrote:DK_PETER wrote:@Little John
Your post was already hijacked and my response wasn't to you..
I didn't say that it was you who hijacked my thread. I just wanted to make things clear.
Message received.