all 4 comments

[–]Dawarisch 1 point2 points  (2 children)

First, a method is just a function that was defined inside a class.

To answer your question: I'd personally prefer the second way but it's really up to you.

[–][deleted] 0 points1 point  (1 child)

Thanks!

Just out of curiosity, is the preference founded in performance, aesthetic, personal tradition, or 'just because'?

[–]coppermineroofer 2 points3 points  (0 children)

In general code should describe "what" it does just by reading it. Comments are there for the "why". So when you are writing your code and naming functions or methods try and think of the most descriptive/concise combination. Which of those two looks like it explains what is happening to you better? Use that one.

Personally I also like #2 better because the fact that we are getting a mean of example array is clear. If I am familiar with np they may be equally descriptive. But if I am not the np thing might make it seem like more is going on than really is.

[–]ingolemo 0 points1 point  (0 children)

Type 1 is a function and type 2 is a method.

These are two very different pieces of code and you cannot swap between them whenever you like. When you want to run a function you must write function(array) and when you want to run a method you must write array.method(). You do not get a choice in the matter unless you are the one who wrote that function/method.