63

What is easier to understand, a big boolean statement (quite complex), or the same statement broken down into predicate methods (lots of extra code to read)?

Option 1, the big boolean expression:

    private static bool ContextMatchesProp(CurrentSearchContext context, TValToMatch propVal)
    {

        return propVal.PropertyId == context.Definition.Id
            && !repo.ParentId.HasValue || repo.ParentId == propVal.ParentId
            && ((propVal.SecondaryFilter.HasValue && context.SecondaryFilter.HasValue && propVal.SecondaryFilter.Value == context.SecondaryFilter) || (!context.SecondaryFilter.HasValue && !propVal.SecondaryFilter.HasValue));
    }

Option 2, The conditions broken down into predicate methods:

    private static bool ContextMatchesProp(CurrentSearchContext context, TValToMatch propVal)
    {
        return MatchesDefinitionId(context, propVal)
            && MatchesParentId(propVal)
            && (MatchedSecondaryFilter(context, propVal) || HasNoSecondaryFilter(context, propVal));
    }

    private static bool HasNoSecondaryFilter(CurrentSearchContext context, TValToMatch propVal)
    {
        return (!context.No.HasValue && !propVal.SecondaryFilter.HasValue);
    }

    private static bool MatchedSecondaryFilter(CurrentSearchContext context, TValToMatch propVal)
    {
        return (propVal.SecondaryFilter.HasValue && context.No.HasValue && propVal.SecondaryFilter.Value == context.No);
    }

    private bool MatchesParentId(TValToMatch propVal)
    {
        return (!repo.ParentId.HasValue || repo.ParentId == propVal.ParentId);
    }

    private static bool MatchesDefinitionId(CurrentSearchContext context, TValToMatch propVal)
    {
        return propVal.PropertyId == context.Definition.Id;
    }

I prefer the second approach, because I see the method names as comments, but I understand that it's problematic because you have to read all the methods to understand what the code does, so it abstracts the code's intent.

guntbert
  • 109
  • 3
