Excellent cheat-sheet

Hi All,

Wanted to flag a Julia cheat-sheet I recently stumbled across that seems phenomenally concise and comprehensive!

Open for PRs if anyone wants to contribute more!

EDIT: This was rolled into JuliaDocs org, so updated url in link above to The Fast Track to Julia

19 Likes

That is a really nice cheat sheet!

2 Likes

Right?

Is there somewhere else to post this to improve visibility? Maybe on julialang.org under resources? (If so, is there a place to PR such a submission?)

Yes, that seems like a good place. This is the repo for the website: https://github.com/JuliaLang/julialang.github.com, just make a PR like you normally would on a project!

I wonder what @brakmic thinks about transferring https://github.com/brakmic/Julia-Cheat-Sheet into the JuliaDocs org :slight_smile:

2 Likes

@waldyrious @brakmic says heā€™s up for it! Are you an admin on JuliaDocs?

Hi,

Yes, of course. Itā€™d make more sense to have the cheat sheet there :slight_smile:

2 Likes

forio returns 404 and GitHub - forio/julia-studio: An IDE for the Julia Language seems abandoned tooā€¦

1 Like

Nope :slight_smile: only 3 people are publicly visible as members of the org (not sure if there are more): @mortenpi, Michael Heatherly (no discourse account?) and @ararslan. Iā€™m not sure what the process of migrating a repo to an org is, but IIRC one of them should invite @brakmic and he can then initiate the transfer.

Iā€™ll update the links. Thanks :slight_smile:

The info on types seems out of date. Ie, types ā†’ structs, immutables ā†’ mutable structs, typealias x y ā†’ const x = y.

Very thorough. Some comments / suggestions after a read through. Just personal opinions.

Immutable types are passed around by value (i.e. copying), whereas mutable types are passed by reference.

Iā€™m not sure this is really true. Since you canā€™t modify an immutable struct it doesnā€™t matter if you copy it or not to pass it as an argument, and the compiler can chose what to do. Also, I donā€™t think there is anything called ā€œpass by referenceā€ in Julia. What I think it is typically called is ā€œpass by valueā€ and this is true both for mutables and immutables.

Free up memory for large arrays with arr = nothing

I feel like this is rarely needed. If you have no use for arr anymore then it typically would have dropped out of scope and be cleaned up by the gc anyway.

Use named instead of anonymous functions.

Donā€™t think this is true anymore.

Use type annotation rather than tests for function arguments.

I donā€™t think this has a performance impact.

Split functions into smaller components to aid the compiler.

Not sure if this is true, or helps performance. (Note that the link in this text leads to a suspended account).

Type alias typealias Nerd Programmer

typealias is deprecated in 0.6.

Moreover, using only loads exported names by default while import loads all names defined in the module.

Iā€™m not sure what this means. What does loading a name mean?

Statically sized arrays ImmutableArrays

Should probably change this recommendation to StaticArrays.

Test framework Test

Iā€™m not sure what package this references but Base own Test is pretty good now.

type Hacker <: Programmer
  name::AbstractString
  birth_year::UInt16
  fave_language::AbstractString
end

Perhaps put String instead of the abstract type AbstractString as the fields. Also, I think just using an Int for birth_year might be preferable.

Dictionaries are mutable; when symbols are used as keys, the keys are immutable.

Not sure what this means. How are symbols as keys special?

Julia has many built-in mathematical functions, including special functions (e.g. Airy, Bessel, Gamma), and supports complex numbers right out of the box.

Airy and Bessel are no longer built in (in 0.6).

6 Likes

@kristoffer.carlsson @Elrod Some of those errors are mine ā€“ I tried to update for 0.6, but sounds like there were a lot of things I apparently know about. Wanna PR some of those?

This could probably start another topic. If someone has to agree with you then some harmony in wider context is necessary. For example: what is value of Vector with thousand and one element? So although I could understand what you mean, this paradigm could not be described by one sentence. In some other paradigm your sequence is false! I think we have to describe what we understand with variable binding and then we could say that parameters pass by bind value. Or something similar (sorry my English is very poor).

Passing by value is a fairly standard term. See for example: language agnostic - What's the difference between passing by reference vs. passing by value? - Stack Overflow.

Note

When a parameter is passed by reference, the caller and the callee use the same variable for the parameter.

This is clearly not the case in Julia.

would be nice with a print-friendly version

5 Likes

Two points:

  1. We could continue reading SO answer: ā€œHowever, if the value in question is a mutable reference-type object or otherwise indirectly references other values, then you can emulate call-by-reference in a call-by-value environment: if the callee modifies the object (or other values pointed to by the object), those modifications are visible to the caller.ā€ (emphasis is mine) ā† it is what probably cheat-sheet wants to say.

  2. I donā€™t like to start philosophic and linguistic argue about terms (and I rather agree with your POV). But you could look for example at wiki (ā€œIn some cases, the term ā€œcall by valueā€ is problematic, as the value which is passed is not the value of the variable as understood by the ordinary meaning of value, but an implementation-specific reference to the value. The effect is that what syntactically looks like call by value may end up rather behaving like call by reference or call by sharing, often depending on very subtle aspects of the language semantics.ā€) that it is indeed problematic in some cases so it has not so well established meaningā€¦ I loosely remember that Julia has this aspect described well in documentation! But IMHO it is difficult to describe this in cheat-sheetā€¦ (maybe some links to doc/wiki/so could help)

Edit: I agree with you that it has to be fixed in cheat-sheet! :slight_smile:

My point is that there is no difference how arguments are passed to functions. It just happens that some object are mutable and some are not. Hence, I donā€™t think the statement about argument passing need to be there at all.

I agree with this, nevertheless it is apparent that some newcomers to Julia struggle with the semantics of shared structure, so an opportunity to point it out should not be wasted. Possibly a ā€œcheat sheetā€ is not the right place to expand on this, but it could contain a link to tutorials.

3 Likes

Regarding pass by value, the question is: is passing an argument x to a function parameter p equivalent to assignment p=x? The answer, in Julia, is yes, so it is pass by value.

(If x is a mutable object, the of course its contents can still be altered via p.)

If youā€™ve never used a true pass-by-reference language, like Fortran 77, then it may be hard to imagine anything other than pass by value semanticsā€¦

1 Like