-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add "unusual Julia features" section in the manual noteworthy diffs. #11966
Comments
That particular example does bear distinguishing, julia is great in allowing Unicode, and using Unicode, |
"unique" is a strong word - for essentially any feature you can find an example of it having been done before somewhere, Julia's not really about treading new ground in terms of individual unique language features but rather synthesizing a compelling set of features in new combinations. |
@tkelman @JeffBezanson What's your opinion on using a Unicode "Mathematical Operator" class character (0x2200-0x22ff) as part of a julia variable name? |
@ScottPJones that doesn't seem bad at all to me: julia> x² = 5
5
julia> x = sqrt(x²)
2.23606797749979
julia> with_rounding(Float64, RoundDown) do
x² == x^2
end
true
@tkelman yes that's what I meant! Things like:
From Wikipedia:
How could I rephrase it? [pao: fix CLisp in table] |
@ScottPJones this is another advantage: julia> with_rounding(Float64, RoundDown) do
@time (x^2 + x^2*x^2) / (x^2 - (x^2)^(x^2))
end
3.688 microseconds (15 allocations: 320 bytes)
-0.009615384615384616
julia> with_rounding(Float64, RoundDown) do
@time (x² + x²*x²) / (x² - x²^x²)
end
2.603 microseconds (7 allocations: 192 bytes)
-0.009615384615384616 More performant and also more readable IMHO. |
Is this a bug? julia> with_rounding(Float64, RoundDown) do
@show x² == x^2
@show x², x^2
println()
@show x²*x² == x^4
@show x²*x², x^4
end;
x² == x ^ 2 = true
(x²,x ^ 2) = (5,5.0)
x² * x² == x ^ 4 = false
(x² * x²,x ^ 4) = (25,25.000000000000004)
julia> x²*x² == round(x^4)
true |
This julia> xˆ2 = round(x^2); xˆ2 == x²
true
julia> Int('ˆ'), Int('^')
(710,94) |
@Ismael-VC I'm not saying that you shoudn't use an variable to store |
@ScottPJones you keep mentioning the "postfix square operator", but no character of this description exists in the mathematical operators block of Unicode characters. What you are actually seeing is U+B2 in the Latin-1 block, which is semantically a superscript digit 2 (official Unicode name SUPERSCRIPT TWO) and not an operator. |
@ScottPJones Being able to write |
I'll give you my Unicode variables when you can pry them from my cold, dead hands. |
Unicode variable names are staying. That's not really up for debate, so let's mellow this conversation out. |
@jiahao, that is somewhat for historical reasons, they were already in Latin1 before Unicode existed. |
@rsrock I didn't say anything at all against being able to write |
Nevertheless,
In the LJ example I gave, I had to compute a lot of different powers other than squares. I have yet to find a compiler smart enough to figure out the optimizations needed for that case, like the fact that computing the intermediate inverse square allows one to build a common subexpression tree. The naming of things like |
Can we stop with the "confusion" argument ? In that case the confusion is extremely simple to solve (and thus not "dangerous" at all) : just paste it in the REPL. Every choice like this will induce some bounded form of confusion on some class of people, what we should instead aim for is not to have confusing and subtle things in the language. |
@ScottPJones But that's exactly the point, and probably what you're missing here. I don't want |
@Ismael-VC please see JuliaStrings/utf8proc#11 for a discussion of possibly canonicalizing all visually confusable characters to the same canonical form. |
If you see |
There are variables in a number of domains that legitimately have a superscript 2 as a part of their identity: the (I'm not a huge fan of the sqrt symbol, myself.) |
@pao That's the first good reason I've heard for having it as part of a name. |
@ScottPJones I expect it to be a variable, like below. This is equivalent to the use of
Before the change that allowed this, I had (By the way, I know you said nothing about |
Strange? Sure. "Doctor, it hurts when I use this identifier." There is a natural tension between trying to make style uniform (on this end of the spectrum, Go, where you code fails to compile if it's stylistically invalid) and allowing users to do things that may make sense in context but are dangerous in others. So far, Julia has been mostly designed along a "consenting adults" principle, and you aren't prevented from doing dumb things. When you hit technical computing, you start to get users who have a preferred notation. I learned a notation for kinematics/dynamics that requires a left superscript, a right superscript, and a right subscript. Even Julia doesn't give me that much notational flexibility! And when I compare what I implement on my computer with what I have in my notes, I have to translate, which makes it easier to introduce errors between what the math says and what I'm computing. There are a lot of applications for Julia where allowing an idiosyncratic notation will be valuable. This code may be seen by only a few people, or people working in a particular domain. If you are working in a bigger group, or a more disparate group, or aren't doing things where this is valuable--no one will prevent you from putting your own house style rules in place. (For those keeping score at home, yes, my opinion on Unicode-characters-in-code-related issues has changed drastically over the past couple of years.) |
OK, I hope people understand why I raised this as an issue, which I think definitely needs to be pointed out in @Ismael-VC's documentation section, as something that would definitely be confusing to people not coming from a technical computing background. As my background has been in software engineering and computer languages, followed by decades in an industry where confusability leading to bugs can literally lead to life or death situations, I always like things to be as non confusable as possible. |
Sure thing-- it's absolutely a valid point, and a valid discussion that followed. One of the things that makes Julia so great is that all of these angles are considered. One other thing to keep in mind here. When my code crashes, it doesn't kill anyone. Instead, it's part of an experiment, and is constantly in flux. I appreciate language elements that make such changes easier. That's why some practices that would be horrific in your earlier experience are desirable, even necessary, in the technical computing arena (necessary, within reason, of course). On Jul 1, 2015, at 12:00 PM, Scott P. Jones <notifications@git.luolix.topmailto:notifications@github.com> wrote: OK, I hope people understand why I raised this as an issue, which I think definitely needs to be pointed out in @Ismael-VChttps://github.com/Ismael-VC's documentation section, as something that would definitely be confusing to people not coming from a technical computing background. As my background has been in software engineering and computer languages, followed by decades in an industry where confusability leading to bugs can literally lead to life or death situations, I always like things to be as non confusable as possible. — Ronald S. Rock, Jr., Associate Professor |
Maybe this is something a Lint option could check. |
Note that we also allow superscript parens, which are commonly used in identifiers in mathematics in combination with superscript letters or numbers or ± signs. e.g. Anyway, this entire issue seems to have gone off the rails into an unrelated argument over what characters should be allowed in identifiers. Wasn't this about documentation? |
By that principal, for consistency, it would seem you would have wanted also |
@ScottPJones, it would be helpful if we could keep issues focused. Open separate issues (or comment on existing relevant issues) if you want to enhance Lint (e.g. to warn about superscripts, or by warning about usage of two variables that are NFKC-equivalent in the same scope), restrict usage of super/subscripts, canonicalize (or warn about) confusables (see also JuliaStrings/utf8proc#11), or to allow This issue was supposed to be about (potentially) documenting a short summary of features that are unique to Julia, not about debating endlessly whether those features are a good idea. |
@stevengj I will certainly do this, I'm waiting for more material to come in order to document a good chunk of info at once. I already have several good examples of unicode identifiers. What other languages use staged functions? I'd like more examples of peculiar if not unique julian features. |
@stevengj This particular issue was opened precisely to discuss this and other similar issues, where Julia was different from most languages, because I noted the inconsistency in #11927 (comment), as referenced in the opening comment. I also never proposed julia> cube(x) = x³
cube (generic function with 1 method)
julia> cube(3) # Silly me, I think I'll get 27
ERROR: UndefVarError: x³ not defined
in cube at none:1
julia> x³ = 42
42
julia> cube(3)
42 And also things like this: julia> y = div(typemax(UInt),3)
0x5555555555555555
julia> z = typemax(UInt)/3
6.148914691236517e18
julia> Int(y)
6148914691236517205 Because of the |
Thank you, Oscar. Let's call this "unusual features" – "unique" is too strong, "peculiar" sounds too negative. |
@ScottPJones, this was discussed previously – before you were around. The current behavior was agreed upon and people who use reason to use this kind of mathematical notation a lot like it. There's no compelling reason to revisit that decision, despite your misgivings. Feel free to document it, however. |
@ScottPJones ...empty your cup of 🍵 I know I had to do it (coming from Python) when I started watching MIT 6.001 Structure and Interpretation in order to learn Scheme, in order to learn Lisp like macros, in order to learn Julia macros, staged functions ...and beyond! (still stuck there) Maybe I don´t have many years of programming experience like you all do (and everyone started from scratch at one point), but the little that I do have right now, has cost me a lot of effort. Julia being relatively new and radical in may aspects is of course going to be misunderstood quite often (which is why I'm trying to help diminish that). But I would at least expect that the other people interested in Julia also study how to use it (I'm not expecting that they also study how it works, like I'm also doing). If they don't have the common sense to do this or the will to exercise their effort and they simply expect that it should just work like x or y thing that they already know ...then they are free to shoot themselves in their feet for all I care.
And what about the millions of future programmers that are out there! ...yet to be tainted by anything non Julian? |
@StefanKarpinski thanks! unusual it is then, my english is not that good to tell the difference. |
@StefanKarpinski I wasn't asking to change that particular issue, and I had read some of the long ago discussions, but that is exactly the sort of thing that belongs in the proposed "unusual Julia features" documentation. They don't belong in the "differences between Julia and C/C++", or some other section, because they are different from most if not all languages out there. |
@Ismael-VC Agreed, but in order to save them valuable time, they need something to study, which is precisely why I wrote the "Noteworthy differences between Julia and C/C++" section, and why we need to determine what unusual features in Julia people are stubbing their toes on already, or are likely to in the future, and at the very least, get them well documented in the section you have nicely proposed.
Well, I don't know if you would consider my children "tainted" by Lua, I think that's a very fine little language, but I'm spending a bit of time each day this summer teaching them Julia, to hopefully save them from C++ hell! |
@ScottPJones that's what I've been talking about all this time! I believe no one disagrees to document it.
That's great! Also learn from them! You could show them the pros of using unicode ( After that you could let them use it in more and more examples and then after all that show them the cons (if they haven't find them yet) and the alternatives ( |
@ScottPJones, this issue was opened to document unusual features of Julia. Can't you see that turning it into an open-ended discussion of what identifiers should be allowed and what warnings should be raised is a mite off-topic? Having a long unrelated (or marginally related) discussion thread in any issue makes life harder for everyone trying to follow Julia development. |
At this point I'm inclined to just close this issue and @Ismael-VC can open a fresh one in order to increase the signal-to-noise ratio. |
@stevengj No. If something is unusual enough from most all other languages that it needs to be specially documented, it deserves at least a little time to discuss whether or not it actually is needed in the language, and if so, what else, besides documentation, can be done to preserve the sanity of people coming new to Julia. |
This is the wrong issue for that discussion. Please don't hijack issues that are not about changing the language in order to focus on your preferences for changing the language. |
@stevengj I haven't said anything about changing the language (except giving warnings) for most of this discussion, ever since @pao's comment. I've only been thinking of ways of decreasing the possibility of confusion among programmers new to Julia, by documentation or other means (not everyone reads all of the documentation). |
Yes, examples to document these points would be great. Please open a PR to start with any you can think of. This issue has gone down a rabbit hole and does not need to be kept open.
Please heed this advice. This was supposed to be a request for other examples, and it's instead become an overly long discussion about unicode in identifiers that belongs on the mailing list. Open-ended questions that aren't directly addressing the current issue or PR don't belong on the bug tracker. |
julia> julia ≡ :👽
true |
Reference:
primes
performance. #11927 (comment)Some things in Julia doesn't compare to anything else, help me list those things so I can document them!
x² = x*x
. (more examples of this)The text was updated successfully, but these errors were encountered: