6 ms·
> Extended characters in identifiers may now be specified directly in the input encoding (UTF-8, by default), in addition to the UCN syntax (\uNNNN or \UNNNNNNN
by MauranKilom 7y ago
> Extended characters in identifiers may now be specified directly in the input encoding (UTF-8, by default), in addition to the UCN syntax (\uNNNN or \UNNNNNNNN) that is already supported:
static const int π = 3;
int get_naïve_pi() {
return π;
}
Lovely!
- q92z8oeif 7y agoi don't know if you are being ironic or not, but the non-english speaking world will love it.
- throwaway894345 7y agoThere are lots of other languages that support full UTF-8 in identifiers (e.g, Go) and the non-English-speaking world doesn't take advantage.
- erik_seaberg 7y agoSome do: https://news.ycombinator.com/item?id=14276891 https://news.ycombinator.com/item?id=14276891
- throwaway894345 7y agoI've done a similar thing when I was writing a language (with generics) that compiled to Go and needed to implement name mangling. But in any case, this isn't an example of a non-native speaker using utf-8 to write in his native language. :)
- rurban 6y agoEvery such such language does it insecurely. The only exceptions are Java, rust and cperl. I rather have no unicode identifiers than insecure identifiers, which don't follow the unicode security guidelines for identifiers.
- alufers 7y agoAs a non-English programmer who has seen a lot of code not written using English please, god, NO. The mixture of English and other languages identifiers in the external libraries makes me cry.
- wiz21c 7y agoYep, writing non english keywords in C++ is like having prolog code inside c++ :-) (but as a non english person, I find it very helpful to be able to have unicode in strings)
- q92z8oeif 7y agothat's fine, keep using english. But do not expect people that do not speak english to learn it if there's an alternative. Someday we might have multilingual frameworks and not restrict programming to the privileged few that could learn a second language. Entitled programers are so into their broculture they can't see their own problems as being socially constructed. On one hand they complain "reading mixed language code is hard, despite me being fluent on both! everyone should speak what is more convenient to me!" without realizing they are leaving billions of people that do not know english out. Then on this very same thread they also complain that "reading math with greek letters is too hard" despite that being an arbitrary rule set in place by the people that used greek and latin knowledge as a way to make their privilege less accessible. The irony is dense! ...don't even get me started on a programmer workers union.
- aspaceman 7y agoI really disagree with the idea that math uses greek letters just to make things less accessible. If you have a better symbol than the large S for an integral, or Sigma for sums, I'd love to hear it.
- wtallis 7y agoPeople who complain about math notation and want something more verbose like programming usually don't fully understand the notation they're complaining about. In particular, there are fairly strong conventions for which letters get used for which purposes. Longer variable names that try to be more descriptive often aren't as necessary as they might seem, and in many cases would make an expression less generic than it really is. And then there's the fact that what's easy to type on a standard keyboard without a specialized IME has little bearing on what notation is most effective for the reader, or for someone writing on paper or blackboard.
- lenkite 7y agoFrom a non-english speaking country: I prefer US-ASCII for code. Anything else just obfuscates.
- MauranKilom 7y agoTbh, I mainly shared the example code because I was entertained by the contrast of sophisticated naming and crude approximation. Still, it illustrates that this can come in very handy if used properly. Of course you can also cause all sorts of mayhem. Even disregarding fun such as GREEK QUESTION MARK looking like a semicolon and zero-width spaces, I probably would not use this feature in enterprise code. Too likely that some tool somewhere (e.g. an alternate compiler?) is KO'd by characters outside of basic ASCII range (which has served us well and will keep doing so).
- asjw 7y agoFor what is worth being able to enforce conventions like present?(p) // return bool get!(g) // throw if not found a-la ruby/elixir could be good
- hinkley 7y agoThe next obfuscated code competition is sure gonna be interesting.
- signa11 7y agoyup zero-width-space is going to a do a number on everyone.