Advanced PHP Programming- P2

Tham khảo tài liệu 'advanced php programming- p2', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 28 Chapter 1 Coding Styles Compare this with the following table tr td Name td td Position td tr php foreach employees as employee tr td echo employee 1 name1 td td echo employee 1 position1 td tr php table The second code fragment is cleaner and does not obfuscate the HTML by unnecessarily using echo. As a note using the syntax which is identical to php echo requires the use of short_tags which there are good reasons to avoid. I print Versus echo print and echo are aliases for each other that is internal to the engine they are indistinguishable. You should pick one and use it consistently to make your code easier to read. Using Parentheses Judiciously You should use parentheses to add clarity to can write this if month february if year 4 0 year 100 year 400 0 days_in_month 29 else days_in_month 28 However this forces the reader to remember the order of operator precedence in order to follow how the expression is computed. In the following example parentheses are used to visually reinforce operator precedence so that the logic is easy to follow if month february if year 4 0 year 100 year 400 0 days_in_month 29 else days_in_month 28 You should not go overboard with parentheses however. Consider this example if month february if year 4 0 year 100 0 year 400 0 days_in_month 29 Documentation 29 else days_in_month 28 This expression is overburdened with parentheses and it is just as difficult to decipher the intention of the code as is the example that relies on operator precedence alone. Documentation Documentation is inherently important in writing quality code. Although well-written code is largely self-documenting a programmer must still read the code in order to understand its function. In my company code produced for clients is not considered complete until its entire external application programming interface API and any internal idiosyncrasies are fully documented. Documentation can be broken down into two major categories Inline comments that explain .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.