Skip to content
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

WIP: Document noteworthy unusual Julia features. #11998

Closed
wants to merge 7 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions doc/manual/noteworthy-differences.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,39 @@
Noteworthy Differences from other Languages
*******************************************

Noteworthy and unusual Julia features
---------------------------------

* Julia allows identifiers with complex Unicode, for example you could represent the value of a chi-squared test with ``χ²``,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence is way too long. Also, I don't think using Unicode in identifiers in general is what would cause problems, I think its more just this one particular case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a whole set of characters that at least as I understand the Unicode standard UAX 31, shouldn't be considered part of identifiers. (I have no problem at all with Unicode in identifiers, I just brought up a point where it seemed inconsistent with other uses of Unicode characters in Julia)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. Instead of replying to me, write that in documentation form, which is not what is here right now.

similarly ``χ⁽³⁾`` is used in electromagnetism for the third-order nonlinear susceptibility, another example is ``∇²``
which is the name of the Laplacian operator. All of these Unicode symbols are valid Julia identifiers.

It can also be useful for caching powers of ``x`` to ensure that intermediate products are reused optimally in time-critical code.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get why this example was put here, but this is a microoptimization that is going to freak people out if its the first thing they see in a section of the manual. I'm not sure an example is needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One would hope also that the compiler would be smart enough to lift things out of loops, if you have x*x or x^2 inside a loop. (If Jeff can't make the compiler do that, or more likely, has done it already, I'd eat my hat)

A classic example is in computing the [Lennard-Jones 12-6 potential energy](https://en.wikipedia.org/wiki/Lennard-Jones_potential) in computational chemistry and physics, in order to compute:

.. math::

A/x^12 - B/x^6

one can write:

.. doctest::

"Lennard-Jones potential"
function lj(x, A, B)
x⁻² = x^-2
x⁻⁶ = (x⁻²)^3
x⁻¹² = (x⁻⁶)^2
A*x⁻¹² - B*x⁻⁶
end

.. note::

Be wary about referencing a global variable while thinking it was an operator applied to a local variable and updating a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea what this sentence is trying to say. Could you word it differently? Is this related to unicode?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ScottPJones would you mind showing a short example of this pitfall?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This "pitfall" is a contrived strawman crafted to make a specific point.

variable without remembering to update the cached value.

* The ``/`` operator gives floating-point results for integer arguments, use ``div`` for truncating to an integer.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably just be in the C differences section, people coming from Python, MATLAB, R, etc. wouldn't find this a noteworthy or unusual Julia feature.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is a lot more languages than just C/C++, also Java, Lua, Python, etc.
Can you give an example of that actually working in MATLAB or R, or any other language?
AFAICT, it doesn't follow the Unicode standard for identifiers http://www.unicode.org/reports/tr31

>>> x³ = 5
  File "<stdin>", line 1
    x³ = 5
     ^
SyntaxError: invalid character in identifier
>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ScottPJones, its talking about division, not unicode, what are you talking about?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, I thought you were talking about the part above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I'll change it to the C part.


Noteworthy differences from MATLAB
----------------------------------

Expand Down