Please improve examples

Found an issue in the documentation ? Please report it here !

Moderator: Documentation Editors

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

Re: Please improve examples

Post by Little John »

Hello Andre, Tenaja, davido,

thank you for your kind reactions :!:

Anyway, I am somewhat tired ...
  1. ... 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.
  2. ... 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.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4749
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Please improve examples

Post 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
Amateur Radio, D-STAR/VK3HAF
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Please improve examples

Post 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.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Please improve examples

Post 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

Code: Select all

EnableExplicit
or

Code: Select all

DisableExplicit
?
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..
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Please improve examples

Post 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.
User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Please improve examples

Post 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.
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
Post Reply