Tải bản đầy đủ - 0 (trang)
Chapter 6.  Correctness, simplicity, and clarity come first

Chapter 6.  Correctness, simplicity, and clarity come first

Tải bản đầy đủ - 0trang

Summary

KISS(KeepItSimpleSoftware):Correctisbetterthanfast.

Simpleisbetterthancomplex.Clearisbetterthancute.Safeis

betterthaninsecure(seeItems83and99).



Discussion

It'shardtooverstatethevalueofsimpledesignsandclear

code.Yourcode'smaintainerwillthankyouformakingit

understandableandoftenthatwillbeyourfutureself,tryingto

rememberwhatyouwerethinkingsixmonthsago.Hencesuch

classicwisdomas:

Programsmustbewrittenforpeopletoread,andonly

incidentallyformachinestoexecute.

HaroldAbelsonandGeraldJaySussman

Writeprogramsforpeoplefirst,computerssecond.

SteveMcConnell

Thecheapest,fastestandmostreliablecomponentsofa

computersystemarethosethataren'tthere.

GordonBell

Thosemissingcomponentsarealsothemostaccurate

(theynevermakemistakes),themostsecure(theycan't

bebrokeninto),andtheeasiesttodesign,document,test

andmaintain.Theimportanceofasimpledesigncan'tbe

overemphasized.

JonBentley

ManyoftheItemsinthisbooknaturallyleadtodesignsand

codethatareeasytochange,andclarityisthemostdesirable

qualityofeasy-to-maintain,easy-to-refactorprograms.What

youcan'tcomprehend,youcan'tchangewithconfidence.



Probablythemostcommontensioninthisareaisbetweencode

clarityandcodeoptimization(seeItems7,8,and9).Whennot

ifyoufacethetemptationtooptimizeprematurelyfor

performanceandtherebypessimizeclarity,recallItem8's

point:Itisfar,fareasiertomakeacorrectprogramfastthanit

istomakeafastprogramcorrect.

Avoidthelanguage's"dustycorners."Usethesimplest

techniquesthatareeffective.



Examples

Example1:Avoidgratuitous/cleveroperatoroverloading.One

needlesslyweirdGUIlibraryhaduserswritew+c;toadda

childcontrolctoawidgetw.(SeeItem26.)

Example2:Preferusingnamedvariables,nottemporaries,as

constructorparameters.Thisavoidspossibledeclaration

ambiguities.Italsooftenmakesthepurposeofyourcode

clearerandthusiseasiertomaintain.It'salsooftensafer(see

Items13and31).



References

[Abelson96][Bentley00]Đ4[Cargill92]pp.91-93

[Cline99]Đ3.05-06[Constantine95]Đ29[Keffer95]p.17

[Lakos96]Đ9.1,Đ10.2.4[McConnell93][Meyers01]Đ47

[Stroustrup00]Đ1.7,Đ2.1,Đ6.2.3,Đ23.4.2,Đ23.4.3.2

[Sutter00]Đ40-41,Đ46[Sutter04]Đ29



7.Knowwhenandhowtocodefor

scalability

Summary

Discussion

References



Summary

Bewareofexplosivedatagrowth:Withoutoptimizing

prematurely,keepaneyeonasymptoticcomplexity.Algorithms

thatworkonuserdatashouldtakeapredictable,and

preferablynoworsethanlinear,timewiththeamountofdata

processed.Whenoptimizationisprovablynecessaryand

important,andespeciallyifit'sbecausedatavolumesare

growing,focusonimprovingbig-Ohcomplexityratherthanon

micro-optimizationslikesavingthatoneextraaddition.



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 6.  Correctness, simplicity, and clarity come first

Tải bản đầy đủ ngay(0 tr)

×