POINTER NULL CHECK

General FreeBASIC programming questions.
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Re: POINTER NULL CHECK

Post by vdecampo »

fxm wrote:
fxm wrote:Another example, I don't like the syntax:

Code: Select all

If Len(string) Then ...
Obviously this syntax compiles well and works but this code BASIC is not "clean" in my humble opinion, because the expression 'Len (string)' is neither true nor false, but conversely the expression 'Len (string) = 0' is true or false.
Here, I talk about the quality of the source code!
In FB, isn't TRUE defined as non-zero?

-Vince
fxm
Moderator
Posts: 12106
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: POINTER NULL CHECK

Post by fxm »

Yes, it's true!!!
But I was just talking about my syntactic preference when I write my own source code.
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: POINTER NULL CHECK

Post by jj2007 »

Btw it's not trivial whether true=1 or true=-1 or something else. Micros**t has introduced true=1, unfortunately, because with true=-1 you could 'confirm' values as in MyVal=123 and (a<b) ' 123 if true, 0 if false

My defunct favourite dialect Gfa returned the full source string for Left$("some text", true); with true=-1, of course. I often used stuff like this:

Code: Select all

a%=1, b%=1, i$="Hello, this is a text"
t$=LEFT$(i$, 4-(a%<b%))
Ret%=MessageBox(0, t$, "Test 4-(a%<b%) with a=b:", MB_OK)   'Hell
b%++
t$=LEFT$(i$, 4-(a%<b%))
Ret%=MessageBox(0, t$, "Test 4-(a%<b%) with a<b:", MB_OK)   'Hello
t$=LEFT$(i$, a%<b%)
Ret%=MessageBox(0, t$, "Test a%<b% with a<b:", MB_OK)   'Hello, this is a text
Awful coding style, I know. I was young, hehe.
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: POINTER NULL CHECK

Post by srvaldez »

a bit off topic, I don't know when this started but I simply abhor variable suffixes like %, $ etc, I simply find it incredibly offensive.
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: POINTER NULL CHECK

Post by jj2007 »

Mostly a matter of taste. I can live without the MyInt% (dword) or the flag! (boolean), but the string$ suffix is incredibly useful if you are debugging a 10,000+ lines source.

Imagine Micros**t would abandon their Hungarian notation... would you still understand the MSDN documentation? Is LPCTSTR lpszMenuName more beautiful than MenuName$ ?
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: POINTER NULL CHECK

Post by srvaldez »

I think that an "intelligent" IDE would be preferable than suffixes, imagine and IDE that would highlight variable names with different colours depending on the type, the highlighting would of course be togable.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: POINTER NULL CHECK

Post by dodicat »

No such luck with left true in FreeBASIC.
To make up for this loss, I stuck it in automatic mode (no clicking anything)

Code: Select all



declare function messagebox lib "user32.dll" alias "MessageBoxTimeoutA"(as any ptr,as zstring,as zstring,as long,as long,as long)  as long

dim as long MB_OK
 MB_OK=0
dim as integer a=1,b=1:dim as string i="Hello, this is a text",t
t=LEFT(i, 4-(a<b))
var Ret=MessageBox(0, t, "Test 4-(a<b) with a=b:", MB_OK,0,2000)   'Hell
b+=1
t=LEFT(i, 4-(a<b))
 Ret=MessageBox(0, t, "Test 4-(a<b) with a<b:", MB_OK,0,2000)   'Hello
t=LEFT(i,a<b)+i
 Ret=MessageBox(0, t, "----------------------", MB_OK,0,2000)   'Hello, this is a text
 print "done"
sleep 
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: POINTER NULL CHECK

Post by MrSwiss »

srvaldez wrote:... but I simply abhor variable suffixes like %, $ etc, I simply find it incredibly offensive.
Yes, I'd sign that one, straight away! (exactly the same feeling)
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: POINTER NULL CHECK

Post by jj2007 »

But you have no problem with prefixes as in lpszMenuName, right?
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: POINTER NULL CHECK

Post by MrSwiss »

jj2007 wrote:But you have no problem with prefixes as in lpszMenuName, right?
Not at all:
LongPointerStringZero(terminated)... say's it all, there is to know, about it.
(just a $ tells me, a lot less: some or other sort of String or maybe ZString?!? also, access method?)
Munair
Posts: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

Re: POINTER NULL CHECK

Post by Munair »

jj2007 wrote:Btw it's not trivial whether true=1 or true=-1 or something else. Micros**t has introduced true=1, unfortunately, because with true=-1 you could 'confirm' values as in MyVal=123 and (a<b) ' 123 if true, 0 if false

My defunct favourite dialect Gfa returned the full source string for Left$("some text", true); with true=-1, of course. I often used stuff like this:

Code: Select all

a%=1, b%=1, i$="Hello, this is a text"
t$=LEFT$(i$, 4-(a%<b%))
Ret%=MessageBox(0, t$, "Test 4-(a%<b%) with a=b:", MB_OK)   'Hell
b%++
t$=LEFT$(i$, 4-(a%<b%))
Ret%=MessageBox(0, t$, "Test 4-(a%<b%) with a<b:", MB_OK)   'Hello
t$=LEFT$(i$, a%<b%)
Ret%=MessageBox(0, t$, "Test a%<b% with a<b:", MB_OK)   'Hello, this is a text
Awful coding style, I know. I was young, hehe.
I've seen many BASIC programmers using the boolean TRUE value for other operations. While it seems smart and the code becomes compact, it is a terrible programming habit. One should always keep in mind that the values for TRUE and FALSE may change or will be different when porting the code.
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: POINTER NULL CHECK

Post by jj2007 »

Munair wrote:I've seen many BASIC programmers using the boolean TRUE value for other operations. While it seems smart and the code becomes compact, it is a terrible programming habit.
Agreed. But the "professional" world of C/C++ is full of such ugly habits, such as falling thru in Switch/Case, or the ternary operator. I stopped abusing TRUE when a) I found out that Micros**t uses 1 instead of -1 and b) that it causes more work for the Cpu than a simple conditional jump.
Post Reply