Re:Hello, I’m Mr. Null. My Name Makes Me Invisible to Computers
by gtf21 on Sunday September 04, 2016 @05:38PM
(#12426851)
I've seen this in code I've reviewed before, where people will check for `== "empty"` instead of just using types like `null` which were designed for this (in javascript).
[ Parent
| on HN ]
Re:Hello, I’m Mr. Null. My Name Makes Me Invisible to Computers
by kqr on Monday September 05, 2016 @01:04AM
(#12428224)
A practise that may come from some shell scripting languages where `[ $x == "" ]` is an invalid command because empty strings aren't strings.
Re:Hello, I’m Mr. Null. My Name Makes Me Invisible to Computers
by _kst_ on Monday September 05, 2016 @04:24AM
(#12428893)
That may be true in older shells, but in modern shells [ $x == "" ] is valid, and "" is a single token whose value is the empty string. But I've seen old code that does things like
if [ x$x == "x" ] ; then ...
apparently because it was necessary at one time.
Re:Hello, I’m Mr. Null. My Name Makes Me Invisible to Computers
by kqr on Saturday September 17, 2016 @02:23PM
(#12521692)
It depends on what you mean by "older" shells. More modern shells tend to support this properly, but the baseline for most shell scripts is /bin/sh which is not guaranteed to be modern – it is often a new release of Sh.