willem
  • 1,053
  • 9
  • 10
  • this looks like the case for [Specification pattern](http://programmers.stackexchange.com/a/148855/31260) – gnat Mar 09 '16 at 17:33
  • 13
    Option 2 is similar to what Martin Fowler recommends in his refactoring book. Plus your method names serve as the intent of all the random expressions, the content of the methods are just the implementation details that could change over time. – programmer Mar 09 '16 at 18:00
  • 2
    Is it really the same expression? "Or" has a lesser precedence than "And", Anyways the second tells your intent, the other (first) is technical. – thepacker Mar 09 '16 at 21:54
  • Probably the first one, because if I want to understand the second one, I have to read about 3-4 times as much code. – user253751 Mar 09 '16 at 23:57
  • 3
    What @thepacker says. The fact that doing it the first way has caused you to make a mistake is a pretty good clue that the first way is not easily understandable to a very important sector of your target audience. Yourself! – Steve Jessop Mar 10 '16 at 11:08
  • 1
    @immibis no, you can tell what the if statement should do now without having to read or understand any of the subfunctions. Plus they can now easily be updated and tested independently – JamesRyan Mar 10 '16 at 12:39
  • Specifically in this scenario: using expression-bodied members would make it a lot less verbose here – Jeroen Vannevel Mar 10 '16 at 13:47
  • @Jason: Martin Fowler's refactoring book doesn't recommend either way. He states that you can pull something apart into many small methods, and you can put many small methods back together. Both is refactoring. – gnasher729 Mar 10 '16 at 15:15
  • @gnasher729 I believe that was undoing certain things that weren't "paying for themselves" or whatever. If anyone cares they can read the book and come up with a third translation. – programmer Mar 10 '16 at 15:31
  • SecondOne. And I would also try to refactor the big if into a funtion in itself. For example " if( needsSecondaryFilter( ...) ). Certainly this if must have some business or technical value that is nor explicity at the moment – Borjab Mar 10 '16 at 15:38
  • 3
    Option 3: I don't like either one. The second is ridiculously verbose, the first is not equivalent to the second. Parentheses help. – David Hammen Mar 10 '16 at 15:58
  • 3
    This may be pedantic, but you don't have **any** `if` statements in either block of code. Your question is about *Boolean expressions*. – Kyle Strand Mar 10 '16 at 21:03
  • I think that the second option is way to verbose. The best option (at least, for me), would be to use the first method but with parentheses to group the statements, and indentation to make each part stand out – Jojodmo Mar 11 '16 at 00:17
  • If you are willing to flesh out more of the implementation (e.g. also showing the types `CurrentSearchContext`, `TValToMatch` and `SecondaryFilter`), you might get better opinions and *code feedback* on [Code Review](https://codereview.stackexchange.com) too... – h.j.k. Mar 11 '16 at 10:01
  • Consider which of the two is the easiest to investigate in a debugger. I would personally clearly prefer #2 – Thorbjørn Ravn Andersen Mar 11 '16 at 12:40
  • @willem You sure sparked a lot of debate! Look at all the discussion over each answer. Great question! – BuvinJ Mar 11 '16 at 15:06
  • These methods seem too generic i.e. `ContextMatchesProp()` and `MatchedSecondaryFilter()`. Is there no way you can simply use the existing functionality of LINQ `.Where(lambda)` extension methods? It seems you are simply trying to perform a conditional comparison and return a boolean. Or maybe you can write your own extension methods to make this more readable and "fluent." – user1477388 Mar 11 '16 at 17:14

11 Answers11

88

What is easier to understand

The latter approach. It's not only easier to understand but it is easier to write, test, refactor and extend as well. Each required condition can be safely decoupled and handled in it's own way.

it's problematic because you have to read all the methods to understand the code

It's not problematic if the methods are named properly. In fact it would be easier to understand as the method name would describe the intent of condition.
For an onlooker if MatchesDefinitionId() is more explanatory than if (propVal.PropertyId == context.Definition.Id)

[Personally, the first approach sores my eyes.]

wonderbell
  • 722
  • 5
  • 7
  • 12
    If the methods names are good, then it is also easier to understand. – BЈовић Mar 10 '16 at 08:39
  • And please, make them (method names) significative and short. 20+ chars method names sore my eyes. `MatchesDefinitionId()` is borderline. – Mindwin Remember Monica Mar 10 '16 at 18:12
  • 2
    @Mindwin If it comes down to a choice between keeping method names "short" and keeping them meaningful, I say take the latter every time. Short is good, but not at the expense of readability. – Ajedi32 Mar 11 '16 at 14:11
  • @Ajedi32 one doesn't have to write an essay on what the method does on the method name, or to have gramatically sound method names. If one keeps the abbreviation standards clear (across the work group or organization) won't be a problem with short names and readability. – Mindwin Remember Monica Mar 11 '16 at 14:29
  • Use Zipf's law: make things more verbose to *discourage* their use. – Alex Shroyer Mar 11 '16 at 15:51
44

If this is the only place these predicate functions would be used, you can also use local bool variables instead:

private static bool ContextMatchesProp(CurrentSearchContext context, TValToMatch propVal)
{
    bool matchesDefinitionId = (propVal.PropertyId == context.Definition.Id);
    bool matchesParentId = (!repo.ParentId.HasValue || repo.ParentId == propVal.ParentId);
    bool matchesSecondaryFilter = (propVal.SecondaryFilter.HasValue && context.No.HasValue && propVal.SecondaryFilter.Value == context.No);
    bool hasNoSecondaryFilter = (!context.No.HasValue && !propVal.SecondaryFilter.HasValue);

    return matchesDefinitionId
        && matchesParentId
        && matchesSecondaryFilter || hasNoSecondaryFilter;
}

These could also be broken down further and reordered to make them more readable, e.g. with

bool hasSecondaryFilter = propVal.SecondaryFilter.HasValue;

and then replacing all instances of propVal.SecondaryFilter.HasValue. One thing that immediately sticks out then is that hasNoSecondaryFilter uses logical AND on the negated HasValue properties, while matchesSecondaryFilter uses a logical AND on un-negated HasValue -- so it's not the exact opposite.

Simon Richter
  • 1,568
  • 9
  • 10
  • 3
    This solution is pretty good and I've certainly written lots of similar code. It's very readable. The downside, compared to the solution I posted, is speed. With this method, you perform a pile of conditional tests no matter what. In my solution, the operations can be dramatically reduced based on the values processed. – BuvinJ Mar 10 '16 at 16:52
  • 5
    @BuvinJ Tests like the ones shown here should be fairly cheap, so unless I know some of the conditions are expensive or unless this is extremely performance sensitive code, I would go for the more readable version. – svick Mar 10 '16 at 17:03
  • 1
    @svick No doubt this is unlikely to introduce a performance issue most of the time. Still, if you can reduce operations without losing readability, then why not do so? I'm not convinced this is much more readable than my solution. It does give self documenting "names" to the tests - which is nice... I think it comes down to the specific use case and how understandable the tests are in their own right. – BuvinJ Mar 10 '16 at 17:12
  • Adding comments can help readability too... – BuvinJ Mar 10 '16 at 17:14
  • @BuvinJ What I really like about this solution is that by ignoring everything except the last line, I can quickly understand what it's doing. I do think this is more readable. – svick Mar 10 '16 at 17:22
  • @svick I understand where you're coming from. In my first comment, I stated that I write code like this too. It's a toss up here between my answer and Simon's. – BuvinJ Mar 10 '16 at 17:32
  • @BuvinJ: I support that this solution is much more readable than yours. I admit that it's a personal preference, but you should do too. This answer wins the grand prize! EDIT: Explanatory assignments to variables and verbose naming of variables and methods is also in for winning the grand prize in my book. When I read other people's code, the thing that annoys me above all is that they do not take the time to explain whatever the hell they are trying to do and litter the code with stupid comments like 'getting first item from array' I KNOW THAT, I CAN READ YOUR CODE DAMNIT. GIVE ME USEFUL INFO – klaar Mar 11 '16 at 09:14
  • @BuvinJ It seems likely that the compiler/JIT would optimise this code to avoid any unnecessary computation. – flamingpenguin Mar 11 '16 at 13:43
  • @flamingpenguin Maybe... I don't know for sure, but I don't think this would end up optimized. – BuvinJ Mar 11 '16 at 14:55
  • By far the most readable solution here. – Christopher Berman Mar 29 '16 at 18:40
41

In general, the latter is preferred.

It makes the call site more reusable. It supports DRY (meaning you have less places to change when the criteria change, and can do it more reliably). And very often those sub-criteria are things that will be reused independently elsewhere, allowing you to do that.

Oh, and it makes this stuff a lot easier to unit test, giving you confidence that you've done it correctly.

Lightness Races in Orbit
  • 8,755
  • 3
  • 41
  • 45
Telastyn
  • 108,850
  • 29
  • 239
  • 365
  • 1
    Yes, though your answer should also address fixing the use of `repo`, which appears a static field/property, ie a global variable. Statics methods should be deterministic and not use global variables. – David Arno Mar 09 '16 at 21:48
  • 3
    @DavidArno - while that is not great, it seems tangential to the question at hand. And without more code it's _plausible_ that there's a semi-valid reason for the design to work like that. – Telastyn Mar 09 '16 at 21:57
  • 1
    Yes, nevermind repo. I had to obfuscate the code a little, don't want to share client code as-is on the interwebs :) – willem Mar 10 '16 at 06:10
23

If it's between these two choices, then the latter is better. These are not the only choices, however! How about breaking up the single function into multiple ifs? Test for ways to exit the function to avoid additional tests, roughly emulating a "short circuit" in a single line test.

This is easier to read (you might need to double check the logic for your example, but the concept holds true):

private static bool ContextMatchesProp(CurrentSearchContext context, TValToMatch propVal)
{
    if( propVal.PropertyId != context.Definition.Id ) return false;

    if( repo.ParentId.HasValue || repo.ParentId != propVal.ParentId ) return false;

    if( propVal.SecondaryFilter.HasValue && 
        context.SecondaryFilter.HasValue && 
        propVal.SecondaryFilter.Value == context.SecondaryFilter ) return true;

    if( !context.SecondaryFilter.HasValue && 
        !propVal.SecondaryFilter.HasValue) return true;

    return false;   
}
BuvinJ
  • 354
  • 1
  • 10
  • 3
    Why did I get a downvote for this within seconds of posting it? Please add a comment when you downvote! This answer operates just as quickly and is easier to read. So what's the problem? – BuvinJ Mar 10 '16 at 02:02
  • This is a good compromise IMO - you can still read each check as a separate unit, and you don't have to jump around to see them all. – user253751 Mar 10 '16 at 03:22
  • I think it is a nice compromise. Thanks. +1 :) – willem Mar 10 '16 at 06:12
  • I voted up because a mix of this flow and the latter approach in question is my favorite style of handling conditions. – wonderbell Mar 10 '16 at 10:01
  • This is similar to how I have a stack of ifs that validate and throw exceptions at the top of all my public methods. Extending that flow and multiple exit style to private methods is quite idiomatic and would fit nicely into my code base. – Mike Mar 10 '16 at 13:53
  • 2
    @BuvinJ: Absolutely nothing wrong with it. The same as the original code, except you don't have to fight with a dozen parentheses and a single line that stretches past the end of the screen. I can read that code from top to bottom and understand it immediately. WTF count = 0. – gnasher729 Mar 10 '16 at 15:20
  • 1
    Returning other than at the end of the function makes code less readable, not more readable, IMO. I prefer single exit point. Some good arguments both ways at this link. http://stackoverflow.com/questions/36707/should-a-function-have-only-one-return-statement – Bradley Thomas Mar 10 '16 at 15:26
  • 5
    @Brad thomas I can't agree with the single exit point. It usually leads to deep nested parenthesis. The return ends the path so for me is much easier to read. – Borjab Mar 10 '16 at 15:43
  • 1
    @BradThomas I fully agree with Borjab. Avoiding deep nestings is actually why I use this style more often than to break up long conditional statements. I use to find myself writing code with tons of nestings. Then, I started looking for ways to hardly ever go more than one or two nestings deep, and my code has become MUCH easier to read and maintain as a result. If you can find a way to exit your function, do so as soon as possible! If you can find a way to avoid deep nestings and long conditionals, do so! – BuvinJ Mar 10 '16 at 16:08
  • 1
    @BradThomas: Strict adherence to dogma doesn't make your code more readable. If you think the code is not readable, read it and tell us where you have a problem reading it. I can't find anything that isn't readable. It's the kind of code that I can read at about one inch per second vertically. WTF count = 0. Original, first version, I'm speechless. Second version, four WTF's. – gnasher729 Mar 10 '16 at 16:24
  • @BradThomas: Is that really your opinion? Or is it something that you read? I _have_ opinions about code, and this code is perfectly fine. – gnasher729 Mar 10 '16 at 16:25
  • I think that the text books probably agree with @BradThomas on this one. The thing is, there's a big difference between theory and application... There are a lot of things to throw out from "Programming 101". – BuvinJ Mar 10 '16 at 17:06
  • 1
    @BuvinJ Single-return was from practical application, but solely for something that we don't care about here: manual memory management. It was so you could confidently release resources before return, without having to do that in several places. It's nowadays mostly just cargo-cult programming. – Izkata Mar 10 '16 at 21:29
  • Sure, if you have resources to release, then a single exit makes sense. That doesn't mean it has to be a "rule" to follow in the endless functions and languages which don't have to that to worry about! – BuvinJ Mar 10 '16 at 22:53
  • The main reason I supported @BradThomas in this one, is that I *really* don't like the fact that I have to take into account previous boolean tests that happened before in the flow and glue them to the current test to actually know what is being tested right now, because each test depends on the outcome of the previous. That is why I would never tear them apart into different exit-paths. I want completeness. EDIT: *If* I were to make this more presentable, then it would be by putting subtests into separate booleans and then combining those booleans to do the big test in the end, like SimonR. – klaar Mar 11 '16 at 09:10
  • @klaar Erm, you have multiple exit paths anyway. The conditional would be lazy evaluated and drop out to the return as soon as one check fails. The fact that the massive conditional is masking the fact is a bad thing, not a good one! – Tim B Mar 11 '16 at 12:18
  • I've run into "single return path" fanatics a few times and they always annoy me. If you have too many returns in your function to follow what it means then it means that your function is too big. Preventing multiple returns with ridiculous nesting is not solving the core problem that you need to break your function up! – Tim B Mar 11 '16 at 12:20
  • @TimB Yes I know that *what* this function does is the same thing as one monstrously big if-evaluation, but the fact that the conditions are splintered up into separate ifs with their presence extracted from the whole is confusing me thoroughly. I don't like the way how a return stops the flow, because I have to read it carefully; I cannot just see it at a glance by checking indentation. EDIT: that's why I like the finegrained solution by Simon Richter way more; it splits it up into atomic abstractions and deals with them in the end, instead of worrying about details like null/empty checks. – klaar Mar 11 '16 at 12:56
  • But you can see it at a glance. Each "if" exits. Put "else if" on the later ones if you prefer but you are the only person I've ever met would find this hard to read. Maybe you just need to get used to it. – Tim B Mar 11 '16 at 12:59
  • @klaar makes a lot of good points. Simon's solution is very good for many reasons. Saying that this is hard to read though? That's not a good argument against this. My solution operates in almost exactly the same manner that the original does - using short circuits. It just does that explicitly and breaks the tests into more palatable chunks. – BuvinJ Mar 11 '16 at 15:00
  • When you have an "is" function, where the whole point is to evaluate something verse performing some tasks, I think that changes the dynamic of the multiple exit debate. – BuvinJ Mar 11 '16 at 15:02
  • I like that this puts the laziness front-and-center while being easier (for me) to read than any of the alternatives on this page. – Alex Shroyer Mar 11 '16 at 15:44
  • **Please avoid using comments for extended discussions. If you would like to continue the conversation then please visit our Chat. Thank you.** – maple_shaft Mar 11 '16 at 18:11
  • I don't much like this solution. The advantage of willem's Option 2 (and, for me, Simon Richter's answer in particular) is that it composes the bool checks into conceptual chunks, with the ultimate return-comparison operating on these chunks. If the functions (or bool variables, per Simon) are named well, the complex bool operation becomes an almost natural language construct. This answer doesn't offer that kind of conceptual chunking. You could use comments to supplement, but then Simon's answer has the advantage of not needing comments. – Christopher Berman Mar 29 '16 at 18:39
10

I like option 2 better, but would suggest one structural change. Combine the two checks on the last line of the conditional into a single call.

private static bool ContextMatchesProp(CurrentSearchContext context, TValToMatch propVal)
{
    return MatchesDefinitionId(context, propVal)
        && MatchesParentId(propVal)
        && MatchesSecondaryFilterIfPresent(context, propVal);
}

private static bool MatchesSecondaryFilterIfPresent(CurrentSearchContext context, 
                                                    TValToMatch propVal)
{
    return MatchedSecondaryFilter(context, propVal) 
               || HasNoSecondaryFilter(context, propVal);
}

The reason I suggest this is that the two checks are a single functional unit, and nesting parenthesis in a conditional is error prone: Both from the standpoint of initially writing the code and from the standpoint of the person reading it. This is especially the case if the sub-elements of the expression don't follow the same pattern.

I'm not sure if MatchesSecondaryFilterIfPresent() is the best name for the combination; but nothing better is immediately coming to mind.

  • Very nice, trying to explain what is being done inside the methods is actually better than just restructuring calls. – klaar Mar 11 '16 at 09:08
2

Though in C#, the code is not very object oriented. It is using static methods and what looks like static fields (e.g. repo). It is generally held that statics make your code hard to refactor and difficult to test, while hampering reusability, and, to your question: static usage like this is less readable & maintainable than object-oriented construction.

You should convert this code to a more object-oriented form. When you do, you'll find that there are sensible places to put code that does comparison of objects, of fields, etc.. It is likely that you could then ask objects to compare themselves, which would reduce your big if statement to a simple request to compare (e.g. if ( a.compareTo (b) ) { }, which could include all the field comparisons.)

C# has a rich set of interfaces and system utilities for doing comparisons on objects and their fields. Beyond the obvious .Equals method, for starters, look into IEqualityComparer, IEquatable, and utilities like System.Collections.Generic.EqualityComparer.Default.

Erik Eidt
  • 33,282
  • 5
  • 57
  • 91
0

The latter is definitely preferred, I have seen cases with the first way and it's almost always impossible to read. I have made the mistake of doing it the first way and was asked to change it to predicate methods.

Snoop
  • 2,718
  • 5
  • 24
  • 52
0

I would say that the two are about the same, IF you add some whitespace for readability and some comments to help the reader over the more obscure parts.

Remember: good commentary tells the reader what you were thinking when you wrote the code.

With changes such as I've suggested, I would probably go with the former approach, as it is less cluttered and diffuse. Subroutine calls are like footnotes: they provide useful information but disrupt the flow of reading. If the predicates were more complex, then I would break them out into separate methods so that the concepts they embody can be built up in understandable chunks.

Mark Wood
  • 129
  • Deserves a +1. Good food for thought, even though not popular opinion based on the other answers. Thanks :) – willem Mar 10 '16 at 06:13
  • 1
    @willem No, it doesn't deserve +1. Two approaches are not the same. The additional comments are stupid and unneeded. – BЈовић Mar 10 '16 at 08:45
  • 2
    A good code **NEVER** depends on comments to be understandable. In fact the comments are the worst clutter a code could have. The code should speak for itself. Also, the two approaches that OP wants to evaluate can never be "about the same", no matter how many whitespaces one adds. – wonderbell Mar 10 '16 at 09:29
  • It is better to have a meaningfull function name than having to read the comment. As stated in the "Clean Code" book a comment is a failure to express throw code. Why explain what you are doing when the function could have stated it much more clearly. – Borjab Mar 10 '16 at 15:47
0

Well, if there are parts you might want to reuse, separating them out into separate properly named functions is obviously the best idea.
Even if you might never reuse them, doing so might allow you to better structure your conditions and give them a label describing what they mean.

Now, let's look at your first option, and concede that neither was your indentation and line-breaking all that useful, nor was the conditional structured all that well:

private static bool ContextMatchesProp(CurrentSearchContext context, TValToMatch propVal) {
    return propVal.PropertyId == context.Definition.Id && !repo.ParentId.HasValue
        || repo.ParentId == propVal.ParentId
        && propVal.SecondaryFilter.HasValue == context.SecondaryFilter.HasValue
        && (!propVal.SecondaryFilter.HasValue || propVal.SecondaryFilter.Value == context.SecondaryFilter.Value);
}
Deduplicator
  • 8,591
  • 5
  • 31
  • 50
0

The first one is absolutely horrible. You have been using || for two things on the same line; that is either a bug in your code or an intent to obfuscate your code.

    return (   (   propVal.PropertyId == context.Definition.Id
                && !repo.ParentId.HasValue)
            || (   repo.ParentId == propVal.ParentId
                && (   (   propVal.SecondaryFilter.HasValue
                        && context.SecondaryFilter.HasValue 
                        && propVal.SecondaryFilter.Value == context.SecondaryFilter)
                    || (   !context.SecondaryFilter.HasValue
                        && !propVal.SecondaryFilter.HasValue))));

That's at least halfway decently formatted (if the formatting is complicated, that's because the if-condition is complicated), and you have at least a chance to figure out if anything in there is nonsense. Compared to your rubbish formatted if, anything else is better. But you seem to be able to do only extremes: Either a complete mess of an if statement, or four completely pointless methods.

