Aliasing a function


#1

When using ImageView I find my fingers typing imview rather than imshow. So
imview = imshow

And it works! Well why shouldn’t it? Once again pat on the back to the language designers.
BTW, what is the technical term for this assignment? Alias is not the correct term.


#2

Make sure you make it a const:

const imview = imshow

Whats wrong with calling this an alias?


#3

Interestingly, calling assignment “aliasing” might help people understand how it works in Julia since it makes it crystal clear that all you’re doing is causing two different names to refer to the same thing. Of course, it has a certain implication of permanence, which is not the case without const.

Note that you do really want that const here since otherwise the compiler is forced to pessimize all code surrounding a call to imview since it can’t know that the value and therefore the behavior won’t change at any moment (it could literally happen between any two non-inlined function calls).


#4

@fredrikekre Thankyou @StefanKarpinski thankyou also. Your point since it can’t know that the value and therefore the behavior won’t change at any moment of course chimes with the Julia type system. I read recently that optionally typed languages such as Python (*) the compiler/interpreter must do the same thing - they type of a variable at any given time can change,

(*) Really, really must stop picking on Pythons.