Referencing official documentation in source-code documentation

What are your preferences for referencing official documentation (like a white paper) for an algorithm from comments in
the code that implements it? I’m trying to decide between two methods, as illustrated by the examples below, but am
open to other suggestions. RFC 1321, for instance, describes the MD5 hash algorithm. If I were implementing MD5
in Python using the paper as a guide, and documented my code as I went, which of the following implementations of an
example function pad_string(str) would you recommend, if not something entirely different?

option 1

def pad_string(str):
    """
    Pads the string to be hashed to an appropriate length. See RFC 1321 3.1.
    """

where the relevant section of the RFC is:

3.1 Step 1. Append Padding Bits

    The message is "padded" (extended) so that its length (in bits) is
    congruent to 448, modulo 512. That is, the message is extended so
    that it is just 64 bits shy of being a multiple of 512 bits long.
    Padding is always performed, even if the length of the message is
    already congruent to 448, modulo 512.

or

option 2

def pad_string(str):
    """
    Pads the argument string such that its length is congruent to 448, modulo 512.
    """

Here, option 1 simply references relevant parts of the “official” MD5 documentation by section number, where
option 2 doesn’t make any mention of the paper and basically reiterates its contents where necessary. The
advantage of the first is that the documentation adheres somewhat to DRY (Don’t Repeat Yourself, in this case with
respect to the RFC), but its disadvantage is that it relies on a third-party resource: if it’s an obscure technical
specification hosted in one place and the link provided inside the code documentation dies, then you’re out of luck.
The advantage of the second approach is that your source is self-contained: you don’t need any other information when
reading through it, and our example MD5 script would become as much a description of the algorithm as its
implementation; this, of course, requires more writing on the code author’s part, can bloat documentation, and, more
importantly, may end up with mis-copied information and other errors. Is there any consensus on which is better?

1

It depends on type of documentation. If it is a publicly facing function you probably should provide all information necessary to use API. For example if I want to use SMTP library to send an email I don’t want to read RFC 5321, RFC 2045, RFC 2046, RFC 2047, RFC 4288, RFC 4289, RFC 2049 and others as most parts are only vaguely relevant to what I want to achieve – in most cases I just want to send a simple message filling the To/From/Subject fileds and message – maybe add attachment if I feel adventurous. However you might want to reference it if RFC is simple and protocol is not well-known to provide additional information (or webpage describing protocol/format if it exists).

For internal documentation the more important is why rather then how (this part is covered by code) or what. Therefore referencing the specification is useful. It will also allow the person modified the code to see what (s)he can change or at least what part of spec (s)he needs to consider.

For example in your example it is probably clear from the code that pad_string pads string so result length is congruent to 448, modulo 512. However the MD5 spec provides reference why it is done.

Other method is to nearly copy and paste the paper/RFC into code if flow is non-trivial and you cannot avoid it by making the code nicer in one way or another. For example lets say the pseudocode is:

Ri <- head from stack
Merge Ri and Rj
if Ri' is not well balanced then
   balance(Ri')
push Ri' on stack

You can do something like:

// Ri <- head from stack
Node *Ri = stack_pop(stack);
// Merge Ri and Rj
Node *Rj = NULL;
while(!empty(Ri) && !empty(Rj)) {
   Node *next;
   if (foo(peek(Ri), peek(Rj))) {
       next = get(Ri);
   } else {
       next = get(Rj);
   }
   add(Rj, next);
}
// if Ri' is not well balanced then
//   balance(Ri')
...

Also, of course, in such case you need to check the copyright law first (this is not a legal advice that it is permitted, especially that copyright law vary from jurisdiction to jurisdiction).

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

Referencing official documentation in source-code documentation

What are your preferences for referencing official documentation (like a white paper) for an algorithm from comments in
the code that implements it? I’m trying to decide between two methods, as illustrated by the examples below, but am
open to other suggestions. RFC 1321, for instance, describes the MD5 hash algorithm. If I were implementing MD5
in Python using the paper as a guide, and documented my code as I went, which of the following implementations of an
example function pad_string(str) would you recommend, if not something entirely different?

option 1

def pad_string(str):
    """
    Pads the string to be hashed to an appropriate length. See RFC 1321 3.1.
    """

where the relevant section of the RFC is:

3.1 Step 1. Append Padding Bits

    The message is "padded" (extended) so that its length (in bits) is
    congruent to 448, modulo 512. That is, the message is extended so
    that it is just 64 bits shy of being a multiple of 512 bits long.
    Padding is always performed, even if the length of the message is
    already congruent to 448, modulo 512.

or

option 2

def pad_string(str):
    """
    Pads the argument string such that its length is congruent to 448, modulo 512.
    """

Here, option 1 simply references relevant parts of the “official” MD5 documentation by section number, where
option 2 doesn’t make any mention of the paper and basically reiterates its contents where necessary. The
advantage of the first is that the documentation adheres somewhat to DRY (Don’t Repeat Yourself, in this case with
respect to the RFC), but its disadvantage is that it relies on a third-party resource: if it’s an obscure technical
specification hosted in one place and the link provided inside the code documentation dies, then you’re out of luck.
The advantage of the second approach is that your source is self-contained: you don’t need any other information when
reading through it, and our example MD5 script would become as much a description of the algorithm as its
implementation; this, of course, requires more writing on the code author’s part, can bloat documentation, and, more
importantly, may end up with mis-copied information and other errors. Is there any consensus on which is better?

1

It depends on type of documentation. If it is a publicly facing function you probably should provide all information necessary to use API. For example if I want to use SMTP library to send an email I don’t want to read RFC 5321, RFC 2045, RFC 2046, RFC 2047, RFC 4288, RFC 4289, RFC 2049 and others as most parts are only vaguely relevant to what I want to achieve – in most cases I just want to send a simple message filling the To/From/Subject fileds and message – maybe add attachment if I feel adventurous. However you might want to reference it if RFC is simple and protocol is not well-known to provide additional information (or webpage describing protocol/format if it exists).

For internal documentation the more important is why rather then how (this part is covered by code) or what. Therefore referencing the specification is useful. It will also allow the person modified the code to see what (s)he can change or at least what part of spec (s)he needs to consider.

For example in your example it is probably clear from the code that pad_string pads string so result length is congruent to 448, modulo 512. However the MD5 spec provides reference why it is done.

Other method is to nearly copy and paste the paper/RFC into code if flow is non-trivial and you cannot avoid it by making the code nicer in one way or another. For example lets say the pseudocode is:

Ri <- head from stack
Merge Ri and Rj
if Ri' is not well balanced then
   balance(Ri')
push Ri' on stack

You can do something like:

// Ri <- head from stack
Node *Ri = stack_pop(stack);
// Merge Ri and Rj
Node *Rj = NULL;
while(!empty(Ri) && !empty(Rj)) {
   Node *next;
   if (foo(peek(Ri), peek(Rj))) {
       next = get(Ri);
   } else {
       next = get(Rj);
   }
   add(Rj, next);
}
// if Ri' is not well balanced then
//   balance(Ri')
...

Also, of course, in such case you need to check the copyright law first (this is not a legal advice that it is permitted, especially that copyright law vary from jurisdiction to jurisdiction).

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

Referencing official documentation in source-code documentation

What are your preferences for referencing official documentation (like a white paper) for an algorithm from comments in
the code that implements it? I’m trying to decide between two methods, as illustrated by the examples below, but am
open to other suggestions. RFC 1321, for instance, describes the MD5 hash algorithm. If I were implementing MD5
in Python using the paper as a guide, and documented my code as I went, which of the following implementations of an
example function pad_string(str) would you recommend, if not something entirely different?

option 1

def pad_string(str):
    """
    Pads the string to be hashed to an appropriate length. See RFC 1321 3.1.
    """

where the relevant section of the RFC is:

3.1 Step 1. Append Padding Bits

    The message is "padded" (extended) so that its length (in bits) is
    congruent to 448, modulo 512. That is, the message is extended so
    that it is just 64 bits shy of being a multiple of 512 bits long.
    Padding is always performed, even if the length of the message is
    already congruent to 448, modulo 512.

or

option 2

def pad_string(str):
    """
    Pads the argument string such that its length is congruent to 448, modulo 512.
    """

Here, option 1 simply references relevant parts of the “official” MD5 documentation by section number, where
option 2 doesn’t make any mention of the paper and basically reiterates its contents where necessary. The
advantage of the first is that the documentation adheres somewhat to DRY (Don’t Repeat Yourself, in this case with
respect to the RFC), but its disadvantage is that it relies on a third-party resource: if it’s an obscure technical
specification hosted in one place and the link provided inside the code documentation dies, then you’re out of luck.
The advantage of the second approach is that your source is self-contained: you don’t need any other information when
reading through it, and our example MD5 script would become as much a description of the algorithm as its
implementation; this, of course, requires more writing on the code author’s part, can bloat documentation, and, more
importantly, may end up with mis-copied information and other errors. Is there any consensus on which is better?

1

It depends on type of documentation. If it is a publicly facing function you probably should provide all information necessary to use API. For example if I want to use SMTP library to send an email I don’t want to read RFC 5321, RFC 2045, RFC 2046, RFC 2047, RFC 4288, RFC 4289, RFC 2049 and others as most parts are only vaguely relevant to what I want to achieve – in most cases I just want to send a simple message filling the To/From/Subject fileds and message – maybe add attachment if I feel adventurous. However you might want to reference it if RFC is simple and protocol is not well-known to provide additional information (or webpage describing protocol/format if it exists).

For internal documentation the more important is why rather then how (this part is covered by code) or what. Therefore referencing the specification is useful. It will also allow the person modified the code to see what (s)he can change or at least what part of spec (s)he needs to consider.

For example in your example it is probably clear from the code that pad_string pads string so result length is congruent to 448, modulo 512. However the MD5 spec provides reference why it is done.

Other method is to nearly copy and paste the paper/RFC into code if flow is non-trivial and you cannot avoid it by making the code nicer in one way or another. For example lets say the pseudocode is:

Ri <- head from stack
Merge Ri and Rj
if Ri' is not well balanced then
   balance(Ri')
push Ri' on stack

You can do something like:

// Ri <- head from stack
Node *Ri = stack_pop(stack);
// Merge Ri and Rj
Node *Rj = NULL;
while(!empty(Ri) && !empty(Rj)) {
   Node *next;
   if (foo(peek(Ri), peek(Rj))) {
       next = get(Ri);
   } else {
       next = get(Rj);
   }
   add(Rj, next);
}
// if Ri' is not well balanced then
//   balance(Ri')
...

Also, of course, in such case you need to check the copyright law first (this is not a legal advice that it is permitted, especially that copyright law vary from jurisdiction to jurisdiction).

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