I've been a professional C, Perl, PHP and Python developer.
I'm an ex-sysadmin from the late 20th century.
These days I do more Javascript and CSS and whatnot, and promote UX and accessibility.
This is something you see a lot when stringing shell commands together.
mkdir my_directory &&cd my_directory ||exit(1)
This way of using && before running a function (or command) and calling it a "guard operator" makes it seem like it's not what it actually is (an expression).
It gets a little odd when you try to do things that seem to make sense on the face of it, like use an assignment instead of a final expression:
foo={};foo.bar||"hello";// "hello"console.log(foo.thisworks="hello")// "hello"foo.bar||foo.bar="hello";// Invalid left-hand side in assignmentfoo.bar&&foo.baz="hello";// Invalid left-hand side in assignmentfoo.bar&&(foo.baz="hello");// "hello"
And it can be tempting to string too many of them together and make quite a confusing line.
I prefer to be explicit, and to dive out if the condition isn't met:
This is something you see a lot when stringing shell commands together.
This way of using
&&
before running a function (or command) and calling it a "guard operator" makes it seem like it's not what it actually is (an expression).It gets a little odd when you try to do things that seem to make sense on the face of it, like use an assignment instead of a final expression:
And it can be tempting to string too many of them together and make quite a confusing line.
I prefer to be explicit, and to dive out if the condition isn't met:
Maybe 'Gate' would be a better word?