Reference For detailson iteration, see Section34.8, “Iterate, Repeated dịch - Reference For detailson iteration, see Section34.8, “Iterate, Repeated Việt làm thế nào để nói

Reference For detailson iteration,

Reference For details
on iteration, see Section
34.8, “Iterate, Repeatedly,
Again and Again,” later in
this chapter.
Low-level processes matter, too. If you follow the process of writing pseudocode and
then filling in the code around the pseudocode, you reap the benefits of designing
from the top down. You’re also guaranteed to have comments in the code without having
to put them in later.
Observing large processes and small processes means pausing to pay attention to how
you create software. It’s time well spent. Saying that “code is what matters; you have to
focus on how good the code is, not some abstract process” is shortsighted and ignores
mountains of experimental and practical evidence to the contrary. Software development
is a creative exercise. If you don’t understand the creative process, you’re not getting the
most out of the primary tool you use to create software—your brain. A bad process wastes
your brain cycles. A good process leverages them to maximum advantage.
34.3 Write Programs for People First, Computers Second
your program n. A maze of non sequiturs littered with clever-clever tricks and
irrelevant comments. Compare MY PROGRAM.
my program n. A gem of algoristic precision, offering the most sublime balance
between compact, efficient coding on the one hand and fully commented legibility
for posterity on the other. Compare YOUR PROGRAM.
—Stan Kelly-Bootle
Another theme that runs throughout this book is an emphasis on code readability.
Communication with other people is the motivation behind the quest for the Holy
Grail of self-documenting code.
The computer doesn’t care whether your code is readable. It’s better at reading binary
machine instructions than it is at reading high-level-language statements. You write
readable code because it helps other people to read your code. Readability has a positive
effect on all these aspects of a program:
■ Comprehensibility
■ Reviewability
■ Error rate
■ Debugging
■ Modifiability
■ Development time—a consequence of all of the above
■ External quality—a consequence of all of the above
842 Chapter 34: Themes in Software Craftsmanship
In the early years of programming,
a program was
regarded as the private
property of the programmer.
One would no more think of
reading a colleague’s program
unbidden than of picking
up a love letter and
reading it. This is essentially
what a program was, a love
letter from the programmer
to the hardware, full of the
intimate details known only
to partners in an affair. Consequently,
programs became
larded with the pet names
and verbal shorthand so
popular with lovers who live
in the blissful abstraction
that assumes that theirs is
the only existence in the universe.
Such programs are
unintelligible to those outside
the partnership.
—Michael Marcotty
Readable code doesn’t take any longer to write than confusing code does, at least not in
the long run. It’s easier to be sure your code works if you can easily read what you wrote.
That should be a sufficient reason to write readable code. But code is also read during
reviews. It’s read when you or someone else fixes an error. It’s read when the code is
modified. It’s read when someone tries to use part of your code in a similar program.
Making code readable is not an optional part of the development process, and favoring
write-time convenience over read-time convenience is a false economy. You should
go to the effort of writing good code, which you can do once, rather than the effort of
reading bad code, which you’d have to do again and again.
“What if I’m just writing code for myself? Why should I make it readable?” Because a
week or two from now you’re going to be working on another program and think,
“Hey! I already wrote this class last week. I’ll just drop in my old tested, debugged
code and save some time.” If the code isn’t readable, good luck!
The idea of writing unreadable code because you’re the only person working on a
project sets a dangerous precedent. Your mother used to say, “What if your face froze
in that expression?” And your dad used to say, “You play how you practice.” Habits
affect all your work; you can’t turn them on and off at will, so be sure that what you’re
doing is something you want to become a habit. A professional programmer writes
readable code, period.
It’s also good to recognize that whether a piece of code ever belongs exclusively to you
is debatable. Douglas Comer came up with a useful distinction between private and
public programs (Comer 1981): “Private programs” are programs for a programmer’s
own use. They aren’t used by others. They aren’t modified by others. Others don’t even
know the programs exist. They are usually trivial, and they are the rare exception. “Public
programs” are programs used or modified by someone other than the author.
Standards for public and for private programs can be different. Private programs can
be sloppily written and full of limitations without affecting anyone but the author.
Public programs must be written more carefully: their limitations should be documented,
they should be reliable, and they should be modifiable. Beware of a private
program’s becoming public, as private programs often do. You need to convert the
program to a public program before it goes into general circulation. Part of making a
private program public is making it readable.
Even if you think you’re the only one who will read your code, in the real world
chances are good that someone else will need to modify your code. One study found
that 10 generations of maintenance programmers work on an average program before
it gets rewritten (Thomas 1984). Maintenance programmers spend 50 to 60 percent
of their time trying to understand the code they have to maintain, and they appreciate
the time you put into documenting it (Parikh and Zvegintzov 1983).
1
2
3
HARD DATA
34.4 Program into Your Language, Not in It 843
Earlier chapters in this book examined the techniques that help you achieve readability:
good class, routine, and variable names, careful formatting, small routines, hiding
complex boolean tests in boolean functions, assigning intermediate results to variables
for clarity in complicated calculations, and so on. No individual application of a
technique can make the difference between a readable program and an illegible one,
but the accumulation of many small readability improvements will be significant.
If you think you don’t need to make your code readable because no one else ever
looks at it, make sure you’re not confusing cause and effect.
34.4 Program into Your Language, Not in It
Don’t limit your programming thinking only to the concepts that are supported automatically
by your language. The best programmers think of what they want to do, and
then they assess how to accomplish their objectives with the programming tools at
their disposal.
Should you use a class member routine that’s inconsistent with the class’s abstraction
just because it’s more convenient than using one that provides more consistency? You
should write code in a way that preserves the abstraction represented by the class’s
interface as much as possible. You don’t need to use global data or gotos just because
your language supports them. You can choose not to use those hazardous programming
capabilities and instead use programming conventions to make up for weaknesses
of the language. Programming using the most obvious path amounts to
programming in a language rather than programming into a language; it’s the programmer’s
equivalent of “If Freddie jumped off a bridge, would you jump off a bridge,
too?” Think about your technical goals, and then decide how best to accomplish those
goals by programming into your language.
Your language doesn’t support assertions? Write your own assert() routine. It might
not function exactly the same as a built-in assert(), but you can still realize most of
assert()’s benefits by writing your own routine. Your language doesn’t support enumerated
types or named constants? That’s fine; you can define your own enumerations
and named constants with a disciplined use of global variables supported by
clear naming conventions.
In extreme cases, especially in new-technology environments, your tools might be so
primitive that you’re forced to change your desired programming approach significantly.
In such cases, you might have to balance your desire to program into the language
with the accidental difficulties that are created when the language makes your
desired approach too cumbersome. But in such cases, you’ll benefit even more from
programming conventions that help you steer clear of those environments’ most hazardous
features. In more typical cases, the gap between what you want to do and what
your tools will readily support will require you to make only relatively minor concessions
to your environment.
844 Chapter 34: Themes in Software Craftsmanship
34.5 Focus Your Attention with the Help of Conventions
Cross-Reference For an
analysis of the value of conventions
as they apply to
program layout, see “How
Much Is Good Layout
Worth?” and “Objectives of
Good Layout” in Section
31.1.
A set of conventions is one of the intellectual tools used to manage complexity. Earlier
chapters talk about specific conventions. This section lays out the benefits of conventions
with many examples.
Many of the details of programming are somewhat arbitrary. How many spaces do
you indent a loop? How do you format a comment? How should you order class routines?
Most of the questions like these have several correct answers. The specific way
in which such a question is answered is less important than that it be answered consistently
each time. Conventions save programmers the trouble of answering the same
questions—making the same arbitrary decisions—again and again. On projects with
many programmers, using conventions prevents the confusion that results when different
programmers ma
0/5000
Từ: -
Sang: -
Kết quả (Việt) 1: [Sao chép]
Sao chép!
Reference For detailson iteration, see Section34.8, “Iterate, Repeatedly,Again and Again,” later inthis chapter.Low-level processes matter, too. If you follow the process of writing pseudocode andthen filling in the code around the pseudocode, you reap the benefits of designingfrom the top down. You’re also guaranteed to have comments in the code without havingto put them in later.Observing large processes and small processes means pausing to pay attention to howyou create software. It’s time well spent. Saying that “code is what matters; you have tofocus on how good the code is, not some abstract process” is shortsighted and ignoresmountains of experimental and practical evidence to the contrary. Software developmentis a creative exercise. If you don’t understand the creative process, you’re not getting themost out of the primary tool you use to create software—your brain. A bad process wastesyour brain cycles. A good process leverages them to maximum advantage.34.3 Write Programs for People First, Computers Secondyour program n. A maze of non sequiturs littered with clever-clever tricks andirrelevant comments. Compare MY PROGRAM.my program n. A gem of algoristic precision, offering the most sublime balancebetween compact, efficient coding on the one hand and fully commented legibilityfor posterity on the other. Compare YOUR PROGRAM.—Stan Kelly-BootleAnother theme that runs throughout this book is an emphasis on code readability.Communication with other people is the motivation behind the quest for the HolyGrail of self-documenting code.The computer doesn’t care whether your code is readable. It’s better at reading binarymachine instructions than it is at reading high-level-language statements. You writereadable code because it helps other people to read your code. Readability has a positiveeffect on all these aspects of a program:■ Comprehensibility■ Reviewability■ Error rate■ Debugging■ Modifiability■ Development time—a consequence of all of the above■ External quality—a consequence of all of the above842 Chapter 34: Themes in Software CraftsmanshipIn the early years of programming,a program wasregarded as the privateproperty of the programmer.One would no more think ofreading a colleague’s programunbidden than of pickingup a love letter andreading it. This is essentiallywhat a program was, a loveletter from the programmerto the hardware, full of theintimate details known onlyto partners in an affair. Consequently,programs becamelarded with the pet namesand verbal shorthand sopopular with lovers who livein the blissful abstractionthat assumes that theirs isthe only existence in the universe.Such programs areunintelligible to those outsidethe partnership.—Michael MarcottyReadable code doesn’t take any longer to write than confusing code does, at least not inthe long run. It’s easier to be sure your code works if you can easily read what you wrote.That should be a sufficient reason to write readable code. But code is also read duringreviews. It’s read when you or someone else fixes an error. It’s read when the code ismodified. It’s read when someone tries to use part of your code in a similar program.Making code readable is not an optional part of the development process, and favoringwrite-time convenience over read-time convenience is a false economy. You shouldgo to the effort of writing good code, which you can do once, rather than the effort ofreading bad code, which you’d have to do again and again.“What if I’m just writing code for myself? Why should I make it readable?” Because aweek or two from now you’re going to be working on another program and think,“Hey! I already wrote this class last week. I’ll just drop in my old tested, debuggedcode and save some time.” If the code isn’t readable, good luck!The idea of writing unreadable code because you’re the only person working on aproject sets a dangerous precedent. Your mother used to say, “What if your face frozein that expression?” And your dad used to say, “You play how you practice.” Habitsaffect all your work; you can’t turn them on and off at will, so be sure that what you’redoing is something you want to become a habit. A professional programmer writesreadable code, period.It’s also good to recognize that whether a piece of code ever belongs exclusively to youis debatable. Douglas Comer came up with a useful distinction between private andpublic programs (Comer 1981): “Private programs” are programs for a programmer’sown use. They aren’t used by others. They aren’t modified by others. Others don’t evenknow the programs exist. They are usually trivial, and they are the rare exception. “Publicprograms” are programs used or modified by someone other than the author.Standards for public and for private programs can be different. Private programs canbe sloppily written and full of limitations without affecting anyone but the author.Public programs must be written more carefully: their limitations should be documented,they should be reliable, and they should be modifiable. Beware of a privateprogram’s becoming public, as private programs often do. You need to convert theprogram to a public program before it goes into general circulation. Part of making aprivate program public is making it readable.Even if you think you’re the only one who will read your code, in the real worldchances are good that someone else will need to modify your code. One study foundthat 10 generations of maintenance programmers work on an average program beforeit gets rewritten (Thomas 1984). Maintenance programmers spend 50 to 60 percentof their time trying to understand the code they have to maintain, and they appreciatethe time you put into documenting it (Parikh and Zvegintzov 1983).123HARD DATA34.4 Program into Your Language, Not in It 843Earlier chapters in this book examined the techniques that help you achieve readability:good class, routine, and variable names, careful formatting, small routines, hidingcomplex boolean tests in boolean functions, assigning intermediate results to variablesfor clarity in complicated calculations, and so on. No individual application of atechnique can make the difference between a readable program and an illegible one,but the accumulation of many small readability improvements will be significant.If you think you don’t need to make your code readable because no one else everlooks at it, make sure you’re not confusing cause and effect.34.4 Program into Your Language, Not in ItDon’t limit your programming thinking only to the concepts that are supported automaticallyby your language. The best programmers think of what they want to do, andthen they assess how to accomplish their objectives with the programming tools attheir disposal.Should you use a class member routine that’s inconsistent with the class’s abstractionjust because it’s more convenient than using one that provides more consistency? Youshould write code in a way that preserves the abstraction represented by the class’sinterface as much as possible. You don’t need to use global data or gotos just becauseyour language supports them. You can choose not to use those hazardous programmingcapabilities and instead use programming conventions to make up for weaknesses
of the language. Programming using the most obvious path amounts to
programming in a language rather than programming into a language; it’s the programmer’s
equivalent of “If Freddie jumped off a bridge, would you jump off a bridge,
too?” Think about your technical goals, and then decide how best to accomplish those
goals by programming into your language.
Your language doesn’t support assertions? Write your own assert() routine. It might
not function exactly the same as a built-in assert(), but you can still realize most of
assert()’s benefits by writing your own routine. Your language doesn’t support enumerated
types or named constants? That’s fine; you can define your own enumerations
and named constants with a disciplined use of global variables supported by
clear naming conventions.
In extreme cases, especially in new-technology environments, your tools might be so
primitive that you’re forced to change your desired programming approach significantly.
In such cases, you might have to balance your desire to program into the language
with the accidental difficulties that are created when the language makes your
desired approach too cumbersome. But in such cases, you’ll benefit even more from
programming conventions that help you steer clear of those environments’ most hazardous
features. In more typical cases, the gap between what you want to do and what
your tools will readily support will require you to make only relatively minor concessions
to your environment.
844 Chapter 34: Themes in Software Craftsmanship
34.5 Focus Your Attention with the Help of Conventions
Cross-Reference For an
analysis of the value of conventions
as they apply to
program layout, see “How
Much Is Good Layout
Worth?” and “Objectives of
Good Layout” in Section
31.1.
A set of conventions is one of the intellectual tools used to manage complexity. Earlier
chapters talk about specific conventions. This section lays out the benefits of conventions
with many examples.
Many of the details of programming are somewhat arbitrary. How many spaces do
you indent a loop? How do you format a comment? How should you order class routines?
Most of the questions like these have several correct answers. The specific way
in which such a question is answered is less important than that it be answered consistently
each time. Conventions save programmers the trouble of answering the same
questions—making the same arbitrary decisions—again and again. On projects with
many programmers, using conventions prevents the confusion that results when different
programmers ma
đang được dịch, vui lòng đợi..
Kết quả (Việt) 2:[Sao chép]
Sao chép!
Tham khảo Để biết chi tiết
về sự lặp lại, xem Phần
34.8, "lặp, Liên tiếp,
lần nữa và lần nữa, "sau này trong
chương này.
Low cấp xử lý vấn đề, ​​quá. Nếu bạn làm theo các quá trình viết mã giả và
sau đó điền vào các mã trên mã giả, bạn gặt hái những lợi ích của thiết kế
từ trên xuống. Bạn cũng sẽ được bảo đảm để có ý kiến trong các mã mà không cần phải
để đặt chúng vào sau đó.
Quan sát quá trình lớn và quy trình nhỏ có nghĩa là ngừng lại để chú ý đến cách
bạn tạo ra phần mềm. Đó là thời gian cũng chi tiêu. Nói rằng "mã là những gì quan trọng; bạn phải
tập trung vào cách tốt mã là, không phải một số quá trình trừu tượng "là thiển cận và bỏ qua
núi bằng chứng thực nghiệm và thực tế ngược lại. Phát triển phần mềm
là một bài tập sáng tạo. Nếu bạn không hiểu được quá trình sáng tạo, bạn sẽ không nhận được
nhiều nhất của các công cụ chính mà bạn sử dụng để tạo ra các phần mềm của bạn não. Một quá trình xấu lãng phí
chu kỳ não của bạn. Một quy trình tốt thúc đẩy họ để tận dụng tối đa.
34,3 Viết chương trình cho dân đầu tiên, máy tính thứ hai
chương trình n của bạn. Một mê cung của các phi khập khiễng rải rác với các thủ đoạn thông minh-minh và
luận không thích hợp. So sánh CHƯƠNG TRÌNH CỦA TÔI.
chương trình n của tôi. Một đá quý có độ chính xác algoristic, cung cấp sự cân bằng tuyệt vời nhất
giữa compact, mã hóa hiệu quả trên một mặt và mức độ dễ đọc nhận xét ​​đầy đủ
cho hậu thế về việc khác. So sánh CHƯƠNG TRÌNH CỦA BẠN.
-Stan Kelly-Bootle
Một chủ đề mà chạy suốt cuốn sách này là một sự nhấn mạnh vào các mã dễ đọc.
Giao tiếp với người khác là động lực đằng sau sự tìm kiếm Thánh
Chén mã tự tài liệu.
Các máy tính không quan tâm code của bạn có thể đọc được. Nó là tốt hơn lúc đọc nhị phân
hướng dẫn của máy hơn là lúc đọc báo cáo cấp ngôn ngữ cao. Bạn viết
code dễ đọc vì nó giúp người khác để đọc code của bạn. Dễ đọc có một tích cực
hiệu quả trên tất cả các khía cạnh của một chương trình:
■ comprehensibility
■ Reviewability
tỷ lệ lỗi ■
■ Debugging
■ Modifiability
■ Phát triển thời gian là một hệ quả của tất cả các bên trên
■ ngoài chất lượng-một hậu quả của tất cả các bên trên
842 Chương 34: Chủ đề trong phần mềm Craftsmanship
Trong những năm đầu của chương trình,
một chương trình được
coi là tin
tài sản của các lập trình viên.
Một không sẽ nghĩ về
chương trình đọc của một đồng nghiệp
tự ý hơn khi chọn
lên một bức thư tình và
đọc nó. Đây thực chất là
những gì một chương trình đã được, một tình yêu
thư từ lập trình
cho phần cứng, đầy đủ các
chi tiết thân mật chỉ được biết đến
với các đối tác trong một mối tình. Do đó,
chương trình đã trở thành
larded với tên con vật cưng
và viết tắt bằng lời nói rất
phổ biến với những người yêu thích những người sống
trong hạnh phúc trừu tượng
mà giả định rằng họ là
sự tồn tại duy nhất trong vũ trụ.
Các chương trình này là
khó hiểu cho người bên ngoài
công ty.
-Michael Marcotty
mã Readable doesn 't có bất kỳ thời gian để viết hơn khó hiểu mã nào, ít nhất là trong
thời gian dài. Nó dễ dàng hơn để đảm bảo mã của bạn hoạt động nếu bạn có thể dễ dàng đọc những gì bạn viết.
Đó phải là lý do đủ để viết code có thể đọc được. Nhưng mã này cũng được đọc trong
các ý kiến. Nó đọc khi bạn hoặc người khác sửa chữa lỗi. Nó đọc khi đang
sửa đổi. Nó đọc khi ai đó cố gắng sử dụng một phần của mã của bạn trong một chương trình tương tự.
Làm cho mã dễ đọc không phải là một phần bắt buộc trong quá trình phát triển, và thiên vị
ghi thời gian thuận tiện hơn đọc thời gian thuận tiện là một nền kinh tế giả. Bạn nên
đi đến các nỗ lực trong việc viết mã tốt, mà bạn có thể làm một lần, thay vì nỗ lực của
đọc mã xấu, mà bạn phải làm lại lần nữa và một lần nữa.
"Nếu tôi chỉ cần viết mã cho bản thân mình? Tại sao tôi nên làm cho nó có thể đọc được? "Bởi vì một
hoặc hai tuần kể từ bây giờ bạn sẽ được làm việc trên một chương trình khác và nghĩ rằng,
"Hey! Tôi đã viết lớp này tuần trước. Tôi sẽ chỉ cần thả trong kiểm tra, sửa lỗi cũ của tôi
mã và tiết kiệm thời gian. "Nếu mã là không thể đọc được, may mắn!
Ý tưởng của việc viết mã không đọc được bởi vì bạn là người duy nhất làm việc trên một
dự án đặt ra một tiền lệ nguy hiểm . Mẹ em thường nói, "Điều gì nếu khuôn mặt của bạn bị đóng băng
trong biểu thức đó? "Và cha của bạn được sử dụng để nói, Thói quen" Bạn chơi như thế nào bạn thực hành. "
ảnh hưởng đến tất cả các công việc của bạn; bạn không có thể bật và tắt theo ý muốn, vì vậy hãy chắc chắn rằng những gì bạn đang
làm là một cái gì đó bạn muốn trở thành một thói quen. Một lập trình viên chuyên nghiệp viết
dễ đọc code, thời gian.
Nó cũng tốt để nhận ra rằng cho dù một đoạn mã bao giờ thuộc về độc quyền cho bạn
là gây tranh cãi. Douglas Comer đã đưa ra một sự phân biệt hữu ích giữa các cá nhân và
các chương trình công cộng (Comer 1981): "Các chương trình tư nhân" là chương trình cho một lập trình viên
sử dụng riêng. Họ không được sử dụng bởi những người khác. Họ không được sửa đổi bởi người khác. Những người khác thậm chí không
biết những chương trình tồn tại. Họ thường là tầm thường, và họ là những ngoại lệ hiếm hoi. "Công
chương trình "là chương trình sử dụng hoặc sửa đổi bởi người khác hơn so với tác giả.
Tiêu chuẩn cho công chúng và cho các chương trình tư nhân có thể khác nhau. Các chương trình tư nhân có thể
được viết cẩu thả và đầy đủ các hạn chế mà không ảnh hưởng đến bất cứ ai nhưng tác giả.
chương trình công cộng phải được viết cẩn thận hơn: hạn chế của họ nên được ghi chép,
họ nên đáng tin cậy, và họ cần được sửa đổi. Hãy cẩn thận của một tư nhân
trở thành công của chương trình, như các chương trình tư nhân thường làm. Bạn cần phải chuyển đổi các
chương trình cho một chương trình nào trước khi nó đi vào lưu thông chung. Phần thực hiện một
công trình tư nhân là làm cho nó có thể đọc được.
Ngay cả khi bạn nghĩ rằng bạn là người duy nhất sẽ đọc code của bạn, trong thế giới thực
rất có thể người khác sẽ cần phải sửa đổi mã của bạn. Một nghiên cứu cho thấy
rằng 10 thế hệ của các lập trình viên bảo trì làm việc trên một chương trình trung bình trước khi
nó được viết lại (Thomas, 1984). Lập trình bảo dưỡng dành 50 đến 60 phần trăm
thời gian của họ cố gắng để hiểu các mã họ phải duy trì, và họ đánh giá cao
thời gian bạn đưa vào tài liệu đó (Parikh và Zvegintzov 1983).
1
2
3
HARD DỮ LIỆU
Chương trình 34.4 vào ngôn ngữ của bạn, Không phải trong Nó 843
chương Trước đó trong cuốn sách này đã kiểm tra kỹ thuật giúp bạn đạt được khả năng đọc:
lớp học tốt, thói quen, và các tên biến, định dạng cẩn thận, thói quen nhỏ, ẩn
các xét nghiệm phức tạp trong các chức năng boolean boolean, gán kết quả trung gian để biến
cho rõ ràng trong các phép tính phức tạp, và như vậy. Không có ứng dụng riêng lẻ của một
kỹ thuật có thể làm cho sự khác biệt giữa một chương trình có thể đọc được và là một không đọc được,
nhưng sự tích tụ của nhiều cải tiến khả năng đọc nhỏ sẽ là đáng kể.
Nếu bạn nghĩ rằng bạn không cần phải làm cho mã của bạn có thể đọc được bởi vì không ai có
vẻ ở đó, chắc chắn rằng bạn không khó hiểu nguyên nhân và hậu quả.
34.4 Chương trình thành ngôn ngữ của bạn, Không có trong đó
không hạn chế bất lập trình của bạn chỉ nghĩ đến những khái niệm được hỗ trợ tự động
bằng ngôn ngữ của bạn. Các lập trình viên tốt nhất nghĩ về những gì họ muốn làm, và
sau đó họ đánh giá như thế nào để đạt được mục tiêu của họ với các công cụ lập trình tại
xử lý của họ.
Nếu bạn sử dụng một thói quen thành viên lớp học đó là không phù hợp với các khái niệm trừu tượng của lớp
chỉ vì nó thuận tiện hơn nhiều so với sử dụng một trong những cung cấp nhất quán hơn? Bạn
nên viết mã theo một cách giữ gìn trừu tượng đại diện bởi các lớp của
giao diện càng nhiều càng tốt. Bạn không cần phải sử dụng dữ liệu toàn cầu hoặc gotos chỉ vì
ngôn ngữ của bạn hỗ trợ họ. Bạn có thể chọn không sử dụng những chương trình độc hại
và khả năng thay vì sử dụng quy ước lập trình để tạo nên những điểm yếu
của ngôn ngữ. Lập trình bằng cách sử dụng con đường rõ ràng nhất số tiền để
lập trình trong một ngôn ngữ hơn là lập trình sang ngôn ngữ; đó là lập trình viên
tương đương với "Nếu Freddie nhảy ra khỏi một cây cầu, bạn sẽ nhảy ra khỏi một cây cầu,
quá? "Hãy suy nghĩ về các mục tiêu kỹ thuật của bạn, và sau đó quyết định cách tốt nhất để thực hiện những
mục tiêu của chương trình sang ngôn ngữ của bạn.
Ngôn ngữ của bạn không có hỗ trợ khẳng định? Viết assert () thói quen của riêng bạn. Nó có thể
không hoạt động chính xác giống như một khẳng định được xây dựng trong (), nhưng bạn vẫn có thể nhận ra nhất của
assert () 's lợi ích bằng cách viết trình riêng của mình. Ngôn ngữ của bạn không hỗ trợ liệt kê
các loại hoặc các hằng số được đặt tên? Đó là tiền phạt; bạn có thể xác định kiểu liệt kê của riêng bạn
và hằng số có tên với một sử dụng xử lý kỷ luật của các biến toàn cầu được hỗ trợ bởi
các công ước đặt tên rõ ràng.
Trong trường hợp cực đoan, đặc biệt là trong môi trường công nghệ mới, các công cụ của bạn có thể được như vậy
nguyên thủy mà bạn buộc phải thay đổi cách tiếp cận lập trình mong muốn đáng kể.
Trong trường hợp như vậy, bạn có thể phải cân bằng giữa mong muốn của bạn để chương trình sang ngôn ngữ
với những khó khăn vô tình được tạo ra khi các ngôn ngữ làm cho bạn
tiếp cận mong muốn quá rườm rà. Nhưng trong trường hợp như vậy, bạn sẽ được hưởng lợi nhiều hơn từ
các công ước lập trình giúp bạn tránh xa nguy hiểm nhất những môi trường '
tính năng. Trong trường hợp điển hình hơn, khoảng cách giữa những gì bạn muốn làm và những gì
các công cụ của bạn sẽ sẵn sàng hỗ trợ sẽ yêu cầu bạn phải có những nhượng bộ chỉ tương đối nhỏ
đối với môi trường của bạn.
844 Chương 34: Chủ đề trong phần mềm Craftsmanship
34,5 Tập trung sự chú ý của bạn với sự trợ giúp của các Công ước
Cross-Reference Đối với một
phân tích giá trị của các công ước
như họ áp dụng cho
chương trình bố trí, xem "Làm thế nào
nhiêu là tốt Layout
Worth? "và" Mục tiêu của
Layout Good "tại mục
31.1.
Một tập hợp các ước là một trong những công cụ được sử dụng trí tuệ để quản lý phức tạp. Trước đó
chương nói về ước cụ thể. Phần này đưa ra những lợi ích của công ước
với nhiều ví dụ.
Nhiều người trong số các chi tiết của chương trình là một việc khó. Làm thế nào nhiều không gian làm
bạn canh lề một vòng lặp? Làm thế nào để định dạng một comment? Làm thế nào bạn nên đặt thói quen lớp?
Hầu hết các câu hỏi như thế này có một số câu trả lời đúng. Cách cụ thể
, trong đó một câu hỏi như vậy được trả lời là ít quan trọng hơn là nó được trả lời một cách nhất quán
mỗi lần. Ước cứu lập trình những rắc rối của việc trả lời cùng một
câu hỏi làm việc tùy tiện cùng một quyết định, một lần nữa và một lần nữa. Về dự án với
nhiều người lập trình, sử dụng các công ước ngăn ngừa sự nhầm lẫn có kết quả khác nhau khi
lập trình ma
đang được dịch, vui lòng đợi..
 
