Julia Module 1
Getting started: what Julia is for, installing it and running code interview questions
Interview questions on “Getting started: what Julia is for, installing it and running code”.
Warm-up questions
Short questions with short answers, each answered in full.
-
Fresher to mid
What does just-in-time compilation mean in Julia, and why is the first call of a function slow?
Julia compiles a function the first time it is called with a particular combination of argument types. It infers the type of every value in the function from those argument types, generates machine code through LLVM and keeps that code for the same types. The first call therefore pays for type inference and code generation, which for a small function can take a large part of a second, while every later call with the same types runs the stored machine code directly, often in microseconds. A call with new argument types, say Float32 instead of Float64, compiles a new specialisation. Packages are compiled once when first loaded and the result is cached in the depot. To time code fairly, call it once first, or use a benchmarking tool that runs it many times.
From the lesson What Julia is for, and when to choose it
-
Fresher to mid
How do juliaup's release and lts channels differ, and how do you start each one?
Answered in the lesson Install Julia with juliaup and manage versions
-
Fresher to mid
Besides the Julian mode, which modes does the Julia REPL have, and how do you enter and leave each?
Answered in the lesson The REPL, scripts and the @main entry point
-
Fresher to mid
What does Revise.jl do, and why do Julia programmers use it?
Answered in the lesson Notebooks, editors and the Revise workflow
Questions with model answers
What each question tests, the first step of a good answer and the follow-ups to expect.
-
Fresher to mid
A colleague times a new Julia function once with @time, sees 1.2 seconds, and concludes that it is slower than their NumPy version, which takes 5 ms. What is wrong with the measurement, and how would you measure the two fairly?
- What it tests
- Knowing that a first call includes just-in-time compilation, that single runs and untyped globals distort timings, and how to time compiled code fairly.
- First step
- Read the @time line: if it reports a large compilation share, most of the 1.2 s was compiling, not computing. Call the function once, then time a second call or the fastest of several, with the data passed as arguments, and time the NumPy version the same way.
- Follow-ups
-
- How would you show your colleague how much of the 1.2 s was compilation?
- Why do untyped global variables make a Julia benchmark slower?
- When is the first-call time the number that matters?
From the lesson What Julia is for, and when to choose it
Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.Opening the model answers with your pass…
Model answers open with any MySmartCoPilot pass.
- Pro pass · 1 week₹79$2.99
- 30 days₹179$5.99
- 1 year₹1,699$45
One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.
Passes can’t be bought right now, so the model answers can’t be opened at the moment. If you have a pass, enter your licence key.
It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).
In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
Your lab's Python particle simulation spends about 90 % of its run time in a hand-written loop over particles that no NumPy function covers. Would you port it to Julia, and what would you measure and check before deciding?
- What it tests
- Judging a language move by where the time goes, the measured costs of Julia (compilation per process, package precompilation, missing libraries) and a small, checkable trial.
- First step
- Profile first, to confirm that the loop really takes the 90 % and to see how long one run lasts. Then port only that loop to a Julia function, check that it gives the same numbers, and compare its time after the first call with the Python loop's.
- Follow-ups
-
- How would you keep the rest of the Python code while trying Julia?
- What could make the port not worth it?
- How do you check that the ported loop gives the same results?
From the lesson What Julia is for, and when to choose it
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
On a shared cluster your home folder has a 2 GB quota, and installing Julia packages starts failing with disk-quota errors. How do you move Julia's packages elsewhere, and what exactly must the new JULIA_DEPOT_PATH value contain?
- What it tests
- Knowing what the depot holds, how DEPOT_PATH is built from JULIA_DEPOT_PATH, and why the trailing separator keeps the bundled depots.
- First step
- Find what fills the quota, usually packages, artifacts and compiled caches in ~/.julia. Then set JULIA_DEPOT_PATH to a folder on a larger file system followed by a colon, such as /scratch/me/julia-depot:, before Julia starts, and check DEPOT_PATH in a new session.
- Follow-ups
-
- What goes wrong if the trailing colon is left out?
- Where do you set the variable so that every job gets it?
- What happens to the packages already installed in ~/.julia?
From the lesson Install Julia with juliaup and manage versions
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
Your package must work on the Julia 1.10 LTS and on 1.13. How do you test both on one laptop and in continuous integration, and what does supporting 1.10 change in the code itself?
- What it tests
- Using juliaup channels side by side, a test matrix in continuous integration, and code that avoids or guards features newer than the LTS.
- First step
- Install both with juliaup, juliaup add lts beside the release, and run the test suite with julia +lts and julia +release. In continuous integration, run the same job on both versions. In the code, avoid or guard names that arrived after 1.10, such as logrange and @main.
- Follow-ups
-
- How do you make one project folder always start the LTS?
- How do you guard a feature that 1.10 lacks?
- When would you drop support for 1.10?
From the lesson Install Julia with juliaup and manage versions
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 2 minutes
-
Fresher to mid
A script that works when its lines are pasted into the REPL fails in a continuous integration job with UndefVarError:
subtypesnot defined inMain. Explain why, fix it, and say how you would stop similar surprises.- What it tests
- Knowing that the REPL loads InteractiveUtils for you while a script does not, and running scripts the way the integration job does before committing.
- First step
- The REPL loads InteractiveUtils automatically, and a script run with julia file.jl does not. Add using InteractiveUtils at the top, or avoid the helper in code that runs unattended, then run the script as the job does, julia --startup-file=no file.jl, in a fresh process.
- Follow-ups
-
- Which other helpers behave like subtypes?
- How can a startup.jl file hide the same kind of problem?
- How would you make the job run the script exactly as you do?
From the lesson The REPL, scripts and the @main entry point
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 2 minutes
-
Mid to senior
Design a small Julia command-line tool that converts numbers given as arguments and is called from shell pipelines. Which entry point, output streams and exit codes would you use, and how would you test them?
- What it tests
- Using @main and its return value as the exit status, standard output for results and standard error for messages, distinct non-zero codes, and tests that run the script as a separate process.
- First step
- Put the logic in functions and add an entry point, function (@main)(args), that returns 0 on success and a non-zero code, such as 2, for bad input. Print results to standard output and messages to standard error, so the next program in a pipeline receives only data.
- Follow-ups
-
- What happens on Julia 1.10, and how would you support it?
- Why should errors go to standard error?
- How do you test the exit status from Julia itself?
From the lesson The REPL, scripts and the @main entry point
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
A colleague's notebook shows 3 wet days, but when you run the same notebook from top to bottom you get an UndefVarError instead. How do you find the cause, and how do you make the result reproducible?
- What it tests
- Recognising hidden state left by cells that were deleted or run out of order, and moving the logic into functions and a script that runs in a fresh process.
- First step
- Restart and run every cell from the top: the first cell that fails names a variable that only existed in the old session. In this case a deleted cell defined threshold, so put that definition back, or better, pass the threshold in as an argument.
- Follow-ups
-
- How does Pluto prevent this?
- Why is a fresh process a stronger test than restarting the kernel?
- How would you share the analysis so that others get the same numbers?
From the lesson Notebooks, editors and the Revise workflow
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
You use Revise in a long-running session. You edit a function in your package and save, yet a long simulation you started earlier keeps behaving the old way. List the likely causes in order and how you would check each one.
- What it tests
- Knowing world age, so that running code keeps old methods, Revise's loading order and tracking rules, and the limit on redefining structs before Julia 1.12.
- First step
- Ask whether the code that is running started before the edit: a running function or task keeps the methods of its world age. Call the function fresh at the prompt; if that shows the new behaviour, only the long run is stale, so restart it or call through invokelatest.
- Follow-ups
-
- How do you check that Revise is tracking the file?
- What changes when the edit is to a struct?
- When is restarting the session the right answer?
From the lesson Notebooks, editors and the Revise workflow
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes