Python Programming for Biology: Bioinformatics and Beyond



Download 7,75 Mb.
Pdf ko'rish
bet126/514
Sana30.12.2021
Hajmi7,75 Mb.
#91066
1   ...   122   123   124   125   126   127   128   129   ...   514
Bog'liq
[Tim J. Stevens, Wayne Boucher] Python Programming

10

Coding tips

Contents

Improving Python code

Code clarity

Improving speed

A compendium of tips

Simple operations

Strings

Collections

Loops

Functions



Comparisons

Miscellaneous



Improving Python code

This chapter is concerned with improving Python code and we will illustrate, using short

code  snippets,  various  tips  that  help  with  speed,  memory  use  and  coding  clarity.  There

may  be  several  aspects  of  a  program  that  we  seek  to  improve,  but  we  can’t  necessarily

expect to improve all of them all of the time. Often optimisation of a Python program is

about  compromise;  you  may  make  a  program  run  faster  at  the  expense  of  using  more

memory. Clarity is an especially important aspect that we will be mindful of when making

suggestions, and in general we recommend making code more easily understood over mild

improvements in performance. Finding and correcting errors in code can take a long time,

sometimes  longer  than  the  program  took  to  write  in  the  first  place,  so  keeping  the  code

easy to understand is especially important.

A basic programming approach that the authors often follow, and which may be helpful

for others, is a three-point plan:

1.  Firstly, make the code work: an inelegant program is better than one that doesn’t

work.

2.  Next  do  it  properly:  with  a  working  reference,  you  can  take  a  step  back  and



criticise your approach.

3.  Then  make  it  better:  only  once  your  program  is  working,  and  the  general

approach won’t change, is it worth optimising.



During  this  chapter  we  will  assume  that  the  first  point  is  covered  and  think  about  the

last two. However, it is worth noting upfront that time spent on optimising (point 3) has

the tendency for ever diminishing returns, so we will try not to be too obsessive.


Download 7,75 Mb.

Do'stlaringiz bilan baham:
1   ...   122   123   124   125   126   127   128   129   ...   514




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish