Discord
Login
Community
DARK THEME

"1" + "2" = "12", but "1" - - "2" = 3

I hope it helps ;)

Haha, nice find!

good to know :)

String and number types in microScript are inherited from the same JavaScript types and mostly behave the same way. Including some weird stuff like this!

Having the + operator working to concatenate strings (like in JavaScript) is cool and not cool at the same time, because of the ambiguity you are just pointing, and also because it could be quite a big slow down factor for a future microScript to C transpiler. Sometimes I am thinking of creating a dedicated operator for string concatenation (like | maybe?) and also deprecating the use of + for strings at some point.

What about & as in VB ?

I think that | or & both would work pretty well. You could also do str.join(str1,str2) or something similar.

For a string concatenation op, my biggest preference so far goes to Lua's ... I think it's the least visually cluttering, and it's always right there at your finger-tip (at least in my keyboard), and to my knowledge, it requires no modifier keys on any keyboards (shift, etc). Although, if there's ever gonna be a .. op for ranges, then that may or may not pose a conflict.

While I've been coding in Lua for several years now, whenever I get back to other languages I notice how their concatenators make the code somewhat harder to discern. The + sign is actually not nearly the worse I've seen. That would be the &. Nim uses it, and it's been a peeve of mine. (Although Nim exacerbates the issue by requiring you to clutter the code even more with the $ op to stringify everything). But also because, on my keyboard, & is on shift+6, so my personal experience with typing it hasn't been a breeze. I always miss that key one or two times, every time.

I know this may be quite subjective, though, but those are my personal two cents. I tend to think a lot about these things, because I can be easily annoyed by them, for some reason, and also because I've always wanted to create a language of my own. :)

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community