Results 1 to 3 of 3

Thread: Rusts option construct for null is elegant

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default Rusts option construct for null is elegant

    Hi,

    The request for having null support in DataFlex has come up every now and then.
    I do think it would be good to have, but also see the problems with it.
    For example I just had a bug report last week from my new product (vimarun) where a customer bumped into a runtime bug. Basically it boiled down to the side effect of me not taking care of a null problem...

    So last night my wife asks me to explain something in rust.
    She's studying that now and loves it (for good reason!)

    The problem was "what is an option enum?"
    See this chapter in the rust doc (read it whole) : Defining an enum

    She comes from a loosely typed language (javascript) which is even more loosely typed than DataFlex, but it has support for null.
    So while she understands the null concept, the problem with null first had to be explained.
    Well OK I had a bug I could show

    The solution in rust with having option<T> is elegant and can help a lot while avoiding some of the problems with null.
    Can we have this in DataFlex too please

    Example code on how it could look like once implemented in the compiler & runtime.
    Code:
    // Wont Even Compile, type mismatch!
      Integer iX
      Option<Integer> iY
      Integer iSum
                
      Move (iY + iY) To iSum
    Code:
    // Compiles
      Integer iX
      Option<Integer> iY
      Integer iSum
                
      if (iY.none=false) Begin
        Move (iY + iY.Some) To iSum
      End
      Else ;
        Showln 'Y has no value!'
    Thanks Oy
    --
    Wil
    Last edited by wila; 28-Nov-2020 at 07:18 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •