use "" as an array key

Matt Maier blueback09 at gmail.com
Sat Sep 24 02:22:51 EDT 2016


Thanks for explaining that gotcha in detail.
I've had a few problems before when I relied on the 99% awesome debugger
and variable watcher only to find out that it wasn't showing me the many
characters that exist, and affect code, but are technically invisible.

On Sat, Sep 24, 2016 at 6:26 AM, Kay C Lan <lan.kc.macmail at gmail.com> wrote:

> On Fri, Sep 23, 2016 at 2:27 AM, Peter TB Brett
> <peter.brett at livecode.com> wrote:
> >
> > "" isn't "the absence of a string", it's a string that's 0 characters
> long.
> > Being able to use it as an array key is important for being able to
> > represent real-world data in an array.
>
> It's an important point that "", a 0 character string is not the same
> as NULL because we as humans often 'see them' as the same.
> Unfortunately one of the great features of LC, the fact it's typeless
> and it auto converts integers/strings/dates back and forward as we
> need them, also means that occasionally it makes the same mistake we
> make:
>
> In the msg box - 8 lines all ending with msg:
>
> put "empty = " & quote & quote & " is " & (empty = "") into msg
> put cr & "empty = NULL is " & (empty = NULL) after msg
> put cr &  "navtiveCharToNum(empty) = " & nativeCharToNum(empty) after msg
> put cr &  "natvieCharToNum(" & quote & quote & ") = " &
> nativeCharToNum("") after msg
> put cr &  "nativeCharToNum(NULL) = " & nativeCharToNum(NULL) after msg
> put cr & "Therefore:" after msg
> put cr & "navtiveCharToNum(empty) = nativeCharToNum(NULL) is " &
> (nativeCharToNum(empty) = nativeCharToNum(NULL)) after msg
> put cr & "So although an empty string is NOT the same as the NULL
> character, in some cases LC treats them the same" after msg
>
> or to put it another way, "" and empty do not roundtrip
>
> In the msg box:
>
> put numToNativeChar(nativeCharToNum(empty)) = empty  --returns false
>
> When dealing with databases, tracking the difference between NULL and
> empty and "" can be a real pain. Is this a feature or a bug? To me the
> advantages of 'typeless' far outweigh the 0.001% of times I hit this
> gotcha.
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



More information about the use-livecode mailing list