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

**URL:** <https://discourse.julialang.org/t/is-there-a-matlab-style-linter-for-finding-straggler-code/14447>\
**Category:** General Usage\
**Tags:** question\
**Created:** [September 2, 2018, 8:15pm UTC](https://discourse.julialang.org/t/is-there-a-matlab-style-linter-for-finding-straggler-code/14447 "2018-09-02T20:15:11Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [September 2, 2018, 8:15pm UTC](https://discourse.julialang.org/t/is-there-a-matlab-style-linter-for-finding-straggler-code/14447/1 "2018-09-02T20:15:12Z")

</div>

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:

```julia
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

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [September 2, 2018, 11:58pm UTC](https://discourse.julialang.org/t/is-there-a-matlab-style-linter-for-finding-straggler-code/14447/2 "2018-09-02T23:58:51Z")

</div>

Why should that be a potential bug?

---

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [September 3, 2018, 1:00am UTC](https://discourse.julialang.org/t/is-there-a-matlab-style-linter-for-finding-straggler-code/14447/3 "2018-09-03T01:00:07Z")

</div>

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:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/9/4/9405312a05b4483f242ee6f94ba2071c4f8cc33f.png)

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [September 3, 2018, 4:06am UTC](https://discourse.julialang.org/t/is-there-a-matlab-style-linter-for-finding-straggler-code/14447/4 "2018-09-03T04:06:34Z")

</div>

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.

```julia
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]

```

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [September 3, 2018, 4:10am UTC](https://discourse.julialang.org/t/is-there-a-matlab-style-linter-for-finding-straggler-code/14447/5 "2018-09-03T04:10:47Z")

</div>

Re: your second example,

```julia
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??

```

---

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [September 3, 2018, 4:13am UTC](https://discourse.julialang.org/t/is-there-a-matlab-style-linter-for-finding-straggler-code/14447/6 "2018-09-03T04:13:54Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [September 3, 2018, 4:45am UTC](https://discourse.julialang.org/t/is-there-a-matlab-style-linter-for-finding-straggler-code/14447/7 "2018-09-03T04:45:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JohnnyChen94](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnnychen94/32/29979_2.png) [@JohnnyChen94](https://discourse.julialang.org/u/JohnnyChen94)\
**Post date:** [September 3, 2018, 5:03am UTC](https://discourse.julialang.org/t/is-there-a-matlab-style-linter-for-finding-straggler-code/14447/8 "2018-09-03T05:03:32Z")

</div>

There’s a [Lint.jl](https://github.com/tonyhffong/Lint.jl) but seems unmaintained, and I’m not sure if this works anymore. You may wanna have a try.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 3, 2018, 5:59am UTC](https://discourse.julialang.org/t/is-there-a-matlab-style-linter-for-finding-straggler-code/14447/9 "2018-09-03T05:59:05Z")

</div>

> [@djsegal](#):
>
> // this would probably require the linter to be opinionated, then?

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.
