The Daily Static
  The Daily Static
UF Archives
Register
UF Membership
Ad Free Site
Postcards
Community

Geekfinder
UFie Gear
Advertise on UF

Forum Rules
& FAQ


Username

Password


Create a New Account

 
 

Back to UserFriendly Strip Comments Index

To null or not to null? by Khaar2009-01-29 02:19:43
  Here's how I'd do it: by JimK 2009-01-29 02:48:57
AS the value can be anything, I don't see how you can safely use one value as 'false' Some sort of composite type with a value and a flag; that way they get passed around together. Enzomatrix has the right idea, I think, because the class methods can make the flag use transparent to the user.

As a curiosity, here's a solution in the main language I work in, SystemVerilog. I can use a union that has a type-safeness tag:

typedef union tagged {
  void Invalid;
  int Valid;
} VInt;

VInt vi1, vi2;
...
vi1 = tagged Valid (23+34); // Create Valid int
vi2 = tagged Invalid; // Create an Invalid value
...
if (vi2 == tagged invalid) begin
  do_stuff;
end else begin
  do_other_stuff();
end
And so on. However, even though this solution exists I'd probably still go with a class because it's easier to make the methods enforce access policies.
[ Reply ]
    you cant have a variable/object typed void. by mekkanik_mike2009-01-29 03:21:05
      But this isn't C/++, so I can :-) (n/t) by JimK2009-01-29 04:18:15
      Actually, IIRC, in C# it's possible... by Enzomatrix2009-01-29 04:29:09
        ugh. by mekkanik_mike2009-01-29 20:27:41

 

[Todays Cartoon Discussion] [News Index]

Come get yer ARS (Account Registration System) Source Code here!
All images, characters, content and text are copyrighted and trademarks of J.D. Frazer except where other ownership applies. Don't do bad things, we have lawyers.
UserFriendly.Org and its operators are not liable for comments or content posted by its visitors, and will cheerfully assist the lawful authorities in hunting down script-kiddies, spammers and other net scum. And if you're really bad, we'll call your mom. (We're not kidding, we've done it before.)