It is always good practice to separate your code's IO from its internal computations. The coding-related StackExchange sites are littered with code that mixes Print
(or Println
or putStr
or whatever is the local dialect) inside complex functions. This is bad practice.
In the case of output (as in your example), mixing output statements with computation tends to make the final output of the program dependent on the internal structure of the code. It then becomes difficult to alter that code without breaking the output. For example, you might want to print out a sorted sequence of lines; you happen to extract them from some structure which automatically sorts them, so you naively add print statements as you compute each line. This works. Then you switch to storing the intermediate calculations in a structure which doesn't sort them. Broken output which requires you to remove the print statements, add a sorting step and then put the print statements after that.
If you separate computation from presentation, you don't have this problem.
In your specific example, I don't think either choice is good, because both might fail. Even if you get a valid array, what if it doesn't have a second row? This is a problem you should resolve before your output step. Your second example is actually worse, because it doesn't resolve the problem so adds a pointless extra step.
output=get_array()[2]
print output
Would be better. The retrieval of the data and its output can then be cleanly separated.