This is very to you. If you write one function that is not similar to anything else in a containing, say, project, then the required / important parameters go first, and then the optional / unimportant trace. The language you use may influence your choices; Python allows you to supply optional named parameters or keyword arguments, but they must follow positional parameters.
If you write a set of similar functions for the API, then the sequence becomes more important. Using the haystack example, you can have
def insert(haystack, needle) def remove(haystack, needle) def remove_except(haystack, needle, exclude_value) def copy(haystack, haystack2)
where haystack goes first, because it is a key parameter for all the methods listed and
def remove(needle, haystack) def remove_except(haystack, needle, exclude_value)
will look weird (but of course it will work anyway).
If you use an object-oriented language, and you find that you are writing many functions that share a parameter, you will probably think about creating an object and methods of functions that work with this object, but which are likely to go beyond question.
For your chosen language, find a useful code and learn it. If you use Python, check out the standard libraries. For Javascript, jQuery might be good.
Spaceghost
source share