Does redefining Base.values break Julia too easily?

Hi all — I was a bit surprised that old code using “values” as a variable name wouldn’t run under 0.7. Probably rather late to the party, I found out there is now a function Base.values.

Being a tad perverse, I tried the following

import Base.values
Base.values(x) =2

which compiled ok, though it didn’t increase the number of methods, which remained 4.

However, nothing worked after that. Of course extending the methods of a Base functions in this way is crazy, and I suppose a beginner would quickly learn to stop doing so, but really, ought this to be as easy as above?

Julia gives you the power to do a lot of very silly things–it’s both a benefit and (sometimes) a curse. Try redefining Base.:+(x::int, y::Int) and watch your REPL melt immediately.

But this is just a consequence of the fact that we really mean it when we say that user code is just as fast and powerful as Base code. Julia lets you define a method for any function on any type you want, and all methods are treated equally by the language regardless of whether they came with Julia or not.

Or, another way of putting it: I’ve heard that a fundamental principle of Julia’s design is to enable people to do (formerly) hard things, rather than to try to stop people from doing silly things. That’s why we’ve had so much work put into an amazingly powerful type and multiple dispatch system and almost no work put into things like private variables or hidden methods. I suspect more tools for “safer” code may come along in the future as the language matures, but I’m personally much happier having a nice sharp kitchen knife than a pair of safety shears :slightly_smiling_face: