First time posting.

I know this is a very generalized question, sorry for that, I don't know how to more appropriately word this.

I've noticed a tread, a pattern in methods, it seems in almost all methods, for example, in Java (haven't programmed much in other languages although I would imagine it's the same) the method seems to share a general pattern in their creations.

It's something on the order of: - Create local variables to store/copy things from instance variables - Create a loop to iterate through things - Create a series of if statements/conditions, possibly accessing premade methods - Check for any sort of possible exceptions/problems along the way - Return the desired output of the operations from the above

And all the other aspects such as polymorphism, recursion, interfaces, inheritance seem to be conceptual features/additions to the codes performance and functionality

Is this true? I know that each method is unique and a special combination of the above is probably require. Generally speaking do most methods follow a pattern? Is there a better way of writing out the above list, in a more formal way?

Thank you, I appreciate you taking the time to read this post.


1 Answer 1


A method is just a precise sequence of instructions (in the ordinary English-language sense of the word) of how to perform some specific task. It's certainly true that many tasks – and I mean this in a completely general sense, not just computer programs but things like recipes, travelling to work, repairing a bicycle, building a house – follow a general pattern of "get things ready, do the main part of the work, then tidy up." However, there's no reason that all tasks must follow this pattern, and certainly not at the level you suggest of looping, then doing conditionals, then returning something. In general, methods do whatever it is that they need to do to accomplish the specific task at hand: ultimately, everything really is its own unique snowflake.

Having said that, we should note that we could, in principle, force everything to have a particular pattern. The CPU itself is essentially a loop of "read the next instruction, obey that instruction" where a particular effect of obeying an instruction might be to change what the "next instruction" will be – that would be a jump or goto. So, in principle, we could write every program in this style. However, people find this kind of program extremely difficult to write, understand and debug so, in practice, we use higher-level languages, and use compilers and/or interpreters to translate them into terms that the CPU understands.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.