# Is there a matlab-style linter for finding straggler code?

I remember in matlab, if you had some buggy line like the one that follows, it would give you a nice red squiggle and a note telling you that you probably messed up:

``````cur_RHS = K_F(cur_reactor)

cur_RHS = K_n(cur_reactor) ^ 2
``````

Is there linter package (hopefully for sublime) that tells users about potential bugs like this?

For clarity, the above should multiply the two lines and assign it to `cur_RHS`

// please try to not focus on why the two should just be on one line to begin with

Why should that be a potential bug?

1 Like

Because `cur_RHS` is set equal to something twice.

The first time literally does nothing. They’re supposed to be multiplied

edit: to highlight what I’m suggesting, see this matlab image:

Matlab functions are always pass-by-value, which makes it easy to lint unused, overwritten bindings. Julia, on the other hand, passes arrays by reference, so you have to check for mutation all the way down the call chain.

``````K_n(r) = r .+ 1

function K_F(r)
r .*= 2
end
# Better to call this K_F!(r), but '!' is a syntax convention, not a guarantee

cur_reactor = ones(3)
cur_RHS = K_F(cur_reactor)         # => cur_reactor = [2.0, 2.0, 2.0]
cur_RHS = K_n(cur_reactor) .^ 2    # => cur_RHS = [9.0, 9.0, 9.0]
``````
1 Like

``````cur_eq = 2

function f()
if rand() < 0.5
global cur_eq
cur_eq *= 2
end
end

f()    # has cur_eq been modified? who knows??
``````

Shouldn’t mutating functions end in a bang (!)?

// this would probably require the linter to be opinionated, then?

And to the second response, how does matlab solve the changing global variable problem?

(while still providing that warning)

VSCode gives potentially unused variable warnings. Not sure about that specific example.

There’s a Lint.jl but seems unmaintained, and I’m not sure if this works anymore. You may wanna have a try.

A linter usually examines (local) syntax. It can only do so much.

You should rely on unit tests instead, and aim for high test coverage — Julia’s tooling infrastructure makes this particularly easy.