6 ms·
- one-letter variable names - Greek letters - glyphs with obscure latex codes The last one in particular - how do you read this in your mind if you don't alr
by jstx1 5y ago
- one-letter variable names
- Greek letters
- glyphs with obscure latex codes
The last one in particular - how do you read this in your mind if you don't already know the name of the character? - "Hmm, that's a curly handwritten A". It's so disruptive to the thought process of the reader of your code if they don't already know the notation.
I really think that this is the opposite of beautiful. Code is about communicating with other people too. I also think that mixing code and math notation is liked by a vocal minority of Julia users but in the long term is harming the adoption of the language by beginners.
- dragonwriter 5y agoI also find the combination of Greek letters where they would be in mathematical notation without subscripts where they would be in the same notation has a bit of a uncanny valley effect. I don’t think that Julia having the capacity to use this style is bad, but I don’t think these examples are “beautiful and concise”, more “baroque and tasteless”.
- oscardssmith 5y agoNote that there is an effort to fix this. A group of Julia developers have written a proposal to give Unicode proper subscript and superscript modifiers.
- nerdponx 5y agoWriting is about knowing your audience. If you're a practitioner and not much of a programmer, it might be faster and easier to read the "math notation" version, which will be familiar to you, than the version a programmer might write, which might be unfamiliar and might require your brain to scan everything "from scratch".
- saalweachter 5y agoThe Greek letters don't bother me so much as the ones where I am not quite sure if it's an ASCII x, v or w that is just being displayed with a different font, or a letter is not technically an ASCII x, v or w.
- JustFinishedBSG 5y agoThat's more of an artifact of the font being badly designed though. Math requires excellent fonts if you don't want your reader to want to murder you by attempting to decipher the difference between L, calligraphic L, script L, italic L...
- saalweachter 5y agoMath's fondness for using multiple fonts with semantic meaning is going to backfire when the next generation's math genius uses comic sans for the new math they invent.
- mbauman 5y agoIt's all about matching the language of the literature in your domain. If you don't work in a domain that uses those conventions, you shouldn't use them. If you do, you and your colleagues should recognize it. If you're branching out into other code, you can always ask Julia itself what a particular character is — just paste it into a help prompt at the REPL: help?> 𝒜 "𝒜" can be typed by \scrA<tab> julia> '𝒜' '𝒜': Unicode U+1D49C (category Lu: Letter, uppercase)
- discmonkey 5y agoGradient descent is a pretty common algorithm, and I've seen it implemented in everything from JavaScript to c++. I have to say in this case the notation is significantly more distracting than helpful imo. Or to put it another way, the set of people working in the ml field, is both larger and more diverse than the set of people working purely in math. Everyone in the population of people who can both program and understand this type of notation would also be able to understand the less terse but more readable utf8 based text, the inverse is not true.
- generalizations 5y agoI think that means this code in particular is not catering to the lowest common denominator of people using the algorithm, but is instead aimed to be easy to use by those already fluent in the domain. It's important for both types of implementations to exist, and as you say, there's lots of other implementations available for those not familiar with the mathematical notation.
- deeviant 5y agoIs it easier to use? Or just it just look pretty to a subset of people?
- generalizations 5y agoIt's easier. There's a reason we use 'y = mx + b' instead of 'range = slope * domain + intercept' when we're doing math calculations. It's nice to use the long form when we're learning what the symbols are, but the symbols enhance readability when you're doing math, once you've become familiar with the meaning of the terms.
- generalizations 5y agoIt's also a matter of knowing your audience. All due respect: but this looks like code intended for people familiar with the relevant math, for whom such variables are very familiar. Personally, those 'strange letters' make it more readable, because that's how the mathematics are written.
- contravariant 5y agoThough it's worth keeping in mind that the mathematics is usually accompanied by an article that at a minimum (tersely) tells you what the symbols are.
- ModernMech 5y agoExactly, this is the thing people always seem to forget. When I write a paper with mathematical symbols like this, I always include a glossary for the reader. It's even required in some venues. People like to pretend that mathematical notations are standardized and obvious to practitioners, but they're just not. In my physics undergrad days we made a joke shirt with all the usages of the symbol "k" as it appeared in our physics texts. Is it the constant in Coulomb’s law? Is it a spring constant? The Boltzman proportionality factor? Is it kinetic energy? Is it a kilo? A kelvin? I think we were able to cover the front and back of the shirt with the overloaded usages.
- contravariant 5y agoYeah things can get a little wild sometimes with all possible interpretations. I'm pretty sure there are a few equations that use 'i' as both the imaginary unit and an index at the same time. I've noticed physicists can be a bit fast and loose with their definitions, somehow you're assumed to be up to do date on what concept is given the symbol "R" in that particular context. Though they do tend to agree with each other which concept should have which symbol.
- spywaregorilla 5y agoSounds like something one could expect from a docstring
- FabHK 5y agoOn the other hand, those are precisely the terms you will encounter in the literature. What is easier: matching (𝛍, 𝚺) to (𝛍, 𝚺), or to (mu, Sigma)?
- gugagore 5y agoI personally use Unicode liberally in my Julia code. Let me say there is a third alternative: (mean, cov) (except you'll shadow some functions...).
- 127 5y agoExactly. Making it harder to read, write and understand on purpose, unless you're a part of a specific small exclusive club. There's absolutely no reason.
- gspr 5y agoNo. There's a reason: it communicates extra information very cheaply and in-band with the code for people who are intimately familiar with the mathematics involved. This can be better than comments or documentation in some situations (and also doesn't preclude also having those). It's becoming a pet peeve of mine how HN conflates a solid, classical mathematical education with some kind of gatekeeping club. Anyone is welcome to join. Anyone is welcome not to use this language if they wish. But please don't dictate how us mathematicians are supposed to communicate.
- jstx1 5y agoIt's not about math notation on its own or about mathematical education. I'm very comfortable with mathematical notation in textbooks and papers and I still think that using it in code is a mistake.
- neolog 5y agoCan you explain why?
- 127 5y agoYes, I agree completely. It communicates information very cheaply and in-band to very few people who are intimately familiar with the mathematics involved. And nobody else. Calling this mathematical education makes me doubt your implicit claim of pedagogical ability. I think a lot of math could be taught with a lot less overhead and in more understandable fashion. It's just that the natural incentives seem to drive people to unnecessary overhead and barriers for those who actually want to learn. Lot of the language and symbols involved could be streamlined. But like QWERTY keyboard and C++, you would first have to turn this huge hulking ship of legacy cruft into that direction.
- 8note 5y agoIn mechanical engineering class, there was squiggly, and double squiggly. I don't remember which Greek letters those correspond to, but it's easy enough. Its not like anyone could draw them properly by hand either
- leephillips 5y agoI think these practices make sense for math-oriented code. In particular, I don’t understand the last objection. When you read math, do you need to describe the letters and symbols with English phrases in your head, like “Calligraphic L...right arrow with double staff...bold italic a with squiggle on top....”?
- jstx1 5y ago> When you read math, do you need to describe the letters and symbols with English phrases in your head..? I don't need to only if I already know what they mean. How does your brain process a character that you can't pronounce and whose meaning you're trying to understand from the code you're currently reading? Because my brain will need to assign something to it in order to use it.
- gnarbarian 5y agoI put emoji in my JavaScript all the time.