Feedback on an "Intro to Julia" guide for a university course

Great catch! Indeed, I don’t think I want to introduce arbitrary-precision arithmetic right at the start… I’ll think rewriting this (either along the lines you / Benny suggest, or having a question that asks something like “%f is for floats, so how many of these digits do we expect to be correct?”… or just using %g instead.

Thanks for the kind words, and for the criticisms!

You are, of course, absolutely correct that “annotations” play distinct roles in different contexts, and I think your critique is spot on: the way I’ve written things could easily lead students to an incorrect mental model of :: as a monolithic feature. I think I need to spend some time (both from this, and also from Tamas Papp’s comments) thinking more about how I want to talk about types in this and in the later appendices.

A final comment: I do not want to imply that type annotations are generally desirable for performance, or get students into the habit of sprinkling type annotations as if it is magical fairy dust for their code. On the other hand (and please correct me if this is wrong!) I do want them to get in the habit of making sure that when they define structs they use annotations to make sure the struct’s fields are concrete.

Also, thanks for catching those typos!

(edit – I forgot to write the word “students” in the “A final comment:” sentence)

1 Like

Ah, that’s the fourth meaning of “type annotation”. And, yeah, that one is almost always a good choice.

3 Likes

Thanks for your continued thoughts on this (and for confirming your approach to teaching scope)!

A very fair point — perhaps I was enjoying writing a bit too much, and thus engaging in more hand-holding than is necessary.

Unfortunately, no (we currently have a shortage of TAs available, so they’re largely being reserved for the largest intro classes). It gives a bit of impetus to the project of trying to write something that might head off questions about minor problems that a TA could otherwise handle. As you say: it’s not a trivial task, and the cost-benefit analysis of attempting it is not a slam dunk. But if nothing else at least it’s a task I’m enjoying!

2 Likes

Happy to help, though I am not sure I am helping much; ultimately you are the one who knows these students best.

I would play it by ear: see how the students are doing in the first few homeworks, and go faster/slower accordingly.

1 Like

In my experience teaching this kind of material, this is not a concern. Even senior students often need way more hand-holding than you might expect. And if you do go overboard, they often don’t mind feeling like they know something already.

Increasingly, the real problem is that most students won’t (maybe can’t) read a section of a technical document from start to finish. They have cheerfully admitted as much to me. On top of that, modern computing has abstracted or obscured even filesystem basics for them their whole lives. The idea of dropping an undergrad straight into the Julia manual sounds…unwise…to me.

(Not all students, certainly, but there’s little point in worrying about what to do for the great ones.)

Students increasingly expect just-in-time delivery of solutions to today’s homework, a la LLMs. While that can work out for someone who has a basic understanding already, it’s not clear to me that it works for a raw beginner, and I haven’t figured out what to do about it. I can’t even get them to start assignments early enough to ask for real help in time.

13 Likes

Thanks for sharing your perspective on this! I agree that there has been a real shift in how most students seem to… interact with classes, homework, and technical documents. I worry that such a discussion would rapidly spiral beyond the scope of this Discourse :smile:

1 Like

Picking Julia is good choice. During my PhD I prepared a course on computational thermodynamics and picked Julia that time, then I taught the course for 3 years. Now I’m bringing Julia to my R&D colleagues.

Here is summary of my experience.

  • For students, it took two lessons (2.5 hours) on Julia crash course.
  • I use implementation of bisection algorithm (see at the end) to cover most of syntax and save time. In my case, the students already knew Python and (depends on year) C++.
  • The rest main topics are generic programming (dispatch and type system), structs, modules and packages, built-in arrays and broadcast.
  • I gave two homeworks: (1) implement some classical algorithms from CS classes or solve simple physical problems, (2) complete package and pass all tests. These two homeworks had strict deadlines.
  • Everything else w.r.t. Julia I taught on demand.

Here is my comments on introJuliaDraft.pdf.

  • REPL section misses examples for documentation (help?> sqrt and help?> "square root").
  • Unicode completion in REPL, e.g. \pi<Tab> becomes π.
  • No spaces, like here a=[10,100,1000]; (p. 16). It is matter of choice, but I prefer to stick with Blue style.
  • As an idea, for dispatch section consider to combine all algrotihms for computing π. Something like findpi(by::Method, params::MethodParams).

Hope it helps!


function bisection(f, xl, xr; xtol=eps(), ftol=eps())
    @assert xl < xr

    yl, yr = f.((xl, xr))
    @assert sign(yl) != sign(yr)

    abs(yl) < ftol && return xl
    abs(yl) < ftol && return xr
    
    maxiter = ceil(Int, log2((xr-xl)/xtol))
    
    for i in 1:maxiter
        xmid = (xr + xl) / 2
        ymid = f(xmid)
        
        if sign(yr) == sign(ymid)
            xr, yr = xmid, ymid
        elseif sign(yl) == sign(ymid)
            xl, yl = xmid, ymid
        else
            return xmid
        end
        abs(ymid) < ftol && return xmid
    end
    return (xr + xl)/2
end

# -----

f(x) = exp(x) + log(x) - 2
xsol = bisection(f, 0.1, 2)

# -----

using Plots
using LaTeXStrings

plot(f; label=L"\exp\ x + \log\ x - 2", xlim=(0, 1.5), ylim=(-6, 6), xlabel=L"x", ylabel=L"f(x)")
scatter!([xsol], [f(xsol)]; label="метод бисекции, корень $(round(xsol; digits=5))")
11 Likes

With the caveat that I haven’t looked through your course yet and I’m just going off this thread -

I don’t know if this will be relevant for your students, but for my (biology) students that have some python background (and me for that matter when I was learning), the most common error to hit by far were MethodErrors, and it is impossible to understand what these errors mean without understanding types, at least a little bit. Examples:

julia> v = [1,2,3];

julia> push!(v, π)
ERROR: MethodError: no method matching Int64(::Irrational{:π})
#...

julia> x = first(readlines("my_file.txt"))
"1"

julia> x + 1
ERROR: MethodError: no method matching +(::String, ::Int64)
#...

julia> y = [];

julia> if y
           #do whatever
       end
ERROR: TypeError: non-boolean (Vector{Any}) used in boolean context
# ...

It’s especially tough when these errors are occurring deeper in a call stack, so it’s not directly your “fault”.

My goal, particularly early in the class, was to teach them just enough about types that they could see a MethodError without panicking, and have some idea about how to debug it.

11 Likes

Thanks for sharing your experience – it’s definitely good to have another data point for how long it took to do the “crash course” version of intro to Julia before moving on to the rest of the material!

Thanks also, for the comments on the draft! A few quick responses:

REPL section misses examples for documentation

Fair – I talk about the help mode existing, and I have question boxes that hopefully make it clear that the students should be using this mode of the REPL, but I could certainly add an example or two.

Unicode completion in REPL…

I do actually mention this (in the “Method 1: Asking a friend” section of the installation chapter), although I certainly don’t dwell on it at the moment. Perhaps my attitude about how convenient direct unicode is will evolve over time, but right now I don’t really use it. At the moment I use neovim for writing code – I suppose I could set up a lot of snippets to make entering unicode easier, but for now I mostly just ignore the ability to use unicode both in files and in the REPL.

No spaces…Blue style

I should almost certainly try to be more consistent in my style throughout! I have to admit, though… I still do find Julia’s “mixing upper camel case and snake case is idiomatic” style a bit jarring. I’ll get over it eventually, I’m sure

As an idea, for dispatch section…

Fantastic idea! I already have a homework question in which I ask the students to make a plot of “precision of the estimate of pi” vs “computational effort” for the different algorithms, but I missed the opportunity to explicitly have them implement this in a way so that they can dispatch on the method!

Very helpful to hear, and that’s a great point – thinking about what the most common failure cases / pain points for students learning the language is a good way to frame for myself what I should be doing to give them the tools to push through them.

The link has an updated version of the draft, and over the coming days I’ll think about continuing to work on the type section(s) to incorporate this feedback. Thanks!

1 Like

I’m also a neovim user, JuliaEditorSupport/julia-vim provides both syntax highlighting and Unicode completion like in REPL. This plugin suffices my needs. Also, I became a fan of Unicode and use LaTeXtoUnicode#Toggle() to enable Unicode completion outside Julia files.

1 Like

Thanks for the pointer to this – I hadn’t seen the JuliaEditorSupport organization! I could see how this could quickly become quite convenient.

Also, I just glanced at the (extensive) table of latex-to-unicode conversions supported by julia-vim… what a world we live in, being able to tab-complete \:sauropod: in the terminal :joy:

3 Likes

Yeah, that will be just the ticket when programming the next generation of Jurassic World ride. Hand out the Twinkies!

1 Like