Note that there are some explanatory texts on larger screens.

plurals
  1. USJonah
    primarykey
    data
    text
    plurals
    1. COPeter, my concern with using fields (which seems valid, based on the other replies) is that I am basically "hacking" the intended OO use of fields, which is to store object state. In this case, the fields would not be storing object state, but acting as temporary placeholders to pass information between a method and its submethod during the execution of that method.
      singulars
    2. COPeter, recall my example was a simplified version of the real problem, which would have been too long and cumbersome to paste in. Your solution would indeed be exactly what I'd do if each sub-method only had to return 1 value. The problem is that in the actual problem each submethod would need to return at least 2 values, and then we'd need to be returning objects or arrays, and we're back in the same boat.
      singulars
    3. CO@Jon: 2 things. In my actual code, the submethods perform their own iteration (a small loop of length 10) and some simple arithmetic. I decided to split them up to improve readability and to avoid code duplication -- not really because they were doing a ton of calculation. To me, from a learning perspective, the more important question is the theoretical one raised. I think it would be possible to cook up a less silly example than mine that still retained the essential problem being illustrated. Or do you think that's not true? I'll think about it more and try to come up with something.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload