News for hackers. Stuff that matters.
Re:Concise algorithms written in Julia by jstx1 on Friday July 09, 2021 @11:45AM (#27784882)
- 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.

Re:Concise algorithms written in Julia by mbauman on Friday July 09, 2021 @11:54AM (#27784999)
It'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)
Re:Concise algorithms written in Julia by discmonkey on Friday July 09, 2021 @12:09PM (#27785182)
Gradient 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.
Re:Concise algorithms written in Julia by generalizations on Friday July 09, 2021 @12:12PM (#27785220)
I 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.
Re:Concise algorithms written in Julia by jstx1 on Friday July 09, 2021 @01:18PM (#27786036)
> I think that means this code in particular is not catering to the lowest common denominator of people using the algorithm

Maybe the title should have been 'Algorithms that look concise and beautiful to people who already know them'.

Re:Concise algorithms written in Julia by icedistilled on Friday July 09, 2021 @06:45PM (#27789362)
>is not catering to the lowest common denominator of people using the algorithm

I don't think an expert in some field who just happens not to be an expert in some other field's jargon and pictographs should be branded "a lowest common denominator of people", this terminology is both judgmental and elitist in all the bad ways.

Re:Concise algorithms written in Julia by TheTrotters on Friday July 09, 2021 @06:02PM (#27789031)
Anyone who has even basic fluency with these algorithms has ~never worked with code that uses these symbols and will likely find them distracting in this context.

I've seen plenty of function use, say, `theta` but I have never worked with θ.

Re:Concise algorithms written in Julia by deeviant on Friday July 09, 2021 @12:19PM (#27785309)
Is it easier to use? Or just it just look pretty to a subset of people?
Re:Concise algorithms written in Julia by generalizations on Friday July 09, 2021 @01:01PM (#27785841)
It'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.

Re:Concise algorithms written in Julia by didibus on Friday July 09, 2021 @08:43PM (#27790084)
I'd be tempted to challenge this assertion. It made sense when handwriting to maximize for not having to spend too much time writing, but with modern auto-complete, I might start to believe that it be clearer to use the long form for everyone, yes even for a person familiar with mathematics. If all math was rewritten long form, I feel it would honestly have second order effect on approachability and being able to understand papers even from other mathematicians.
Re:Concise algorithms written in Julia by patrick451 on Friday July 09, 2021 @10:48PM (#27790731)
Hard disagree. Just reading 'range = slope * domain + intercept' is tedious and takes 10 times as long.
Re:Concise algorithms written in Julia by deeviant on Sunday July 11, 2021 @03:39PM (#27803985)
Hard disagree. Because tedious and long is absolutely orthogonal to "easier to understand".

There is a reason why one letter/number variables are basically verboten in best practice.

Re:Concise algorithms written in Julia by generalizations on Friday July 09, 2021 @11:54AM (#27785006)
It'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.

Re:Concise algorithms written in Julia by contravariant on Friday July 09, 2021 @12:00PM (#27785077)
Though 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.
Re:Concise algorithms written in Julia by counters on Friday July 09, 2021 @01:04PM (#27785867)
Bingo. And it goes vice-versa; because software engineering standards are so lax (read: non-existent) in most academic disciplines and domains, on the rare occasion where you get accompanying code to an academic work it may be impossible to actually much of the source to the original work itself.

During my dissertation I had to collect implementations of about a dozen parameterizations of a process I was studying, with the intent of coupling them/incorporating them into a set of climate modeling experiments. All of the implementations were in Fortran (which in and of itself wasn't a problem, albeit it was annoying re-writing or re-factoring some F77 code to play more nicely with the more modern Fortran codebase in which our climate model was written). Of these codes I collected, the majority of them had bugs which restricted my ability to reproduce the reported results from the original work they accompanied. One or two of them had significant flaws in them - answer-changing bugs which, when corrected, potentially would yield different results from those reported in their original papers, and might actually lead to different conclusions.

One of the nice things about the Jupyter ecosystem of tools and Julia is the ability to more closely replicate equations from the original paper. It seems dumb, but in my anecdotal experience I've noticed fewer significant bugs when colleagues have used these features. I've also noticed a propensity for scientists and researchers to write clearer, better-documented code - if your next line of code is going to directly mimic Equation 13 in your paper, why wouldn't you go ahead and write a comment saying so?

Re:Concise algorithms written in Julia by res0nat0r on Friday July 09, 2021 @01:27PM (#27786158)
Do folks normally write code using the Greek alphabet? I totally understand reading/writing math papers in latex, or on paper using the traditional mathematical symbols, but does anyone really want to edit their Julia code in vim and type \scrA<tab> for a variable name? Seems extremely annoying and convoluted vs naming your variables alpha or sigma, etc.
Re:Concise algorithms written in Julia by mbauman on Friday July 09, 2021 @02:09PM (#27786649)
All the time. Incidentally, I got these unicode α and σ by copy-pasting from tab completion in an open Julia REPL.

https://juliahub.com/ui/Search?q=α&type=code&w=true

https://juliahub.com/ui/Search?q=σ&type=code&w=true

Re:Concise algorithms written in Julia by leephillips on Friday July 09, 2021 @02:38PM (#27786952)
But I can type α with two keystrokes. “alpha” is five.
Re:Concise algorithms written in Julia by res0nat0r on Friday July 09, 2021 @03:22PM (#27787514)
Looking up escape codes or cutting and pasting non ascii characters takes much longer than typing 5 letters.
Re:Concise algorithms written in Julia by leephillips on Friday July 09, 2021 @03:33PM (#27787616)
> But I can type α with two keystrokes.
Re:Concise algorithms written in Julia by res0nat0r on Friday July 09, 2021 @05:30PM (#27788768)
Learning that for all the mathematical symbols, still too time consuming.
Re:Concise algorithms written in Julia by ModernMech on Friday July 09, 2021 @12:19PM (#27785311)
Exactly, 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.

Re:Concise algorithms written in Julia by contravariant on Friday July 09, 2021 @01:20PM (#27786064)
Yeah 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.

Re:Concise algorithms written in Julia by spywaregorilla on Friday July 09, 2021 @01:03PM (#27785860)
Sounds like something one could expect from a docstring
Re:Concise algorithms written in Julia by saalweachter on Friday July 09, 2021 @11:48AM (#27784912)
The 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.
Re:Concise algorithms written in Julia by JustFinishedBSG on Friday July 09, 2021 @12:31PM (#27785478)
That'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...

Re:Concise algorithms written in Julia by saalweachter on Friday July 09, 2021 @12:58PM (#27785796)
Math'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.
Re:Concise algorithms written in Julia by enriquto on Friday July 09, 2021 @02:48PM (#27787087)
> the next generation's math genius uses comic sans for the new math they invent.

The way you put it, it almost sounds as if that wouldn'be great!

Re:Concise algorithms written in Julia by kmill on Friday July 09, 2021 @04:05PM (#27787942)
Hmm, I'm tempted to use it for mathscr... It probably would even be more legible.
Re:Concise algorithms written in Julia by FabHK on Friday July 09, 2021 @12:17PM (#27785280)
On the other hand, those are precisely the terms you will encounter in the literature.

What is easier: matching (𝛍, 𝚺) to (𝛍, 𝚺), or to (mu, Sigma)?

Re:Concise algorithms written in Julia by gugagore on Friday July 09, 2021 @12:23PM (#27785363)
I personally use Unicode liberally in my Julia code.

Let me say there is a third alternative: (mean, cov) (except you'll shadow some functions...).

Re:Concise algorithms written in Julia by nerdponx on Friday July 09, 2021 @11:51AM (#27784965)
Writing 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".

Re:Concise algorithms written in Julia by dragonwriter on Friday July 09, 2021 @12:31PM (#27785474)
I 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”.

Re:Concise algorithms written in Julia by oscardssmith on Friday July 09, 2021 @01:21PM (#27786076)
Note 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.
Re:Concise algorithms written in Julia by leephillips on Friday July 09, 2021 @01:07PM (#27785892)
I 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....”?
Re:Concise algorithms written in Julia by jstx1 on Friday July 09, 2021 @01:11PM (#27785960)
> 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.

Re:Concise algorithms written in Julia by 8note on Friday July 09, 2021 @12:53PM (#27785746)
In 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

Re:Concise algorithms written in Julia by 127 on Friday July 09, 2021 @12:22PM (#27785341)
Exactly. 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.
Re:Concise algorithms written in Julia by gspr on Friday July 09, 2021 @12:49PM (#27785686)
No. 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.

Re:Concise algorithms written in Julia by 127 on Friday July 09, 2021 @03:53PM (#27787823)
Yes, 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.

Re:Concise algorithms written in Julia by gspr on Friday July 09, 2021 @05:23PM (#27788695)
> 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.

Ok. Have at it, I guess.

> 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.

This screams a fundamental misunderstanding of mathematics. The symbols need context to make any sense whatsoever. To a reader with intimate knowledge of the context, the symbols convey lots of information very efficiently. That doesn't mean that the symbols are understandable without context, or even that they could be made understandable without context.

Re:Concise algorithms written in Julia by 127 on Saturday July 10, 2021 @03:42AM (#27791841)
For example, using greek instead of latin letters is completely unnecessary. Just to point out completely meaningless overhead.

Using in-group context-sensitive symbols is by definition exclusive. Using descriptive well thought out names is inclusive.

Math as a language seems very needlessly compressed. Imagine a world where programmers invented a new symbol for every function and you would have to look up what they mean, but when you look up what they mean, you would have to look up 10 other symbols. Most of those symbols refer back to symbols where you came from in the first place. It's a detriment for learning. Simple as that.

Not everybody wants to be a mathematician. Some people just want to get work done and read through a bunch of research papers.

Re:Concise algorithms written in Julia by gspr on Saturday July 10, 2021 @06:21AM (#27792435)
> For example, using greek instead of latin letters is completely unnecessary. Just to point out completely meaningless overhead.

Are you saying the whole field of mathematics (and physics) is wrong, and we're doing something "meaningless"?

> Using in-group context-sensitive symbols is by definition exclusive. Using descriptive well thought out names is inclusive.

Not when the group is open to anyone who wants to join. Math is probably the most "open source" field out there. Barring the very cutting edge front of research, everything can be learned from free sources or ones that can be borrowed for free from libraries, or had through very very cheap second hand material.

That there is a high barrier to entry when it comes to effort isn't some malicious gatekeeping design. It's just because some things are hard.

> Math as a language seems very needlessly compressed. Imagine a world where programmers invented a new symbol for every function and you would have to look up what they mean, but when you look up what they mean, you would have to look up 10 other symbols.

You clearly have never done math! The way it works requires intimate familiarity with the definitions of the symbols. Once you actually manage to internalize that (it can be a lot of work), remembering what the symbols stand for comes for free.

> Not everybody wants to be a mathematician. Some people just want to get work done and read through a bunch of research papers.

"Not everyone wants to be a surgeon, some people just wanna read medical research papers."

"Not everyone wants to be an astrophysicist, some people just wanna read astrophysics papers."

Do you not see how ridiculous this is? Nobody is gatekeeping for the sake of gatekeeping. You're conflating gatekeeping with something just being hard, and the practitioners of the hard thing not wanting to change the way we work to accommodate non-practitioners (to our own detriment!)

Re:Concise algorithms written in Julia by 127 on Saturday July 10, 2021 @11:25AM (#27794020)
Symbols and math are two completely different things. Symbols are just something you attach concepts and ideas to. I believe that with words and labels instead of obscure symbols and surnames of mathematicians, teaching math could be more efficient. Even with set theory being a branch of mathematics, categorizing things seems to be very shooting from the hip.

All I'm seeking here is how to improve communicating math without having to go through the credentialism of higher education.

edit: Why you didn't understand my comment on reading papers: some computer science papers require heavy math background. A lot of math is actually applied math.

Re:Concise algorithms written in Julia by gspr on Saturday July 10, 2021 @11:34AM (#27794087)
At this part you're just armchairing.

Lastly:

> All I'm seeking here is how to improve communicating math without having to go through the credentialism of higher education.

Like I've already pointed out: mathematics is perhaps the most "open source" field there is. There's no need to go through the "credentialism" if you don't want to. Again you're just conflating math being hard with it being protected by some imagined wall of credentialism guarded by gatekeepers.

Re:Concise algorithms written in Julia by jstx1 on Friday July 09, 2021 @01:34PM (#27786229)
It'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.
Re:Concise algorithms written in Julia by neolog on Friday July 09, 2021 @02:38PM (#27786951)
Can you explain why?
Re:Concise algorithms written in Julia by TheTrotters on Friday July 09, 2021 @06:09PM (#27789072)
> it communicates extra information very cheaply and in-band with the code for people who are intimately familiar with the mathematics involved.

I think it's just the opposite. People familiar with the relevant math have, most likely, worked with this stuff in other programming languages and never used math symbols in their code.

I'm used to seeing θ or α in text and theta or alpha in code. The combination of Greek letters and for loops looks very weird.

Re:Concise algorithms written in Julia by gspr on Saturday July 10, 2021 @02:35AM (#27791583)
Your assumption is wrong. Lots of really useful math has 0 or 1 implementations. A Julia one may well be first. (Saying this as someone who's done several first implementations, but haven't coded a single line of Julia)
Re:Concise algorithms written in Julia by patrick451 on Friday July 09, 2021 @11:09PM (#27790820)
Why should we cater to the lowest common denominator? If we did it your way, we increase friction for the people most likely to use, read and edit this code. Just like the written word, code has a target audience. If you want to call that gatekeeping or some other putative pejorative, find by me.
Re:Concise algorithms written in Julia by jstx1 on Saturday July 10, 2021 @05:16AM (#27792193)
> Why should we cater to the lowest common denominator?

The options aren't just complete beginner vs math PhD though. Imagine an experienced software developer who has written these kinds of algorithms in other languages and has never used latex. That's the kind of person you're also keeping out. Are they "the lowest common denominator"?

I also don't know why you assumed that the people who are most likely to use this code like this are automatically people who already know the glyphs.

It's gatekeeping not just because there is barrier to entry. It's because that barrier is artificial, unnecessary and comes with a smug feeling of superiority (you aren't the first person to use "lowest common denominator" in this thread).

Re:Concise algorithms written in Julia by patrick451 on Wednesday July 14, 2021 @12:40AM (#27829784)
Frankly, if you don't know the glyphs, you almost certainly have no business using the code. Basic notation is table stakes. I learned this stuff (yes, the latex) as an undergrad, and I wasn't even a math major.
Re:Concise algorithms written in Julia by 127 on Saturday July 10, 2021 @03:48AM (#27791866)
It's fine if it's only for hard core mathematicians. Use a disclaimer front and center next time: NOT MEANT FOR MUGGLES.

(Seriously talking: From an educational point of view, lowest common deminator is exactly what you want, as long as you can communicate the entire concept effectively)

Re:Concise algorithms written in Julia by gnarbarian on Friday July 09, 2021 @01:17PM (#27786027)
I put emoji in my JavaScript all the time.