Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 787163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:09:32+00:00 2026-05-14T21:09:32+00:00

In writing functions my brain always spends a few milliseconds to check which order

  • 0

In writing functions my brain always spends a few milliseconds to check which order of parameters would be best for a given function.

should I write:

    public Comment AddComment(long userID, string title, string text)

Or probably:

    public Comment AddComment(string title, string text, long userID)

Why not:

    public Comment AddComment(string title, long userID, string text)

Do you follow any rules when ordering the parameters for your functions?
Which parameter would you place first and which would follow?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T21:09:32+00:00Added an answer on May 14, 2026 at 9:09 pm

    There are only 3 rules I usually apply:

    • If a language allows passing a hash/map/associative array as a single parameter, try to opt for passing that. This is especially useful for methods with >=3 parameters, ESPECIALLY when those same parameters will be passed to nested function calls.

      This allows for easier maintenance – adding another parameter (especially when that same list of parameters is passed between 10-level-deep nested function calls) involves changing 1 place in the code (the ultimate caller) instead of EVERY single function which takes that list and passes it on elsewhere.

      This has a minor drawback of no type checking in languages like C++ (e.g. your compiler can’t check whether the hash/map contains correct types of values in it for expected types of keys) – if that’s a concern, you can encapsulate that parameter map as a struct/class instead.

    • If a language allows default values for parameters (such as C++, Sybase stored procedures), you obviously leave the optional parameters to be the last, and the less likely the parameter is to be specified with a value, the later in the list it should go.

    • Otherwise, order them in whatever logical grouping is most readable/maintainable.

      This may be a bit subjective – e.g. next/previous weight/height can be ordered next_weight,next_height, prev_weight, prev_height or next_weight, prev_weight, next_height, prev_height equally validly. Again, the 3 main considerations are readability/logicaleness for you, and ease of maintenance.

      As far as readability, you can order them by type, or by meaning.

      As far as “logicalness”, you can order them by meaning (e.g. group all “next” together, or all heights together), OR by some order imposed elsewhere – for example, column order in a corresponding database table, or field order in a GUI (worse, as it’s likely to change).

      As far as maintenance, if no obvious meaningful order crystallizes, alphanumeric order is the best since it allows VERY easy way to find a parameter by scanning and especially to decide where to insert a new parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a few extensions to mimic the map and reduce functions in
I'm writing a C/C++ DLL and want to export certain functions which I've done
I`m writing a chat using WinSock2 and WinAPI functions. And I have a little
I find myself writing delegates occasionally for really simple functions (take no arguments and
I'm writing some JavaScript code to parse user-entered functions (for spreadsheet-like functionality). Having parsed
I'm finding myself writing a bunch of related functions dealing with different nouns (clusters,
Whats this syntax useful for : function(String... args) Is this same as writing function(String[]
I'm writing a function that fishes out the src from the first image tag
I'm writing a function for an installer DLL to verify the Authenticode signature of
Let's say that I'm writing a function to convert between temperature scales. I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.