What are the advantages of allowing unicode characters as variable names in Swift?
-
From Apple's book for Swift Programming Language. You can use almost any character you like for constant and variable names, including Unicode characters: let Ï = 3.14159 let ä½ å¥½ = "ä½ å¥½ä¸ç" let = "dogcow" Were there any reasons besides legacy reason for other languages to not allow it? Is there any advantage of unicode characters in Swift?
-
Answer:
This is a question of notation, so I have to warn you my answer will be subjective to say the least. Programming is not just about getting the machine to do things for us. Arguably, it's about meaningful representations of problems and our solutions to said problems. Naturally, we need reference points like variables to keep ourselves sane while programming. After all, I'm not sure of any programming language in use today that approaches pure data (aside from binary, but you'd have to be stark raving mad!). A well-established convention is that meaningful variable names contribute mightily to meaningful programs. It's no wonder C programmers get teased for single-letter variable names and relentless shortening of function names: Given no context, you couldn't tell what the thing was even supposed to be doing. The same thing applies to companies not using English. Programs written by a firm exploiting Unicode for Tamil are going to be absolutely unmaintainable when handed to somebody who speaks basically any other language. (Sidenote: the same is true when talking about english's stranglehold on programming). So I'll add another component to this discussion: Context. Context is huge when programming. Context is why we can look at functions and intuit what they do. There is some basic assumption when reading code that you know the language, know what the code is supposed to do, and most importantly how it's accomplishing it. Miss any one of the three and you're just reading dense gibberish. But context for programming is very different from context in, say, mathematics, where terse notation is the wit and soul of the field. Unicode variables are the norm when dealing with formulae, and we've come to even expect them when reading papers or solving problems. When a mathematician gets into programming, the context they carry with them is years of working with these symbols and giving strict definitions to these symbols, not writing out strings of english characters. It's almost ridiculous to write lambdaAbstract(x, returning: y) when you also have λx.y The beauty and tenseness of the latter expression is light years ahead of the former. But compactness only makes sense here because the symbols have a well-defined meaning. Showing this to anyone with no working knowledge of the λ calculus would cause them to run away screaming. And so we have to be careful using Unicode variable names and realize that they apply to a wider audience than just our own projects. tldr; Unicode variables allow for a greater ease of internationalization, but chiefly they're meant for terseness and the proper shortening of well-defined operations.
Robert Widmann at Quora Visit the source
Related Q & A:
- What are the advantages and disadvantages of fossil fuels?Best solution by Yahoo! Answers
- What are the advantages and disadvantages of digital voltmeters over the analogue voltmeters?Best solution by Yahoo! Answers
- What are the advantages and disadvantages of animal testing?Best solution by ehow.com
- What are the advantages and the disadvantages of using fossil fuels?Best solution by Yahoo! Answers
- What are the advantages of the amniotic egg?Best solution by ask.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.