27 ms·
Folks who want to work with my program are going to know Julia. These tab completions aren't limited to editors/IDEs, they also work at the REPL. Just copy-pa
by 3JPLW 7y ago
Folks who want to work with my program are going to know Julia. These tab completions aren't limited to editors/IDEs, they also work at the REPL. Just copy-paste the character you didn't know into Julia's help prompt:
help?> α
"α" can be typed by \alpha<tab>
Code is for reading much more than writing — especially for a new person. I maintain that matching the canonical form of
the algorithm I'm implementing will help them gain their feet faster.
Good example:
https://github.com/JuliaStats/Distances.jl/blob/c21aab0fae30916354bc104108c1c065eeb0c6aa/src/haversine.jl#L30-L33 https://github.com/JuliaStats/Distances.jl/blob/c21aab0fae30...
vs.
https://www.npmjs.com/package/haversine-geolocation#introduction https://www.npmjs.com/package/haversine-geolocation#introduc... (note the mathematical formula on that page and the JS code compared to Julia's)
- jacobolus 7y agoThe use of λ₁ and φ₂ instead of l1 and a2 or x1 and y2 or longitude1 and latitude2 is cute, but really not that big a practical improvement. Sure someone can pattern-match the code to the already-derived line in a reference book somewhere, but that doesn’t help at all with reasoning about the geometrical relationships or developing new algorithms, following control flow, building abstractions, improving precision, handling edge cases, ... It’s mostly helpful when you want to treat your formulas as an externally defined black box. * * * Aside: The problem in this particular example is that spherical coordinates and spherical trigonometry are just not a very good formalism for calculating anything, in either theory or practice. Unfortunately cartography, geodesy, etc. are bound by tradition and there hasn’t been much effort to switch them to better tools. I’ve been trying to read a spherical trigonometry textbook (Todhunter, 1878) the last few days and following along is a huge pain. Much better is to switch to cartesian coordinates or stereographically projected coordinates, and then use vector methods (and skip writing explicit coordinates in your code to the extent possible). All of the proofs and derivations get nicer, with geometrically meaningful steps and conclusions. Now your points can just be called p and q or a and b (or if you have a lot of them and aren’t pressed for space in each expression, points[i] and points[i+1]), and the coordinates stay internal. In addition to using clearer code, the calculations will also be faster, more precise, with better numerical stability, take up less memory/bandwidth, ... Here’s some general math for an arbitrary-dimensional sphere; for just the 2-sphere everything is simpler. http://geocalc.clas.asu.edu/pdf/CompGeom-ch3.pdf http://geocalc.clas.asu.edu/pdf/CompGeom-ch3.pdf
- 3JPLW 7y agoGood grief man. I literally just grepped through my installed packages for '₁', looked for a relatively interesting line with lots of unicode, saw "haversine" and realized it was a simple formula others would understand and that I would be able to find an image of online, and then hit google images looking for it. The point isn't the algorithm itself. The point is just how using unicode allows you to match the style of an arbitrary algorithm out of a textbook.
- jacobolus 7y agoCopying random formulas out of a textbook is only a tiny part of writing programs, at least for me. Making this have slightly less friction just isn’t that big a practical improvement for me. YMMV. In general I see code or explanations relying on Greek letters as no better than ones with English words for names.
- ReidZB 7y agoFrom hours and hours of studying math, those symbols are imbued with implicit meaning - in a way, they are simultaneously a data type, a name, and often a purpose or context (e.g. delta-x). That's a lot of information for such a compact representation. And that's mostly unconscious, which is great. I really found the Julia example above to be far, far easier to understand than the linked JS (though I think that JS was not particularly great). To me, it seems like it'd be nice-to-have, but alone, I don't think it would be enough to make me switch languages.
- newen 7y agoIsn't the conversation about using Unicode variables as opposed to ASCII variables and how they are useful when implementing equations from papers and textbooks? How is spherical coordinates not being as useful as cartesian coordinates relevant at all (not that I agree with this opinion)? There are tons and tons of other equations where Unicode letters are useful and the specifics of spherical vs cartesian is not at all relevant to the usefulness of Unicode letters.