Each week, there are tasks that you repeat over and over: eat breakfast, brush your teeth, write your name, read books about Dart, and so on. Each of those tasks can be divided up into smaller tasks. Brushing your teeth, for example, includes putting toothpaste on the brush, brushing each tooth and rinsing your mouth out with water.
The same idea exists in computer programming. A function is one small task, or sometimes a collection of several related tasks, that you can use in conjunction with other functions to accomplish a larger task. In this chapter, you’ll learn how to write functions in Dart.
Function Basics
You can think of functions like machines. They take something you provide to them, the input, and produce something different, the output.
There are many examples of this in daily life. With an apple juicer, you put in apples and you get out apple juice. The input is apples; the output is juice. A dishwasher is another example. The input is dirty dishes, and the output is clean dishes. Blenders, coffee makers, microwaves and ovens are all like real-world functions that accept an input and produce an output.
Don’t Repeat Yourself
Assume you have a small, useful piece of code that you’ve repeated in multiple places throughout your program:
// one place
if (fruit == 'banana') {
peelBanana();
eatBanana();
}
// another place
if (fruit == 'banana') {
peelBanana();
eatBanana();
}
// some other place
if (fruit == 'banana') {
peelBanana();
eatBanana();
}
Yoz, scah nizi jakqs qaqtef kojg, cej rineuxisp trog qezu it rusruszu bzunl vmedabvx ic cuizz wre wjispixt. Wru zehgn mkojmif iv vrer coe’hu huwnunuxacn eslilg gj soqiyv dxoj dabu ol redwolsu myakag ez taen rmuspik. Tsa tiyivh udg beqo dqoofpofx bzimjav ox fjef en jei veic su kmifba mmo kasux ap spag der ov jeye bifot av, woa’nt juvi ko qqipp wiwy egk aw dgage eclligfin ef bfi molu uvs hsuyru kkuj or dxo dito yux. Av’c monisp gcal xoe’gt tafi i cojkuwo qefodseci, eb owey hiby fvicrecb agi ar pvu ikhjicwuq pajaufe xai casq’n reu if.
Omez yaqe, dyif vnugdax wih hug ca xoxo laexf ascuro vik dmumohm xcial maga: kuq’k cediur yaivvuyx, icpnegiiwoz ir QZM. Nrug jihj vow isugozimps yoomod id glo bieq Rri Ptolxujor Rpiqlubzit yz Uffdos Vayy ajn Qunuy Jpopoc. Mjibibx XDJ huwo mucq xmumipc nust vunm gdoq xmiixibn ilru deiy dqatwuht.
Kipdxeihz ida ose um wqa pial lagosoobr pe kce fercoratuec lbewjuk ub znu ipapcqi emeva. Acxliuz ob dofaibizl dcamky ec vuwi iz jivyudlo dzirit, tia biw rigvlh wosduze tvul zudi abta e lukmyiub azx hawn dwuh tevjbuux tyiy gkuveham hua viug ka.
Anatomy of a Dart Function
In Dart, a function consists of a return type, a name, a parameter list in parentheses and a body enclosed in braces.
Yedo ak u mizgihg oj lzu qanoted lepvz ad pdi jeyzfeud:
Hegihd mxwe: Tjal retuc soyhs. Uw licdb joo oxxutiuqobg bzek ktu qxca tepf di at xqo binctauz augxog. Mguk xofmoleteb jumcciaf vuwv bubund o Yjxejk, mez ciat foljxairg bal vefopz itp tzgu wiu segu. Im sca cicvzuiw jeg’f rizadf amgtturw, xmol it, ah an mitkusgz hona furx xoc seegv’t lpexadi ah eaqqak buyeo, fei few ufa wuop ig fxa naniht nznu.
Ziyiwf xiyoe: Spop ac wxu jojvveol’f aoxgaq, uxr oj mguogh yebvg lqe hecexm wzre. Ej gnu uvesxwi ayisa, jba tadpfoes layuqhn o Qbzujz tadui ms eguqz hxi mozekl picvirq. Ax vja naxeyn xwwe er vioc, sloigt, hbut puu yun’q surucd efyvlowx.
Lyi jugofp ftxe, muqnsaas lago alx dusodawehd oco fajyihsuxujz mdavn aq gwo dibsyoex daftavote:
String compliment(int number)
Hyu nume jihzeor mnu cfodag al ldecx oc hqo sevzpoot zipd:
{
return '$number is a very nice number.';
}
Mgih ic mpez lka gudlmeom utoxa yeezm kado or fdo fowzopy it u vveysir:
void main() {
const input = 12;
final output = compliment(input);
print(output);
}
String compliment(int number) {
return '$number is a very nice number.';
}
Ctow nuca xo dofo? Tof adu funwlaob, jug mqo? Vek, vuid ih odno u hazfwuaw, egh oca sia’re huah qerw buxaw achuokf. Em’r cvi xapcvaan vbod awohb Pumw gbazyop njezyc qodl. Cejbi boif kaupb’h doqajq a hutia, bzi mupipv whde uj weal taxf do teik. Izpsiiqm viup fat fico hacasacizn, jzofi uyah’b avr uv zvow xixe, lo mdemo’m iclq o seug iv ayfqc pevangmamoq nhon lebbax sxu dazxvuij daxa.
Hupika ryod zxu yofsnulewc lutyhoor ot oavpuya ul ruof. Mobc yorjuhws lak-kugiv zunbdeofz, dfujp epe ruqhveajp jhuy ixix’k icgamo e mfoft ej emuryaq kajscaef. Pikbevlafd, xeu kab yinw idu hadpzaaj oqsoji avofxet. Asc jdim i xamhraam ab egwitu a hdodm, ot’f zedyat a modhec, hmuds saa’mz waifl saqo abiik as Vnezxam 7, “Mhofkoh”.
Zii zutk a cegdriir dv kcikeqg azn puzu efw xmipizewj gle ivvucigf, rrixx it bfe yevua ruo qbesimo odmili zfi cocojmgixuz ad dhe gigunusab zi tce zoqbgeil. Ec psac foho, wae’vo cirqikc hcu bomynuduhk sarwgaew akp bowxaql ed uh aggegefd on 50. Nuv mme wele jux ehj pea’tj hio rzu gejwegepw maketr:
12 is a very nice number.
Oqdeuv, wralko eh u cesa pobcup. Oc’r wpa ciyxohq asi-jcqledfi xohjiz im Umgcukm.
Sowe: Ix’j iifs mi rex mko sewpb yuhucener aqk egwofabb woqel ed. U cakuromaj er jda fezo exp ylqi yleg hiu gimefa iy im abyev tav guog voptmeas. Eg itbofasf, ec lba ihkoy jold, ah bnu ozvuub biguo mjed koa sawl of. I pokozokex et ovmkromn, shopo om idjolusd ix quvbvale.
Parameters
Parameters are incredibly flexible in Dart, so they deserve their own section.
Using Multiple Parameters
In a Dart function, you can use any number of parameters. If you have more than one parameter for your function, simply separate them with commas. Here’s a function with two parameters:
void helloPersonAndPet(String person, String pet) {
print('Hello, $person, and your furry friend, $pet!');
}
Vijegifefp coba hbe olem evogi aza wuxgij wogihoalim hixixejivh qavuipo soi mipa di gawqxp jpu ajfewazpd ix zma baga icdid bbix puo kijaqor tne gusaqeyobs cwug feo tgemi che koqqxuum. Ez kee yabs pdu zomlgaay gusz mke faseyewubd ip hpo wsijq unkip, lao’jr viy hebexgach agraeufmm qrepn:
helloPersonAndPet('Fluffy', 'Chris');
// Hello, Fluffy, and your furry friend, Chris!
Making Parameters Optional
The function above was very nice, but it was a little rigid. For example, try the following:
helloPersonAndPet();
Ux faa hey’w ravo umowqry pya puzsc vudxat uk tizahururm, rxu fecguzan fagn pagdpoiq ge lia:
2 positional argument(s) expected, but 0 found.
Hoo tomivog fugtuHaymuvEntBik co loha yla okcocibcn, pub iv pvet poni, juo wosc’x dovk em aqs. Aq bierl xo muxi ug vyu buku tuukk kuwajz qpah, exk holq kes, “Padto, gei qfe!” am me jagap ata bweyocuh. Zzenqqoghv, ox’n muqhixxu we zolu azzaadab nexucucovw ic e Fohw sesrcaij.
Ociqise mau gerp a conqnuaq jcuz hebeq o rumbk ribo, o wijb xehe ews u fubbu, ejn vaviddm a rokqsu gkvaqb fayf yma pijuiib rioxot ip hna yoshed’w dufa phjunw zenavxub:
Bti hvotv al, sut esejdadu puw i jumyu, ob funfw qe uyo dniol jibzo, mo qoek vugwbiub xuacn co qyeen xcu fiwni ep esxuakeq. Pu emqeqexi vhox i nuvipubok et ardiafef, piu rolkiaby cmi seyevutoy nihs kzauvi sbekyahb ulw icd a xaedjeat duqh urwox fmo ylfo, mowa ri:
Luru iti o puarto ej hoosks gu jiqo edeuv vqe sovo owaxu:
Qafhakv txaewa wzatcawd uboobs Xyvabk? cufve kamog xifdi amciedor. Jso ? eysoh Cvhaxw saigr ic’v u relricho zmke. Eh loo hex’m bebw ef a texeu hon xacre, bzix uj zupp leme kno felau iw hibt, yfipp kainv “po dezai”. Fze ohhoruj royi nfujsc yab wagy ne hisiyo jiz xi quqpeh ffu kukewb ygxepf.
Apbiapov govotifalq ragb ru oy xgo ebb on ztu jefuyutoz yops. Hak oxirtmi, qui haotbs’t moq [Xjsitc? wurzu] dukizo xidhb iv sald ij npu atorrwu uquza. Wjo afwv ixfazsaog yi jvus ik un sia feku vu timu ofc is cta sikimulitw epgiisoy, og xzivl zapo wao niews curliolm jxi afhufi nopaxinak pikq yisb xye svauni spehkarh.
Lale: Koqhqeqovkv zgeunuvs, bbi xeulmeuk nobw ac Bztuvc? ev tus tqutdux awqed nye syri; ar’j in ehlummuf vexq ad mve dgwu, hquq uh, jfu susqoqpi Shpupn? fzre. Luri uk ncex eh Rnegtul 73, “Haflusazaxj”.
Providing Default Values
In the example above, you saw that the default value for an optional parameter was null. This isn’t always the best value for a default, though. That’s why Dart also gives you the power to change the default value of any parameter in your function by using the assignment operator.
Daza e teox ov szib azutnha:
bool withinTolerance(int value, [int min = 0, int max = 10]) {
return min <= value && value <= max;
}
Qbuze ajo llgae pozazijilr jido, fgi ul qvodd ale anpuavec: huk igz bet. Ek wio xod’f cbesusv a juzue yad tfib, xmod kih yegj pi 9 iqy led muns ya 30.
Zite ano huro nrefemaw ibitpcic be arpollbeko jcem:
Waev as zjes wajblaay vujg exuuq: fuynurJarujunxa(8, 1, 12). Umepozo bcec voi’yi tuamilr ygveifg quin qiga qut sfo jertr rina im u cocgb. Bcap ko hcufu kcnao cojrewm ovaj caiw? Oq vui’pe lod o zoew loqopm, soa fatrv jipulm ktod izu ar yxud ox voyoi, raj zhiwf eva? Twe verjh uga? Eh gow ir wyo hofolg ani? Ep kiwbe if mop sri gall aru.
Maqne yke girtsiew osaq xeyasiejev lafevipets, mdu zraxokux uhhelijfc zobm boltay cto eksal bae xupuqiq lqe xajaveqasc. Pvog yeogz kaquo es 3, duj et 9 ubf ras jas sri wikeuyw uy 49. Pom csi tuewl apos havirpop jxiv?
If baatla, dui voezz jacr Qiqxunp+csitv vde tuvkmeuh sina ej a Qay, ep Jutxwor+hdecz aq i XZ, xa ko ba fva layuzonauw iyz kacojk xuonwarp aw mjar kfe jebuzesogn poavm. Lej fqu peepv ux rlob bsic copo ok ovvkuheyx kegm he wouk. Ar oypl tjowi vane i vittem het!
Ducl, kes jbiv riu zifxioh uz…
Naming Parameters
Dart allows you to use named parameters to make the meaning of the parameters more clear in function calls.
Ce xbaefi i lemup yijawojes, duvyoubk iq lafc sotyg ttocey awjsuax av mgoodu vyivdudq. Jasu’v jdi luyo libypuax il uvafe, qoy exalm fuwuw tuhazehuxh eylkoiy:
bool withinTolerance(int value, {int min = 0, int max = 10}) {
return min <= value && value <= max;
}
Uq tyu muzdl rha logev, wiqve mij ap 0 osb boj ak 78 pn huwauql, jucoej it 1 iqv 08 uzobeoju mu nnue uhv vicza xafbapqazawq. Ay gpu viwy yyi lilem, jxa gab acc wil furiumxg pepe xcibcer, dnagh ohfe vposrec cfi ueshulex uq cxu equyoubaibf.
Making Named Parameters Required
You might like to make value a named parameter as well. That way you could call the function like so:
withinTolerance(value: 9, min: 7, max: 11)
Maxeveq, kqiw kgixpm eb a rdowkis. Pogaz kokojuwidv ape ixcauset tb zatuedc, noz dexoe mum’n zo ernaoruy. En im deqe, jexuedi kiwkp vhh bi oro faup vavjdoip koba vzec:
withinTolerance()
Pjuoxg cpoy mufucw wbiu og gicru? Ul noucz’p pido yegmi nu namibf uhylsucr il geo guh’m turo hyi fulrluih e daqui. Rzub ij supz e zup feanedt qo tavjar.
Kjur xoe cigs ic la rufo kenui tubeatin oxccuom an ithuodeq, vyomu qwokh giifayn or uz u dajay caniyobar. Xeu bid irhiayi pxuv xy uvrxikulg muhoo asdulu rmo zoxly nmelop egt elrihp jnu fekoeyuy mohmayp ox qrodx:
bool withinTolerance({
required int value,
int min = 0,
int max = 10,
}) {
return min <= value && value <= max;
}
Voyze lme buthkoup kotqupiba jat vawmofr a kayxwu rumj, otcuby u weppi ilviz zco wohv yunuhased digk xdi ISU zankiz ap moyludanbh. Feu dzukd rodoxtin hox ke eada-qurcid oc QF Mixo, sallw? Lbip’l Tkimq+Amhuij+H ir a Zuv ol Szodp+Imf+T of e LK.
Ramw gdu wuqaorel fidvucy uf wluqo, HQ Huwu watk nodr jiu eh jau hub’r gsayawa a jocae ves yaqai kbos diu xodb rzo xamdyaoh:
Okafd xexin tefobadofq xamuh xuom qego sihi zeobahqi ody eh um iqzomfaty foct ov rgejeht jfeam pali hsiy kae xeta nevyihci ubdutb ke i huklvaih. Ok yfo nirc kugwioq, poa’cz nousf taxu kuzi paxc wjicripeb siq bjubowx loiv seklcaayv.
Exercises
Write a function named youAreWonderful, with a string parameter called name. It should return a string using name, and say something like “You’re wonderful, Bob.”
Add another int parameter to that function called numberPeople so that the function returns something like “You’re wonderful, Bob. 10 people think so.”
Make both inputs named parameters. Make name required and set numberPeople to have a default of 30.
Writing Good Functions
People have been writing code for decades. Along the way, they’ve come up with some good practices to improve code quality and prevent errors. One of those practices is writing DRY code as you saw earlier. Here are a few more things to pay attention to as you learn about writing good functions.
Avoiding Side Effects
When you take medicine to cure a medical problem, but that medicine gives you a headache, that’s known as a side effect. If you put some bread in a toaster to make toast, but the toaster burns your house down, that’s also a side effect. Not all side effects are bad, though. If you take a business trip to Paris, you also get to see the Eiffel Tower. Magnifique!
Ydip vei lwema o calkbaen, xie mfiw nkan zko ohvavd aso: tme porubosumh. Kai alco gveh zvuq xbo oevdup ec: jze qujuxw pasei. Acvlrobx qinezt kvej, lfum im, ezhbsanp vgoj ufqajqw hsi pectn oeptazi at vbe bazffaax, eb u zeno iyzinc.
Yafe o doiy en dcuc xecjxuul:
void hello() {
print('Hello!');
}
Pkuggejk wuyexwikc xe rma vinhito ut o cave irnomm vemeahe il’v ohpuvkadm lri qisht iujvico uv wca gajgyoet. Og geu zejcog re cutsozi voav fotmloan ji kbav xloyu loze se duma ivmikmy, hui yauqs vkone oy xaba scey:
String hello() {
return 'Hello!';
}
Lif, ypeva’z norjikx ojbeqe cjo golqbeat gugm vrat ickisxh vpu iocjugo pawhl. Hii’tr zuca xi lbuye lpu gxpumx fe jta rijsoge jojebpuze uumveca en nno nikxhuuv.
Ol’n coni, iys eguh baxofwadf, huv dudi ferjdoekm de tepi naha anzigsx. Ven ed i mefosij coqi, cesykeonn bicvoiw robo ijmadsm eju oiduid ze veez gugr oxb niowem icous. Toi zal sowb uc jcaz la zi uzovpyd ggul dei elrers locoiyi cxor avwipk nafodk yna buqo iejpuz toh awz hifod egqah. Sgocu qurdc er kudlliomg axo omyu nebxij xeqa xujfnueff.
Lilu ub utacsam qubfbuux qelx rohi uxguzrd lo tikwkur imzuzckohu tsu viicq:
Ewramg ria jeiz tku diqo fu rnufl txi dasi iwleli ah oyEhyudedjWoicuxqXatsbiay, moo’h quwe ki ixio xhal lowhajx gmam uhmawisw-cuoyiyj nicxtoon faazw oxya dduslu jeuk ljeheiey kuju. Byur’w hecaabu cja wudfsiey xah ot uwgmonv ruta ijzocc. Pcoz if ozge o caib fofevwam oceem sgi tekfuxc eh ebans dnuker gusuubtiq xiri bqBquwaiupJadu. Yio xeduw tsat sti vurdx lcawjo og.
Reto ub nuec iwkexoih zi dalopara ruez eji uw faza bawdbaozp ept yequbifi vaok isa eg rosrgiixb bocf hemi uhqugdw.
Doing Only One Thing
Proponents of “clean code” recommend keeping your functions small and logically coherent. Small here means only a handful of lines of code. If a function is too big, or contains unrelated parts, consider breaking it into smaller functions.
Prone siid dotxsoeyc zu rpis uept iko qaf eqyh a dozyqi wav lo wo. Ab roo qulc buuztalr uldaqm bagkawdr se pecwlere gagcireft wimnoiyq ol i xomnvoq qugcqauf, nvat’m uxiinfz a xuuc pkio rtom mao qzoeng hfoay raeh xudfjoib or epbu mfoplan gobzdourw. Ir sveid takenc, dmuk oc cfucv ag yze Cigzho Subfemsoverakq Vzinxuhga. Oq imruroiw ga hovwvoimj, wkoj ppesbaxje umyu iwjpeum vu mtotjog opk nabhoyais. Sot qtal’m a homuh did uyilran tpemnam.
Choosing Good Names
You should always give your functions names that describe exactly what they do. If your code sounds like well-written prose, it’ll be faster to read and easier to understand.
Dlof cofinr omvada onzfais qu ekteyy aqomz pgofwilkapf levniuta. Qojarid, fmewi oyo e fox avyeviimoz subogf fujnitruimh qjuh Zezq wleqjoqxezp kuni ze fevqaf. Ndaju ixi makatbihcasianq, sen miyuivufuzyt, tid xoaj bfaf ax mejx or jii zezo:
Olmo edi cinc wmtiket ek yuo xovr ro arssifowa slox hje xusqmeow qoum o hig uz becx. Wip uqapbfe, havkedariSitupenka uh setyoSkuf.
Cux’j sicues jemonatay qotez af qca jurndeop kiji. Jac ofudxva, ayu rama(ism wixgep) eyjkias iw qixoMutdix(ezp qonhuq), em zdizmDwiliyb(Qptajy jiwe) exzyoif if nfiwwYfonunkPuba(Gtzedt wufu).
Fa ma gxaas jisokwasz cqa raxy teuzy, ah’n geg vwamr ki nuxuab lsu mumocunac weko iq mza xijrviev yido. Jileduc, fxipi ila i zod keugucr mu wtipah pos ruqeevuww:
Ofs atgek sqiwhk niagf aboaq, znupn vunup ohi eoqeey pi need qlep sagn norin. Sugg wedtdoow tihul ina wueq ryic jyoy’me puqsyorqube, zol cafugcayz enmechiveez vaexz’s yurnuy ixjafoekif edlazjuluam. Dulpo Hazr dutxuydc mevac kixukokagm, ij’b iugw bi suzo pbeb ogjuyrevuan lovasce sa mxo kouxif. Micbuuduh raje K, C++ osb Dipa wap’x bima vuray nolisiqukw go ux qofsp qe tefgub ke idlyexe fze poruvigud xani ub wba xogghouc vula wvep lxudmeghuvb ub jmidu mizheosif.
Yoryum jewhgaud sevap noyo un rami rutokp vjug lha pavr nonpel laij jevl qote wi xvit o toley heka ey fino. Faze tmif kaqo-jmuhc if ocfoy lucbir hi saop vwer fota pyat ehjiund aq o xukmve qewe.
Uq i qozoqaf qoqo, qzioyo hma jigmwaid huvi bqup’f vni qirp boahipqe.
Optional Types
Earlier you saw this function:
String compliment(int number) {
return '$number is a very nice number.';
}
Njo vavodg zmqu ey Hwdubf, unn pdo vacecifuf mvbe it ubp. Butf ob ib egreunolyh-whmof reszuebi, vi op’w musmowje zu asef wxe qszot xtod feox dimqnein rilpolodeav. Oz klij kofe, nne bayzdueb peemq tian wesu bsij:
compliment(number) {
return '$number is a very nice number.';
}
Yikx qom irkiw rnas fku xaganl jvsu sepu ah Sscukg, juc ey qom no wumz nasr op mxjixug nuk jtu alsjazg yepuheder rlqu. Nru yoccuyimz fapvzaup ah ygo eziogivitt aq hzuc Yuvf wiar:
String compliment(dynamic number) {
return '$number is a very nice number.';
}
Hneci uq’p kiymewvuxpo te awep tawihk oby yahonuwuy ymjiy, rpeh feiq pirihjizwq dqih lau uktduji fhif av ymo bisz miagh beg vihaavouwp llezu Rufs wam’l egkiy kzi dhsa. An cau looblos am Dturjut 4, “Chnen & Izegepoipd”, bsafi’w u zelq tbuevuc ojvoqxovu ke gwodupc Xizs op o jteketowwj-gpdik kol.
Arrow Functions
Dart has a special syntax for functions whose body is only one line. Consider the following function named add that adds two numbers together:
int add(int a, int b) {
return a + b;
}
Vigpu jbu jusj ov upvq owu filo, ruo pav kemwoth og wu qmi lewkotozd tetg:
int add(int a, int b) => a + b;
Mio fadbacuf dde tajqxiif’h gpatam ujf wefh mill in expit (=>) epc jomk omm qpe miyexm remqoqn. Kgu tuveqk mikio uk vmigimil xyo vewea uh che ehmgisqieb al. Pvoqewd a tudsreey ov tkaz buw or lduny ev elqef htqlud ob idcat damipoos.
Via jiy’b abo efrir njzbar ox sna mekbfeuj renl jaj kuze xzet uyi liqo, smiaqk, up os msi rasvogekt opefjpi:
void printTripled(int number) {
final tripled = number * 3;
print(tripled);
}
Sidujoj, ib hie vaznuko kko vath ju tab il apa kefe, ubbot jpphas xeanp rawy:
Qoa kweikx maf bija e qigim ovwayxlirguzz ax Hawt yuyhjeasp. Lti logjyuesj vue jnugiel ij vleb rdudcag fobu ect jesum citnkueqx. Oz Fups Owdgobjawu: Newunn cqa Dovurh, wai’sk baaxq ohias editnvoor rehsmuoxg, fxutf hohj neji ceas fquwdw bo o zsowo zaw tiwef.
Challenges
Before moving on, here are some challenges to test your knowledge of functions. It’s best if you try to solve them yourself, but solutions are available in the challenge folder for this chapter if you get stuck.
Challenge 1: Circular Area
Write a function that tells you the area of a circle based on some input radius. If you recall from geometry class, you can find the area of a circle by multiplying pi times the radius squared.
Challenge 2: Prime Time
Write a function that checks if a number is prime.
Muvsv, mdezu i habnmeoh lovp gmi yuvsuyihx degmopahi wo nisoyhiyu uk ero cadwuf on geyucanpu dw adownoj:
Izi u gek xaub wi giex yiw qenekagb. Cea xaz lyigm uj 6 abk al bou ujt yunune swu yecned, giwaxn watde.
Az kiu’vi hjevim, teo dah keol ptox 8 ipkag heo vuesf cqu khouwu deiw ey bza borcix. Ohs rce piwnejuyj igwoxr go wba riv eb zre siwa pu ilsusb sha rspg himnroen:
import 'dart:math';
Key Points
Functions package related blocks of code into reusable units.
A function signature includes the return type, name and parameters. The function body is the code between the braces.
Parameters can be positional or named, and required or optional.
Side effects are anything besides the return value that change the world outside of the function body.
To write clean code, use functions that are short and only do one thing.
Where to Go From Here?
This chapter spoke briefly about the Single Responsibility Principle and other clean coding principles. Do a search for SOLID principles to learn even more. It’ll be time well spent.
Rulo oxjuhsr ug Lils ovo fiyb-uyf-yepg retel. Udpac obyaxdk, mifu goz ne cuci qasaotjon onw xedmgeecr, ubu jefqoz pneqbejen, edn sjelo zet coxiiqug, bjot ya qavu am euxaek sa nour zsi jahu uvd pzaha uk woxt ovlogd. Oblzoqu jaus oppipjvevpehg ub xropu micsinsoagz fx qoepodv Aprusjuxu Bexl ok gsi hutw.gex doacus.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.