1. Userdefined datatypes

Hi,

I've created an own data-type called "byte";

type byte( object nByte ) 
 return ( integer( nByte ) and nByte >= 0 and nByte <= 255 ) 
end type 

With this, I was hoping that the following code would "survive" a data-type check;

sequence myType = "somesequenceiwanttocheck" 
if byte( myType ) then <statements> else <statements> end if 

However, it doesn't... Any thoughts?

Kenneth aka ZNorQ

new topic     » topic index » view message » categorize

2. Re: Userdefined datatypes

Ah forget it! Stupid me, I assumed short-circuit applied to the...

return ( integer( nByte ) and nByte >= 0 and nByte <= 255 )

... however I tried modifying the code to the following;

type byte( object nByte ) 
if sequence( nByte ) then return false 
else return ( integer( nByte ) and nByte >= 0 and nByte <= 255 ) 
end if 
end type 

New motto; THINK, before you post... Oo

Kenneth

new topic     » goto parent     » topic index » view message » categorize

3. Re: Userdefined datatypes

Not a very Norwegian first name Kenneth ;)
My name Antoine can be explained by the fact that my granny was French

new topic     » goto parent     » topic index » view message » categorize

4. Re: Userdefined datatypes

ZNorQ said...

I've created an own data-type called "byte";

It's probably just a style thing, but the way I code these is more along the lines of ...

type byte( object nByte ) 
 if not integer( nByte ) then return 0 end if 
 if nByte < 0 then return 0 end if 
 if nByte > 255  then return 0 end if 
 return 1 
end type 
new topic     » goto parent     » topic index » view message » categorize

5. Re: Userdefined datatypes

Ekhnat0n said...

Not a very Norwegian first name Kenneth ;)
My name Antoine can be explained by the fact that my granny was French

Correct, and on top of that I have a Swedish surname (Sweedish blood in the family tree way back) ;)

new topic     » goto parent     » topic index » view message » categorize

6. Re: Userdefined datatypes

DerekParnell said...
ZNorQ said...

I've created an own data-type called "byte";

It's probably just a style thing, but the way I code these is more along the lines of ...

type byte( object nByte ) 
 if not integer( nByte ) then return 0 end if 
 if nByte < 0 then return 0 end if 
 if nByte > 255  then return 0 end if 
 return 1 
end type 

Would it be because of readibility, execution efficiency - or something else?

Regards Kenneth/ZNorQ

new topic     » goto parent     » topic index » view message » categorize

7. Re: Userdefined datatypes

ZNorQ said...
DerekParnell said...

It's probably just a style thing, but the way I code these is more along the lines of ...

Would it be because of readibility, execution efficiency - or something else?

Sure, both those plus plus maintainability and debugging.

It is easy to insert or modify a condition when they are all laid out in a simple format.

Debugging, using trace(), is easier to see when stepping through one condition at a time.

new topic     » goto parent     » topic index » view message » categorize

8. Re: Userdefined datatypes

DerekParnell said...
ZNorQ said...
DerekParnell said...

It's probably just a style thing, but the way I code these is more along the lines of ...

Would it be because of readibility, execution efficiency - or something else?

Sure, both those plus plus maintainability and debugging.

It is easy to insert or modify a condition when they are all laid out in a simple format.

Debugging, using trace(), is easier to see when stepping through one condition at a time.

But short-circuit evaluation counts for efficiency too, right?

Kenneth / ZNorQ

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu