10 ms·
Having to do math and physics heavy work, I very much support the "fad" of having Unicode literals. "omega_0" is much worse than "ω_0" especially if you have to
by sharikous 5y ago
Having to do math and physics heavy work, I very much support the "fad" of having Unicode literals. "omega_0" is much worse than "ω_0" especially if you have tons of these variables.
If you don't do math it's difficult to understand, but try writing without the alphabet and expressing the same concepts. Possible but clunky
- azalemeth 5y agoI respectfully disagree with this. I do a lot of maths-heavy work, but for me in languages (not Julia!) being able to quickly write the LaTeX names for symbols is more than enough. It's also much quicker, and easier to search for when reading someone elses' code. I personally find it also helpful to make the distinction between the maths and its implementation, though I accept that others would vehemently disagree iwth me.
- vicek22 5y agoMaybe there could be a middle ground. For math-heavy applications, the editor could implement ligatures same as Fira-Code and the latex name would render as the symbol until you put a cursor on it.
- IlliOnato 5y agoIt makes it easy to type, but does it make it easy to read/maintain? As they say, it's already way too easier to write code than to read it. A programmer should make every effort to make code more readable. An editor should make it relatively easy to enter special symbols (especially if you can specify a limited set); it is totally solvable problem. An editor can only help you so far with reading code...
- kaba0 5y agoI believe it is most definitely easier to read/maintain -- restricted to that small domain-specific function. Some greek letters have very specific meanings, replacing them with long-ass names straight up worsens readability. Writing out density, velocityX, etc will quickly fade the core logic of that function.
- brandmeyer 5y agoI don't think that there is a single example of a greek letter which has been universally adopted by all of the different engineering and mathematics communities to have a single non-overloaded meaning. The use of greek letters in academic writing has a single purpose: Compact notation. It has nothing to do with abstract readability.
- astrange 5y agoGreek letter abuse rarely happens in CS but there are a few cases. Try to guess what "lambda calculus" and "pi calculus" are without looking them up.
- wtallis 5y ago> The use of greek letters in academic writing has a single purpose: Compact notation. It has nothing to do with abstract readability. The compactness of the notation is a major factor in overall readability. Long variable names make it harder to see the overall structure of an expression. When operators, numerical constants and parentheses mostly are represented with one or two characters each but variable names are all much longer, then the only thing you can tell about a long line of code at first glance is what variables it uses as inputs. Mathematical pretty printing can help with some operators (eg. fractions) and make it more visually apparent what's being grouped together by parentheses, but even then long variable names will still detract from the ability recognize the structure of an expression.
- azalemeth 5y agoFor me, the biggest problem with the whole maths ---> code mapping is that of nested brackets. For a random quick example, I mean things like (a*(1+exp(1i*theta[0,:]))+foo(x))/((b-cosh(bar(x))+(b+sinh(y[:,-1])). The sort of thing where it just _looks_ far nicer on a page with like _real fractions_ -- where missing a bracket or changing the order of two brackets can _totally_ bugger you. Yes, changing the form of the expression a bit can make it "far nicer" or simpler -- for example, by defining intermediate terms -- but sometimes there's something to be said for <expression x> matches <equation y> in the paper. Another example where I think ASCII actually _is_ limiting is for entries of matrices directly. I mean, we try, but I'm not convinced we succeed. For an example (picked at random), hands up if you think this is a nice Euler angle transformation, where cphi/sphi etc are the cosine and sine of phi? No matter how you write it, it's going to be ugly. alpha = [cpsi*cphi-ctheta*sphi*spsi cpsi*sphi+ctheta*cphi*spsi spsi*stheta; -spsi*cphi-ctheta*sphi*cpsi -spsi*sphi+ctheta*cphi*cpsi cpsi*stheta; stheta*sphi -stheta*cphi ctheta];
- a1369209993 5y ago> a nice Euler angle transformation I'd probably go with something like: double cf = cos(phi),sf = sin(phi); double cp = cos(psi),sp = sin(psi); double ct = cos(theta),st = sin(theta); alpha = [ cp*cf-ct*sf*sp cp*sf+ct*cf*sp sp*st; -sp*cf-ct*sf*cp -sp*sf+ct*cf*cp cp*st; st*sf -st*cf ct]; but I agree it would look better with: alpha = [ cψ*cϕ-cθ*sϕ*sψ cψ*sϕ+cθ*cϕ*sψ sψ*sθ; -sψ*cϕ-cθ*sϕ*cψ -sψ*sϕ+cθ*cϕ*cψ cψ*sθ; sθ*sϕ -sθ*cϕ cθ]; Either way, I don't think Euler angles are ever going to be "nice".
- b2gills 5y agoIn Raku you can also use × (U+D7) for multiplication # this assumes that ϕ, ψ, and θ have already been set my \cϕ = ϕ.cos; my \sϕ = ϕ.sin; my \cψ = ψ.cos; my \sψ = ψ.sin; my \cθ = θ.cos; my \sθ = θ.sin; my \alpha = [ cψ×cϕ−cθ×sϕ×sψ, cψ×sϕ+cθ×cϕ×sψ, sψ×sθ; −sψ×cϕ−cθ×sϕ×cψ, −sψ×sϕ+cθ×cϕ×cψ, cψ×sθ; sθ×sϕ, −sθ×cϕ, cθ]; I'm not sure if using × helps or hurts in this case since I'm not really experienced in this area. These all work because Unicode defines ϕψθ as "Letter lowercase" say "ϕψθ".uniprops; # (Ll Ll Ll) --- I would like to note that I used the Unicode "Minus Sign" "−" U+2212 so that it wouldn't complain about not being able to find a routine named "cϕ-cθ". (A space next to the "-" would have also sufficed.)
- zelphirkalt 5y agoI disagree. Instead of writing one letter variable names, one could do the hard work of naming things properly, which software developers often do. Instead of going with one letter or the name of that letter as variable name, which tells your fellow non-mathematicians exactly nothing about what it contains, one could put in the effort and make the code readable. Using these one letter variables forces the reader of the code to either be already familiar with the concept, which that letter refers to, or keep the whole calculation in their head, until the final result, to hope, that they then can make sense of it. It is implicitly requiring outside knowledge. It is shutting out many potential readers of the code. It might still be saved/helped though, if good prose comments are given, that help the reader understand the meaning of the one letter symbols. Whenever I have seen this one letter code salad, I have seen few if any comments, as if the author of the code expects me to magically know, what each symbol stands for. Lets say omega was a vector of weights. Why not name it "weights"? That is much better naming than "omega" or that character, that most cannot easily input and need to copy paste from somewhere.
- geraneum 5y agoWell yes, clarity and good practices can definitely help but to be fair, software developers might often do this: (_ < 5) Instead of this: (e: Int) => (e < 5) It’s just a trivial example so I understand if someone wants to have the same comfort. I am not a mathematician so I am not sure what is best here so I’d cut them some slack.
- kaba0 5y agoMathematicians have been thinking about nomenclature for a long time - certain fields have very specific usage of symbols. I see no evil in using these well-known one-letter variables in these rare/small parts of functions.
- taeric 5y agoSorta. Examples abound of notation that had changed or that is adapted for some fields. Complex numbers using j instead of i, for example.
- 5y ago
- scrollaway 5y agoA variable named ω is no better than a list named l. Both are bad. Be explicit. Terse, but explicit.
- drdec 5y agoPart of the problem here is that a variable in mathematics is a different concept from a variable in programming. Mathematicians are used to using one letter variables. Using a set of unwritten naming rules, mathematicians almost always know what concepts the variables are referring to (in a mathematical context). So, I'd say if the code is only to be maintained by mathematicians, one letter variables for mathematical concepts only, would be an advantage. The danger comes when you start using them for everything.
- nanis 5y ago<disclaimer>Not a mathematician, but took enough Ph.D. level classes to be dangerous with bad proofs.</disclaimer> > Using a set of unwritten naming rules Simplest being things like using upper case Greek for certain sets and lower case Greek for its elements. Or, in Statistics, using Greek letters for parameters and English equivalents for their estimates. So, if I were programming something to do something in that realm, I would write: for my $ω ($Ω) { # ... } where what Ω represents would be clear from the subfield of Math that is relevant to the program. Then, of course, you get people like one of my former professors who liked to invent notation on the fly and would quickly and up cycling through Greek (π, Π), Hebrew (פ), Blackboard (ℙ), and reach out for Sanskrit (?). (Symbols used here for illustration, this was a long time ago and we didn't even know if he was correct as we had no way of checking with no intarwebs back then.)
- Quekid5 5y agoI'm also under the impression that mathematicians generally work much more deeply with a smaller set of variables, so you actually don't need to name that many individual concepts. A typical program contains thousands and thousands of "named things", so you're naturally going to see a proliferation of names. That just doesn't seem to be that necessary in math once you're working in a particular context (e.g. statistics).
- eterevsky 5y agoI have a degree in math and I disagree with this. ω_0 definitely looks better than omega_0, but it is much harder to enter unless you have a special keyboard setup. Suppose you write a function that uses a variable ω_0, and somebody else wants to change it. Unless they have the same keyboard setup as you, they will have to just copy-past it everywhere. And what if you have several variable with special names?
- leephillips 5y agoYou don’t need a “special keyboard setup”. Linux with X11 can do this out of the box. Add a line to your xmodmap file to put the dead Greek key where you want, and you’re done. I type ω by tapping a modifier key and then w. It’s even easier than typing W, because I don’t even have to hold down the modifier.
- umvi 5y agoThat... sounds like a special keyboard setup to me.
- Avamander 5y agoIt was the default for me.
- lolinder 5y agoThat it was your default doesn't mean it was everyone's. OP's argument is that programmers should make it easy for someone else to change their code. It doesn't matter what your defaults were, it matters what the defaults of the next maintainer are.
- Avamander 5y agoGlad you understand why there's no need to restrict everyone to US-ASCII.
- 5y ago
- Symbiote 5y agoWhy not go all the way, and write ω₀ :-) I don't often write complicated formulae, but I do find it easier to use the original symbols if possible. Its one less thing to think about when comparing the source code with a mathematical description of the algorithm.
- sharikous 5y agobelieve it or not but the ₀ (u2080) is not allowed in Python, it's not for a lack of trying :) for some reason the entire Unicode "No" (Number, other) category is not included in the admissible character list for identifiers