Hope everyone is doing safe in these stressful times. I am just getting started with Julia programs and wanted to know about the bug types that typically occur. Are bug types the same as C/C++ or Java? Do different Julia bug types have different consequences?
This is a very general question, so I am not sure what you are expecting here.
If you just write pure Julia, then memory allocation bugs (as eg in C) will not happen, but all kinds of other bugs can. Generally the (near-)zero cost abstractions are a good way to guard against a lot of bugs: eg in
for x in v
do_something(x)
end
the iteration interface will take care of traversing v, precluding all kinds of coding errors that may entail (off-by-one, etc).
Well-designed interfaces hide complexity and can thus reduce bugs, but require some investment for the initial design.
The main difference that I’ve experienced is due to the fact that Julia is a dynamic programming language.
The most common bugs that I have encountered are actually those simple and stupid mistakes e.g. syntax error, method misspelled, wrong number of arguments, wrong type being passed to functions, etc. Sometimes VSCode linter can give me a hint but it doesn’t cover all cases.
I figured that test-driven development is super important for a dynamic language like Julia. So, I started making small functions and writing tests at the same time. Now, I just need to run the tests before I run the program. Perhaps unsurprisingly I am also making the code better. Functions become more composable. They are also smaller and easier to read.
I can share a beginner mistake that I had before. Once upon a time, I created a function that defines a local variable named length. Later in the code, I tried to determine the length of an array and it failed miserably because the length function was hidden away by the local variable. Since then, I’ve learned to avoid naming conflicts with Base functions.
Comparing with Java
The IDE would nudge you to correct problems on every single keystroke. You also cannot compile and run the program unless the code is syntactically correct. So the same kind of issues doesn’t happen.
In my experience, Java bugs are more likely logical problems – improper exception handling, resources not getting released, bad design, etc. Java codebases are generally much larger. The sheer volume of code hides away logical problems more easily, whereas in Julia the code is much more concise and IMO easier to comprehend.
There are a few classes of performance bugs new Julia users often run into. Things like allocating tons of data, using non-const globals, and writing type unstable code are the main ones. Your program will still run, but it is definitely possible to be 1000x slower than you would be with more idiomatic code.
I have coded the same programs (e.g., lattice Boltzmann method in Computational Fluid Dynamics) in the Julia language and C language. I have found that despite all similarities between the Julia and C language, if I code in Julia with the concepts of C language in mind, I will probably face some problems which are not necessarily a Julia language problem. For example, Julia continues doing operation with NaN values, which in C language would throw an error and exit the program. Although, I consider these bad programming, not bugs.
I just want to second that. I’ve been working a fair bit on the VS Code extension, and it is interesting because I write both Julia and TypeScript code that constantly overlaps and is very, very similar in style. My bug rate for TypeScript is way lower than for the Julia code I write, and it is all due to the static type checking I get from TypeScript (and don’t even get me started on what a productivity booster it is that I can just type foo. and then see all the methods that make sense for foo…). For a certain type of code (like the one we are writing for the VS Code extension), static type checking is just awesome. I think there is a certain type of programming problem (IDE extension, language server etc) where one really doesn’t benefit much from the dynamic aspect of Julia, but the lack of a static type checking system is a very, very real and major drawback.
Having said that, here is an interesting aspect: TypeScript is a strict superset of JavaScript, i.e. any JavaScript is valid TypeScript. Of course, JavaScript is super dynamic, and then TypeScript has this genius way for users to opt-in to static type checking for certain parts of their code. We’re slowly exploring to what extent we can give some feedback in StaticLint.jl that is similar for Julia.