Page 1 of 5 1234 ... LastLast
Results 1 to 10 of 48

Thread: YAFR DataTypeToJson beyond 19.1

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2009
    Posts
    5,468

    Default YAFR DataTypeToJson beyond 19.1

    Please can the DataTypeToJson be improved in 19.2 and or NextGen so that the JSON only contains the struct elements that have been set and not all of them

    Yes the JSON can be processed afterwards to remove blanks etc but you might want to send a blank to clear the contents of a field at the other end or you don't want a boolean set to false etc etc

    At the moment DataTypeToJson is almost a solution instead of having to manually code the contents of a JSON object to get the exact JSON you expect but it's not quite there

    The JSONToDataType could also do with ignoring nulls

    Thanks
    Success consists of going from failure to failure without loss of enthusiasm - Winston Churchill

  2. #2
    Join Date
    Feb 2009
    Location
    Stuart, FL
    Posts
    5,321

    Default Re: YAFR DataTypeToJson beyond 19.1

    what we need is null support. Currently without proper null support the runtime of course doesnt know if a field is blank/0/etc or null

    the boolean solution is a hack that imo is quite terrible and has bad side effects on code later down the road that will not be easily found

    once the language supports null which it should for so many reasons the rest just falls into place
    Michael Salzlechner
    StarZen Technologies, Inc
    http.://www.starzen.com

    IT Director at Balloons Everywhere

    Development Blog
    http://www.salzlechner.com/dev

    DataFlex Package Manager (aka Nuget for DataFlex)
    http://windowsdeveloper.com/dfPackage

  3. #3
    Join Date
    Feb 2009
    Posts
    5,468

    Default Re: YAFR DataTypeToJson beyond 19.1

    I don't disagree but Null support would mean lots of code change for developers would it not ?

    sVal="" is not the same as sVal=Null

    or maybe it is in the DF world and if you want to know if it is actually Null

    If IsNull(sVal)

    Also If (bVal) would need to treat false and null the same so as not to break existing code

    etc etc

    Not saying it would not be better overall and maybe it is as simply as
    ""=Null
    False=Null
    0=Null
    1/1/1753=Null

    to preserve existing compatibility unless Null is specifically tested for when it is needed
    Success consists of going from failure to failure without loss of enthusiasm - Winston Churchill

  4. #4
    Join Date
    Mar 2009
    Location
    Beech Hill - a village near Reading in the UK
    Posts
    2,812

    Default Re: YAFR DataTypeToJson beyond 19.1

    How do other languages handle this?

    I don't mean the syntax in various SQL implementations and such like, I mean how does it actually work at a low level? After all there is no way a bit or a byte or a word (of whatever size) can actually be null (unless you mean ASCII 0, which I'd say was zero, regardless of the character code assigned to it, which is only about strings), so how is the magic done?

    Mike (hoping to learn something)

  5. #5
    Join Date
    Feb 2009
    Posts
    5,468

    Default Re: YAFR DataTypeToJson beyond 19.1

    Success consists of going from failure to failure without loss of enthusiasm - Winston Churchill

  6. #6
    Join Date
    Feb 2009
    Location
    Stuart, FL
    Posts
    5,321

    Default Re: YAFR DataTypeToJson beyond 19.1

    depends on the language

    c# has value types where the value is stored in the variable itself. They cannot be null.

    for ex a non nullable int

    int myInt;

    or a nullable int

    C# also has nullable types for example

    int? myNullableInt

    they can be null or have a value

    nullable types are stored in a struct based on Nullable<T> which has properties such as HasValue, Value and a few methods and operators

    c# also has reference types. reference types support null. Classes for example are reference types

    MyClass test; // now test is null
    test = new MyClass(); // now test is not null

    In Javascript and TypeScript all fields can be null and also undefined
    undefined means a variable has been declared but not assigned a value. null is an actual assigned value

    In C++ NULL also exists but no nullable types. NULL is actually the same as 0. References (Pointers) can be null of course which again is the same as 0.
    Michael Salzlechner
    StarZen Technologies, Inc
    http.://www.starzen.com

    IT Director at Balloons Everywhere

    Development Blog
    http://www.salzlechner.com/dev

    DataFlex Package Manager (aka Nuget for DataFlex)
    http://windowsdeveloper.com/dfPackage

  7. #7
    Join Date
    Mar 2009
    Location
    Beech Hill - a village near Reading in the UK
    Posts
    2,812

    Default Re: YAFR DataTypeToJson beyond 19.1

    Thanks Mike - I didn't know that stuff (so I did just learn something <g>).

    So basically in 1st-3rd gen languages, no nulls, while in things like C# they have nullable types that are kind of like a struct with an extra bit (an actual bit maybe?) to indicate whether they are null or not, in addition to the underlying type? (Correct? Wrong?)

    Seems to me that in that case DataFlex's best bet would be to add an entire parallel set of nullable datatypes to its type system.

    Sort of like we currently have Integer and UInteger (for unsigned), we might have nInteger, for nullable integer, etc. So we'd have:
    • nChar
    • nShort
    • nInteger
    • nBigInt
    • nNumber (sounds like you are fighting a stammer <g>)
    • nDecimal
    • nString
    • nDate
    • nDateTime
    • and so on.


    I'm guessing Address and Pointer and Handle would simply use 0 as their null value, so wouldn't need special nullable versions. Would a nullable Boolean be a thing? Sounds silly... surely the whole point of a Boolean is that it can only be True or False.

    Would we have to add in unsigned nullable types as well? I'd guess so for completeness.

    Maybe they wouldn't all be required... not sure.

    That wouldn't mess with existing code, but would provide a capability to handle nulls where required. Could be a part of DataFlex Nextgen...?

    Or am I talking rubbish (don't answer that! <g>)

    Mike

  8. #8
    Join Date
    Feb 2009
    Location
    Stuart, FL
    Posts
    5,321

    Default Re: YAFR DataTypeToJson beyond 19.1

    in C# a nullable type is actually a struct using a generic. But a struct in C# has fields, methods and properties like a class

    for example you can do this

    Nullable<int> myNullableInt;

    or short form

    int? myNullableInt;

    if (myNullableInt.HasValue) {
    int newint = myNullableInt.Value;
    }

    or

    if (myNullableInt != null)
    {
    int newint = myNullableInt;
    }

    and yes pointers by definition support null when they are not pointing to anything

    because they are implemented using generics any type can be made available using the nullable<T> struct
    Last edited by starzen; 17-Apr-2019 at 09:33 AM. Reason: additional
    Michael Salzlechner
    StarZen Technologies, Inc
    http.://www.starzen.com

    IT Director at Balloons Everywhere

    Development Blog
    http://www.salzlechner.com/dev

    DataFlex Package Manager (aka Nuget for DataFlex)
    http://windowsdeveloper.com/dfPackage

  9. #9
    Join Date
    Feb 2009
    Posts
    5,468

    Default Re: YAFR DataTypeToJson beyond 19.1

    Would a nullable Boolean be a thing? Sounds silly... surely the whole point of a Boolean is that it can only be True or False.


    This brings us full circle

    I actually don't mind if null is supported or not, to me that is a separate question, what I want to know (and I want DF to know) is has a value been assigned to a variable

    So yes unassigned or null for a boolean is needed


    As Stazen says these are two different 'values' in the case of Javascript
    Last edited by Focus; 17-Apr-2019 at 09:40 AM.
    Success consists of going from failure to failure without loss of enthusiasm - Winston Churchill

  10. #10
    Join Date
    Feb 2009
    Location
    UK
    Posts
    826

    Default Re: YAFR DataTypeToJson beyond 19.1

    Hi Mike

    If the language supports NULL then Booleans should also. If NULL then it has not been set, I know how can a binary variable have a third state? But the variable does not have the third state, it’s the “has a value been set” flag that is being changed when a value is assigned to the variable.

    MS SQL keeps a bit map for the columns in each record to indicate if a value has been saved in the column.

    No idea what is happening in Next Gen, but one option would be to implement the “has a value been set” flag for all variables, default it to true and set the value to the current defaults. This keep backward compatibility. We would then need to be able to move NULL to variables to clear the “has a value been set” flag. And a couple of methods to test the “has a value been set” flag, IsNULL and IsNotNULL. (I would like both – saves on parenthesis).

    You need to try and stop thinking of NULL as a value and think of it as a “has a value been set” flag. Took me some time to do this...
    Ian Smith
    (Member of the SigCj project)

Page 1 of 5 1234 ... LastLast

Posting Permissions

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