Các ngôn ngữ khác
Hỗ trợ công cụ dịch thuật: Albania, Amharic, Anh, Armenia, Azerbaijan, Ba Lan, Ba Tư, Bantu, Basque, Belarus, Bengal, Bosnia, Bulgaria, Bồ Đào Nha, Catalan, Cebuano, Chichewa, Corsi, Creole (Haiti), Croatia, Do Thái, Estonia, Filipino, Frisia, Gael Scotland, Galicia, George, Gujarat, Hausa, Hawaii, Hindi, Hmong, Hungary, Hy Lạp, Hà Lan, Hà Lan (Nam Phi), Hàn, Iceland, Igbo, Ireland, Java, Kannada, Kazakh, Khmer, Kinyarwanda, Klingon, Kurd, Kyrgyz, Latinh, Latvia, Litva, Luxembourg, Lào, Macedonia, Malagasy, Malayalam, Malta, Maori, Marathi, Myanmar, Mã Lai, Mông Cổ, Na Uy, Nepal, Nga, Nhật, Odia (Oriya), Pashto, Pháp, Phát hiện ngôn ngữ, Phần Lan, Punjab, Quốc tế ngữ, Rumani, Samoa, Serbia, Sesotho, Shona, Sindhi, Sinhala, Slovak, Slovenia, Somali, Sunda, Swahili, Séc, Tajik, Tamil, Tatar, Telugu, Thái, Thổ Nhĩ Kỳ, Thụy Điển, Tiếng Indonesia, Tiếng Ý, Trung, Trung (Phồn thể), Turkmen, Tây Ban Nha, Ukraina, Urdu, Uyghur, Uzbek, Việt, Xứ Wales, Yiddish, Yoruba, Zulu, Đan Mạch, Đức, Ả Rập, dịch ngôn ngữ.

Copyright ©2025 I Love Translation. All reserved.

E-mail: