Are there defined standards for argument sequence? [closed]

Say I have a function taking three arguments:

a symbol (an alias for a class, method or function name)
a mirror/reflection of a specific object
a mirror/reflection of a class in general

is there a how-to (e.g. for certain languages or libraries) to sort things in function calls to keep an API consistent?

3

That pretty much depends on your API / environment.

A few rules and guidelines that I know of:

  • In general: POLA – Principle of Least Astonishment (first brought to Computer Science by Mike Colishaw in his book the Rexx Programming Language), also known as Rule of Least Surprise – try to think from an API user’s perspective, how is it easy to remember? How is it natural to read? Avoid astonishment / surprise.
  • Place cohesive arguments together. Example: In arraycopy(src, srcOffset, dst, dstOffest, length), src and srcOffset are very cohesive, so they stay together. length is also cohesive to src, but it is equally cohesive to dst, which makes the cohesion less specific, therefore it comes last.
  • Place the primary object first, i.e. the object that would be a this reference in an OO language. In other words: Place the object “to which the operation is told” first.
  • Place the destination before the source (C and similar languages).
  • Place the source / input before the destination / output (Java and similar languages).
  • Place those arguments that are more likely to vary between similar function calls more to the right, those arguments that are more likely to stay the same more to the left.
  • Place the parameters with more generic meaning more to the left, the ones with more specific meaning more to the right. For example: (directory, file) is usually more logical than (file, directory) – unless directory is a destination. Or class, object usually is more logical than object, class – unless object is of this nature.
  • Try to make the calls read (almost) like well-written prose.

And a few hints:

  • Be consistent within your API.
  • Make it easy for users which already know similar APIs, i.e. look around. If you develop a Qt extension, look how the Qt API itself feels. If you develop a Java API, look how the SUN / Oracle Java API looks and feels.

A few more examples:

  • If a function takes an array, an offset into that array, and a length, the sequence should be (array, offset, length) because that’s how you think: First what, then the details, and the details in the sequence in which they matter. The contract is probably about iteration which we expect to start at offset and run until length is reached.

In your case it depends on the nature of the symbol, the object and the class. If I assume that object is a member of class, and symbol is a member of object, I would probably expect the sequence to be (class, object, symbol).

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật