bigskysoftware / _hyperscript

a small scripting language for the web
BSD 2-Clause "Simplified" License
3.14k stars 149 forks source link

PROPOSAL: & and && operators #120

Closed benpate closed 3 years ago

benpate commented 3 years ago

The original HyperTalk used & for string concatenation, and && for string concatenation with a space in between. This would be really useful, and would help avoid statements like this set fullName to firstName + " " + lastName -- changing them into this instead set fullName to firstName && lastName

Right now, hyperscript uses && as a logical AND operator, and we should not change this. But, would it be possible (and not too confusing) to overload this behavior when dealing with two strings? Or, would it be better to use a different operator for this?

1cg commented 3 years ago

I wonder if we should drop && and just go w/ what hypertalk did

benpate commented 3 years ago

The trouble here is that && is so common to most modern developers that its second nature to use. You'll have tons of cleanup to do even in the hyperscript examples.

But, I can't imagine anyone is already using && with strings, so it seems like it should be safe to overload this operator.

dz4k commented 3 years ago

People definitely use && with strings.

if (options.prefix && options.selector) {
  // check the existence of prefix and selector, which are both strings
}
benpate commented 3 years ago

That's a fantastic example, @dz4k. It would require a small change to make your code above work correctly. If we adopted this syntax for string concatenation, you'd have to say if options.prefix and options.selector then... instead.

I think this is a cool idea, but it would only work if we're okay with removing (or confusing) support for the javascript && operator. I'll leave that decision for the big boss, but my first thought is that it may not be worth the confusion.

dz4k commented 3 years ago

http://rigaux.org/language-study/syntax-across-languages.html#StrngStrnCnct

AFAIK ^ isn't used for anything as of now.

P.S. Is this really necessary when template literals exist?

benpate commented 3 years ago

True. It's probably more trouble than it's worth. Let's just close it :)