Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Unicode variables, I love it:

let ๐Ÿถ๐Ÿฎ = "dogcow"

Moof!



You can do this in C# (and presumably other languages). I've seen people using Greek symbols in mathy code before. It's kind of fun.


It's fun once. It's impractical for someone editing the code later though, I don't want to have to look up the unicode character each time I want to remember it, and I don't want to have to copy and paste it either, it's better to stick with the characters available on a keyboard.


OS X handles some of this by assigning mnemonics to keyboard keys with the meta key (on mac keyboards, Option, or the "windows" key on the standard layout) held down.

For instance, the registered trademark symbol ยฎ is just option+r. โˆ‘ is option-w. Diacritics are two-stroke combinations, to get รฉ, you'd type option-e, which puts the ยด on the screen, and then type the e to complete the character.

Some of them definitely make more sense than others. โˆ‘ looks like a sideways 'W", the trademark symbol is just a circled r, and the diacritic marks fit the character you'd commonly associate them with. (Guess what letter you hit to get ยจ over a letter?)

Beats copy/pasting out of character map, anyways!


"OS X handles some of this by assigning mnemonics to keyboard trademark symbol ยฎ is just option+r. โˆ‘ is option-w."

And, after they ran out of mnemonics, they sprinkled the rest of the characters on the keyboard (almost; I think they tried hard to keep things memorable, but some combinations are just plain of the "if you don't know it, you 'll never guess". The Apple logo is on the k key, for instance (IIRC). Mnemonic? MaKintosh?)

"Diacritics are two-stroke combinations, to get รฉ, you'd type option-e, which puts the ยด on the screen, and then type the e to complete the character."

That's the old way. Recent OS X has 'hold down the e key, a menu pops up, click the desired variant or type the digit shown next to it'.


Ah neat, I wasn't aware of this. Every mac I use has the press-and-hold mechanic disabled to support a higher repeat rate. I might have to go back and play with it some more.


> Some of them definitely make more sense than others, but it sure beats copypasting out of character map!

Sure, but even making your own keyboard layout beats copypasting out of character map for any characters that you use regularly (and if you switch from US-English to US-International as your base layout, you get a lot characters that aren't on US-English for free without making a new layout.)


except โˆ‘ is an upper-case sigma which corresponds to s in the latin alphabet, so why not option+s ?


I guess it depends what country you're currently in. I know some chinese developers would prefer some chinese characters because it happens to be the ones available on their keyboard.


I have to agree. I had a love affair with unicode put directly in LaTeX markup (delta, integral signs, element-of, etc...) and it was very fun at first. Then I had to send the paper to a collaborator while writing a follow-up article together. I ended up removing all the unicode, and in subsequent work I didn't do it any more.


Why would you want to put math symbols in LaTeX using unicode? What would be the advantage over using a package like amsmath or even the native math environment? I'm genuinely curious.


Because then instead of writing \int, you can have an actual integral sign, etc., and it's more readable.


I won't mind it if the original author also has a comment signifying what unicode character the variable refers to. This will reduce some pain though not all of it.


Bluntly, though, that's a deficiency in your OS user interface or text editor.


I'm stuck doing most of my work in php, so this is kind of neat. (I also like that the example in the text resurrects the famous 30 year old dogcow joke.)


The only practical use is that we can assign functions to a variable named ฮป Or define a type alias to that.

On a more serious note, several languages have that, Ruby included.


It's not entirely useless to be able to use natural-language words/names for variables (if your language happen to not be English). For example when teaching kids how to code, why have proper spelling (eg: naming a "crow", "krake" rather than the proper "krรฅke") be an error? Just adds another barrier to learning.

I think we're approaching the level of unicode penetration that this shouldn't really be much of a problem.

Incidentally, I think this will be much more useful in Japan and possibly parts of China than in the parts of the world that speak an indo-european language (and therefore has an easier time learning English).

But, those areas that doesn't speak native English is of course just a small market. /s


I've only seen one thing actually use it in Go:

    	func Polar(x complex128) (r, ฮธ float64) {
    		return Abs(x), Phase(x)
    	}
    
It seems to be good for documentation reasons.


This should make for interesting entries in upcoming IOS (International Obfuscated Swift) competitions.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: