3 ms·
> In turn what the author is saying is precisely what he says, no more, no less - explicit code is code whose behavior you can understand just by reading it, wi
by judofyr 9y ago
> In turn what the author is saying is precisely what he says, no more, no less - explicit code is code whose behavior you can understand just by reading it, with no external context, like how the runtime currently works on a particular hardware.
I'm not sure where this definition is coming from. Let's look at this code:
vec.len()
I understand this behaviour very clearly. This will invoke the method given the following rules:
- Look for `len` on the type of `vec`
- If `vec` implements Deref it will look for `len` there
- Look for `len` on traits that the type of `vec` implements
- And so on…
Yes, the behaviour is conditional, but it's still well-defined and easy to understand, although complex.
"Implicit" is usually used when you want to describe situations where there are multiple interpretations, and one is chosen due to context. In Ruby:
first_name + " " + last_name
In this example `first_name` can either be a local variable or a method call (which can either be in the same class, an included module, or a method_missing). Here it turns out it was a method call, and we therefore call this an "implicit method call". I can rewrite:
self.first_name + " " + self.last_name
In this case there is a single interpretation: It can only be a method call.
However, while this code is explicit on whether or not it's a method call, it's not explicit about which method is being invoked. Usually this implicitness is considered a good feature since it allows abstraction, polymorphism and so on.