Kavacky Posted June 27, 2016 Report Share Posted June 27, 2016 "Saule" poliski tulkojās kā "słońce", tā kā velns viņu zin, kā tas nosaukums radies... Visās indoeiropiešu valodās vārds "Saule" ir diezgan līdzīgs. Quote Link to comment Share on other sites More sharing options...
F3llony Posted June 27, 2016 Report Share Posted June 27, 2016 http://www.paralleluniverse.co Quote Link to comment Share on other sites More sharing options...
jurchiks Posted June 27, 2016 Report Share Posted June 27, 2016 (edited) https://www.sitepoint.com/self-documenting-javascript/Ieteikumi galīgi neattiecas tikai uz JS, tā kā recommended read for everyone. Vienīgais punkts, kuram ne pārāk piekrītu, ir "Avoid boolean flags". Ir lietas, kurām nekas cits neder, turklāt izmantojot IDEs, tas ir moot point - uzhovero uz funkcijas un uzreiz redzi, kas ir tas boolean parametrs (ja vien tur nav 10 boolean pēc kārtas, in which case there's different problem you need to address first). Edited June 27, 2016 by jurchiks Quote Link to comment Share on other sites More sharing options...
briedis Posted June 27, 2016 Author Report Share Posted June 27, 2016 Boolean flagi argumentos sux smagi, pilnīgi nelasāmi. Labāk izveidot vnk atsevišķu funkciju, kas izsauc konkrēto funkciju ar konkrēto boolean flagu, bet funkcijai vismaz ir lasā nosaukums. saveOrder($asDraft = false); saveOrderAsDraft(){ return saveOrder(true); } Internāli klasēs lietot tādas metodes vēl ok, bet uz ārpuse nerullē. Quote Link to comment Share on other sites More sharing options...
jurchiks Posted June 27, 2016 Report Share Posted June 27, 2016 Oi da labi... Un ja ir 2 boolean flagi, tad 4 funkcijas? Quote Link to comment Share on other sites More sharing options...
briedis Posted June 27, 2016 Author Report Share Posted June 27, 2016 Oi da labi... Un ja ir 2 boolean flagi, tad 4 funkcijas? Ja tev ir divi būleani, tad tev ir 4 funkcijas sabāztas vienā funkcijā. Quote Link to comment Share on other sites More sharing options...
jurchiks Posted June 27, 2016 Report Share Posted June 27, 2016 https://github.com/jurchiks/numbers2words/blob/master/src/Speller.php#L120 Tiešām? Quote Link to comment Share on other sites More sharing options...
F3llony Posted June 28, 2016 Report Share Posted June 28, 2016 (edited) Boolean flagi argumentos sux smagi, pilnīgi nelasāmi. Labāk izveidot vnk atsevišķu funkciju, kas izsauc konkrēto funkciju ar konkrēto boolean flagu, bet funkcijai vismaz ir lasā nosaukums. saveOrder($asDraft = false); saveOrderAsDraft(){ return saveOrder(true); } Internāli klasēs lietot tādas metodes vēl ok, bet uz ārpuse nerullē. Arī šis piemērs nav īsti pareizs, jo tas, vai flagi ir slikti vai nē, ir atkarīgs no tā, vai tu modificē behavior vai arī entity. Tādam "saveOrderAsDraft" vispār nevajadzētu eksistēt, jo draft ir Order īpašība, un ar persistance layer šim steitam diez vai būs kāds sakars. Lūk: class Order { private $isDraft = false; public setDraft($draft) { $this->isDraft = $draft; } public isDraft() { return $this->isDraft(); } } // ... $order->setDraft(true); $db->save($order); Taču oriģinālajā rakstā autoram ir pilnīga taisnība - no šādas inline konfigurācijas aļa flagiem vajadzētu izvairīties cik vien iespējams. Ne vienmēr tas ir praktiski un reāli izdarāms, taču, jā, tā tam vajadzētu būt. Ps. Jurčik, tas, ko Tu te proponē saucas parameter hell. Un risinājums tam ir konfigurācijas konstrukti. // WTF? function doStuff($relative, $secondOnly = false, $merge = false, $thing = false, $whatever = null, $oneMore = null, $booHoo = false) { //... } $x = doStuff(true, false, false, null, false, null, false); // WTF? // vai arī... function doStuff(DoStuffOptions $options) { //.. } $options = new DoStuffOptions() ->withRelative(true) ->secondOnly() ->doAMerge() ->addThing($thing) ->withWhatever($whatever) ->addMore($more) ->doABooHoo() ; $x = doStuff($options); Edited June 28, 2016 by F3llony Quote Link to comment Share on other sites More sharing options...
briedis Posted June 28, 2016 Author Report Share Posted June 28, 2016 Ye, struktūras kā argumenti FTW.Man šāda klase padodās metodei, kas salipina kvēriju, lai atlasītu produktus: Quote Link to comment Share on other sites More sharing options...
jurchiks Posted June 28, 2016 Report Share Posted June 28, 2016 (edited) >Ps. Jurčik, tas, ko Tu te proponē saucas parameter hell. Un risinājums tam ir konfigurācijas konstrukti. Tu gribi teikt, ka manā koda piemērā man jātaisa speciāla klase DIVIEM boolean parametriem? Kaut gan jebkurš normāls IDEs un arī dažu advanced text editoru lietotājs var apskatīties, ko tie parametri nozīmē, sekundes laikā? Edited June 28, 2016 by jurchiks Quote Link to comment Share on other sites More sharing options...
codez Posted June 28, 2016 Report Share Posted June 28, 2016 Apskatīties jau var, var arī atvērt dokumentāciju un palasīt un vēl daudz ko. Pats taču sāki runāt par "self documenting" kodu, un f(true,false) nu nekādi tāds nav, jo ir kaut kas kaut kur jāskatās. Quote Link to comment Share on other sites More sharing options...
daGrevis Posted June 28, 2016 Report Share Posted June 28, 2016 Pythonā var darīt šādi: > f(isFoo=1, isBar=0) Quote Link to comment Share on other sites More sharing options...
Kavacky Posted June 28, 2016 Report Share Posted June 28, 2016 Pliks boolean ir tāds pats ļaunums kā random skaitļi parametros vai aprēķinos (piemērs par meaning of life = 42). Ja izsaukums toties izskatās "doShit($with_this_stuff, YES_MORE, NOT_SURE, YES_PLS)", nevis "doStuff($with_this_stuff, true, false, true)", tad viss ir ok. Quote Link to comment Share on other sites More sharing options...
F3llony Posted June 28, 2016 Report Share Posted June 28, 2016 Javā var darīt šādi: public class Foo { public static Baz bar() { // Well, how cool is this, eh? return new Baz() {{ isFoo = true; isBaz = true; method = () -> "Hello World!"; }}; } private static class Baz { boolean isFoo = true; boolean isBaz = true; ReturnValue method; } private interface ReturnValue { String thing(); } } Quote Link to comment Share on other sites More sharing options...
waplet Posted June 28, 2016 Report Share Posted June 28, 2016 Es tādos gadījumos mēdzu uzrakstīt - "doFunc($data, $isDev = true);" pie izsaukuma. Varbūt tā nedrīkst darīt? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.