Hi Tobias:

My 'hard to find bug' statement should really have read 'hard to find bug from 
a newbie perspective'. These bugs would be obvious to someone familiar with 
basic programming. My numpy example is too big to give now but here is a simple 
metropolis hasting markov chain short example:

theta_curr = 0.0
for k=1:10_000
        theta_prop = theta_curr 
        theta_prop += randperturbation()
        likelihoodratio = computelr(theta_prop, theta_curr)
        if rand() < minimum([1,likelihoodratio])
                theta_curr = theta_prop
        else
                theta_curr = theta_curr
        end
end

The variable theta_prop is only supposed to be set to theta_curr if the first 
conditional is true. I guess in python += acts inplace, so that line 3 actually 
changes theta_curr, which would be a bug. In my numpy excursion, once I 
realized this (after many more lines of code) my stomach turned and I suddenly 
decided I didn't know what the heck I was doing and ended up running back to 
safe matlab. I had a similar feeling with vec(a) where after learning the 
output was the same as input I suddenly had to review all my code that used 
vec(a) to make sure I wasn't spuriously fusing variables. The thing about Julia 
that I like is that I could start out reasoning about code immediately (if I 
avoided functions with ! at the end) and then slowly venture into the more 
modern techniques....but the point is I was scientifically productive immediate 
without knowing much about programing.

I definitely agree that the suffix "!" works well. In fact I like it so much I 
was just hoping that there would be something similar to indicate when output 
shared input member. I was thinking there would be reshape(A,dims), 
reshape!(A,dims) and reshape*(A,dims) where reshape(A,dims) returned a copy, 
reshape!(A,dims) mutated A and reshape*(A,dims) left the arguments alone but 
returned a variable which shared memory with A. Anyway, that suggestion now 
seems silly after hearing Tim say that there are really only corner, easy to 
understand, cases where I need to worry about it.

Again, thanks all for the discussion!
Ethan

Reply via email to