Note that (cond1 && cond2) || (! cond1 && cond3) can be written as

cond1 ? cond2 : cond3

which would reduce the mess. I'd write

if (propVal.PropertyId == context.Definition.Id && !repo.ParentId.HasValue) {
    return true;
} else if (repo.ParentId != propVal.ParentId) {
    return false;
} else if (propVal.SecondaryFilter.HasValue) {
    return (   context.SecondaryFilter.HasValue
            && propVal.SecondaryFilter.Value == context.SecondaryFilter); 
} else {
    return !context.SecondaryFilter.HasValue;
}
gnasher729
  • 42,090
  • 4
  • 59
  • 119
-4

I don't like either of those solutions, they are both hard to reason about, and difficult to read. Abstraction to smaller methods just for smaller methods sake doesn't always solve the problem.

Ideally, i think you would metaprogrmatically compare properties, so you don't have a define a new method or if branch every time you want to compare a new set of properties.

I am not sure about c#, but in javascript something like this would be MUCH better and could at least replace MatchesDefinitionId and MatchesParentId

function compareContextProp(obj, property, value){
  if(obj[property])
    return obj[property] == value
  return false
}
user1152226
  • 111
  • 6
  • 1
    Should not be a problem to implement something like this in C#. – Snoop Mar 09 '16 at 18:05
  • I'm not seeing how a boolean combination of ~5 calls to `compareContextProp(propVal, "PropertyId", context.Definition.Id)` would be easier to read than the OP's boolean combination of ~5 comparisons of the form `propVal.PropertyId == context.Definition.Id`. It's significantly longer and adds an extra layer without really hiding any of the complexity from the call site. (if it matters, I did not downvote) – Ixrec Mar 22 '16 at 09:21