Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^3: Confused as to why the "casting context" is mis-behaving (model)

by tye (Sage)
on Oct 21, 2010 at 13:22 UTC ( #866549=note: print w/replies, xml ) Need Help??

in reply to Re^2: Confused as to why the "casting context" is mis-behaving ("list vs array", again)
in thread Confused as to why the "casting context" is mis-behaving

The reason I point out the nonsense of it is because I repeatedly see people make mistakes based on the model. I don't think having an incorrect model that leads to the right answer for the wrong reasons in a few cases but also leads to a fundamental misunderstanding and also leads to the wrong answer in a lot of other cases is better than having a better model.

The alternative is not "no model at all". The alternative is actually a simple model that matches reality much better.

- tye        

  • Comment on Re^3: Confused as to why the "casting context" is mis-behaving (model)

Replies are listed 'Best First'.
Re^4: Confused as to why the "casting context" is mis-behaving (model)
by philipbailey (Chaplain) on Oct 21, 2010 at 16:26 UTC

    So what is the "simple model that matches reality"? I guess what you are saying is "it depends, look at the documentation" for each case. Correct me if you are saying something different.

    The difficulty with saying to newer users of Perl that everything is a documented special case is that (1) it is hard to remember all those special cases, and (2) not everything is documented adequately. It's useful to have some default model to explain common behaviour.

      If you try to memorize a big list of cases (whether you pejoratively label them "special" doesn't matter), then you are doing it wrong. This is the same mistake many people make with the precedence table.

      Instead, understand why the cases are there and they are easy to remember. For both scalar context and operator precedence, there are a minority of exceptions that have little sense behind them (and most of those have both a reason why they "don't matter as much" and historic context that explains the imperfect design). The majority are well justified and thus easy to understand and remember.

      If it isn't clear what the useful scalar value is for a particular operation, then reasonable responses include 1) looking up what the scalar return is in that case and why, 2) wondering why you are using scalar context in a way that doesn't make clear sense.

      A really bad response is: consult a fundamentally flawed "model" to make a guess at what is returned and then either be surprised or pat yourself on the back and still not have any clue why that is the most useful thing to return (or, less often, why there isn't really an obvious answer and something more arbitrary got implemented or, rarest, why something other than the most useful value got implemented).

      Yes, part of a correct model here is "it depends". Inventing an incorrect model, especially one as elaborate as "is it an array or is it a list?" tends to become, just so you can use it to make poorly-motivated guesses and avoid understanding how scalar context is useful in many cases, seems of dubious value at best. Certainly not enough value to justify the wrong answers it provides much less the confusion it leads to.

      It's useful to have some default model to explain common behaviour.

      A slice in scalar context is "common behavior"? I don't think so.

      - tye        

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://866549]
[Discipulus]: oiskuu from the top aka 0-0 coords
[LanX]: edge or node?
[oiskuu]: from each height difference, there's a fixed number of "moves right" - "moves left". So it's a number of combinations.
[Discipulus]: I already know how much distinct paths exists but to demonstrate the property i want to have them all
[oiskuu]: ie C(n, k); where n is height difference, k is position in the line
[Discipulus]: infact there are 70 distinct path to reach the tale wich holds 70
[Discipulus]: what i want is to compute them

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (10)
As of 2018-03-19 11:05 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (239 votes). Check out past polls.