5 ms·
I may be wrong, but one of the benefits of NOT allowing hyphens in names in languages like JavScript is code can be minified (you can remove spaces and use oper
by abhinav22 6y ago
I may be wrong, but one of the benefits of NOT allowing hyphens in names in languages like JavScript is code can be minified (you can remove spaces and use operators as delimiters, which only works if “-“ only stands for subtraction).
I think. Haven’t verified this, but the thought came to my head the other day.
- colonwqbang 6y agoThere is not a great need to minify many languages other than Javascript. The way I see it, the need arose mainly because it took such a long time to agree on a bytecode representation of JS. I would say that Javascript was not at all designed to be delivered the way that it is. The design characteristics of JS that allow minification, I think are just happy coincidence. Consider that Javascript early on was marketed as a companion to Java (applets). Java, of course, used a bytecode representation to deliver programs on the Web from square one. If Javascript had been designed for efficient delivery of "compiled" programs, bytecode would have been the obvious choice. I think my point is, languages are not generally designed to minify well, because minification is the technique of last resort for efficient delivery.
- abhinav22 6y agoThanks - this helps expand my knowledge on this topic :)
- tsimionescu 6y agoI think a much bigger consideration would be the utter difficulty of reading something like this: a-b - a - b Even though I personally love hyphenated-identifiers in Lisp, I would not want them in any language that has infix operators, whether it cares about minification or not.
- kazinator 6y agoThat could be English written in ASCII, with the same hyphen serving as a dash: Example sentence: "Examples of sado-masochism - such as Java-influenced languages - are rampant in the field of computing." Quite readable.
- deleted 6y ago[deleted]
- abhinav22 6y agoI think it’s getting used to it, for example I would never confuse a-b with a - b, but that’s because I’m used to using hyphenated identifiers. I can see others (beginners) getting confused, but it’s something they will very quickly get over. For example I didn’t know JavaScript was case sensitive, but it was a very quick adjustment when I learnt this
- lispm 6y agoIn some infix syntax, one might then need to escape characters. Example 'infix' for Common Lisp: (let ((foo-bar 29)) #i( foo\-bar - 3 * foo\-bar ))
- Jach 6y agoI refer to long symbol names a lot more often than I subtract things. If I could have it in Python or Java I'd be happy, using - is just nicer than _ or camelCase. Using spaces in pipes |like this| is nifty sometimes too. I'd be willing to accept warnings/compiler errors on the seemingly never-in-practice occasion when the compiler notices that all 3 of 'a-b, 'a, and 'b are bound symbols and I need to use a more explicit expression (like the escaped '- in lispm's example, which is how the cmu-infix library solves the problem). On the other hand, some advice from Chuck Moore (found in Thinking Forth) that I think about sometimes: "There are diverging programming styles in the Forth community. One uses hyphenated words that express in English what the word is doing. You string these big long words together and you get something that is quite readable. But I immediately suspect that the programmer didn’t think out the words carefully enough, that the hyphen should be broken and the words defined separately. That isn’t always possible, and it isn’t always advantageous. But I suspect a hyphenated word of mixing two concepts."