5 ms·
The URL https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... is al
by sillysaurusx 5y ago
The URL https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... is also close to valid code as an expression.
Consider something like:
foo ? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label
I was hoping that was where the post was going with this :)
Sadly, JavaScript doesn't have the // operator (floor division) so it doesn't quite work. And double-sadly, I can't think of a language that has all the necessary ingredients; Python uses `and` and `or` for trinary syntax, not ? and :, and besides, you'd need to be able to overload the // operator as unary rather than binary, which ... well, I'm not sure we'd want a language to be able to do that. But I do!
Still, if you want to confuse your coworkers, consider sneaking in something like:
developer = {mozilla: 42}
en = US = docs = web = Web = JavaScript = Reference = Statements = label = 420
console.log(developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label)
and be sure to hand in your resignation after pushing the commit.
- valenterry 5y agoScala can do it, except for // starting a comment, so it would have to be foo ? https:/developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label which of course isn't as cool. Still pretty close though.
- eru 5y agoShould work in Haskell. You can add your own operators there.
- whateveracct 5y agoCould probably make it actually valid Haskell too, not just syntactically
- eru 5y agoYes, definitely. You would just have to define all those variables and operators. You could very probably even make it evaluate to the right URL in the end.
- bryanrasmussen 5y agoeveryone loves MDN, surely you should only resign after commiting w3schools?
- lmilcin 5y agoFor you young people, there is one language which is called "executable line noise". This is valid Perl code syntactically, except Perl complains of invalid or incompatible regexp modifiers. So, if you chose the characters carefully an url like that could be executable in Perl (but not this one or urls in general).
- chrismorgan 5y agohttps://www.mcmillen.dev/sigbovik/ https://www.mcmillen.dev/sigbovik/: “93% of Paint Splatters are Valid Perl Programs”
- draegtun 5y agoI don't think you can make that or any URL into valid syntactic Perl code. But maybe you're thinking of this - https://metacpan.org/pod/Acme::URL https://metacpan.org/pod/Acme::URL use Acme::URL; print https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label;
- BerislavLopac 5y ago> Python uses `and` and `or` for trinary syntax A nitpick: Python uses `if` and `else` for trinary syntax: a = foo if bar else baz
- bionoid 5y agoPython also has "shorthand ternary" which uses and/or: a = bar and foo # "or None" is implied b = bar and foo or baz It does almost the same but not quite. In the latter example, if foo is falsey, it evaluates to "b = baz": b = bar ? (foo ? foo : baz) : baz
- Asraelite 5y agoIs this official, encouraged syntax? It looks like it's just exploiting short-circuit evaluation. `bar && foo || baz` works in Javascript as well for example.
- eesmith 5y agoNo. In fact, nearly 20 years ago PEP 308 ("Conditional Expressions") was made so people wouldn't need to resort to this sort of syntax - https://www.python.org/dev/peps/pep-0308/ https://www.python.org/dev/peps/pep-0308/ . Quoting from the Python FAQ from 2.6 at https://web.archive.org/web/20151030070641if_/https://docs.python.org/2.6/faq/programming.html#is-there-an-equivalent-of-c-s-ternary-operator https://web.archive.org/web/20151030070641if_/https://docs.p... : > In many cases you can mimic a ? b : c with a and b or c, but there’s a flaw: if b is zero (or empty, or None – anything that tests false) then c will be selected instead. In many cases you can prove by looking at the code that this can’t happen (e.g. because b is a constant or has a type that can never be false), but in general this can be a problem. > Tim Peters (who wishes it was Steve Majewski) suggested the following solution: (a and [b] or [c])[0].
- bionoid 5y agoI have seen it a lot of code over the years, sometimes referred to as "shorthand ternary" or the "and-or-trick". In Python and/or do not return a boolean, but one of its input arguments. So I am going to say it is official syntax, but I don't know to what extent it's encouraged
- callmeal 5y agoShouldn't that be : developer = {mozilla: {org: 42}} ?
- lifthrasiir 5y ago`{mozilla: 42}` is enough because the goal is not to prevent NaN (arising from converting `(42).org` to a number).