Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Elements of Style in Programming (HWSW Mobile! 2016)

The Elements of Style in Programming (HWSW Mobile! 2016)

Slide deck from my presentation at HWSW Mobile! 2016 in Budapest.

Bozhidar Batsov

November 23, 2016
Tweet

More Decks by Bozhidar Batsov

Other Decks in Programming

Transcript

  1. size=2 start=0 c=['Н', 'Н' ,'Н' ,'Н' ,'Н','Н','Н','Н','Н','Н','Н','Н','Н','Н'] code_dictionary=Array.new() begin_size_code_dictionary=Array.new() end_string=String.new()

    code_dictionary=c.uniq.to_a decode_dictionary=c.uniq.to_a for i in 0...code_dictionary.size begin_size_code_dictionary[i]=i end c.size.times{ if !code_dictionary.include?(c[start,size].to_s)#Comparation code_dictionary.push(c[start,size].to_s.chomp) start=start+(code_dictionary.last.size)/2-1 size=2 else size+=1; end } end_code=Array.new(code_dictionary.size) for i in begin_size_code_dictionary.size...code_dictionary.size end_code[i]=code_dictionary.index(code_dictionary[i].chop.chop)+1 end_string+=code_dictionary[i].chop.chop end govnokod. ru
  2. A style guide • a curated set of (supposedly) good

    practices • spares you the process of making trivial decisions • allows you to focus on the actual problems • simple and concise
  3. Programs must be written for people to read, and only

    incidentally for machines to execute. — Hal Abelson
  4. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do

    eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Chapter I
  5. LOREM IPSUM DOLOR SIT AMET, CONSECTETUR ADIPISCING ELIT, SED DO

    EIUSMOD TEMPOR INCIDIDUNT UT LABORE ET DOLORE MAGNA ALIQUA. UT ENIM AD MINIM VENIAM, QUIS NOSTRUD EXERCITATION ULLAMCO LABORIS NISI UT ALIQUIP EX EA COMMODO CONSEQUAT. DUIS AUTE IRURE DOLOR IN REPREHENDERIT IN VOLUPTATE VELIT ESSE CILLUM DOLORE EU FUGIAT NULLA PARIATUR. EXCEPTEUR SINT OCCAECAT CUPIDATAT NON PROIDENT, SUNT IN CULPA QUI OFFICIA DESERUNT MOLLIT ANIM ID EST LABORUM. LOREM IPSUM DOLOR SIT AMET, CONSECTETUR ADIPISCING ELIT, SED DO EIUSMOD TEMPOR INCIDIDUNT UT LABORE ET DOLORE MAGNA ALIQUA. UT ENIM AD MINIM VENIAM, QUIS NOSTRUD EXERCITATION ULLAMCO LABORIS NISI UT ALIQUIP EX EA COMMODO CONSEQUAT. DUIS AUTE IRURE DOLOR IN REPREHENDERIT IN VOLUPTATE VELIT ESSE CILLUM DOLORE EU FUGIAT NULLA PARIATUR. EXCEPTEUR SINT OCCAECAT CUPIDATAT NON PROIDENT, SUNT IN CULPA QUI OFFICIA DESERUNT MOLLIT ANIM ID EST LABORUM. chapter i
  6. A Fideszt démonizálók közül meglepően sokan képzelik úgy, hogy a

    kor mánypár t valami nindzsahadsereghez hasonló, tökéletesen kiképzett, arctalan, fegyelmezett katonákból álló sereg, egyfajta f é l e l m e t e s e n h a t é k o n y p o l i t i k a i - é s propagandagépezet. Ugyanezt képzeli ráadásul, nem kis büszkeséggel, egy rakás Fidesz-rajongó is. Egy jó propagandaminiszter viszont tudja, hogy ez az imidzs egy határig kedvező ugyan a pártnak, de ha túlzottan kizárólagossá válik, a választók már nem tudnak azonosulni vele és a túlhajtott profizásnak meg klónhadseregezésnek elhidegülés lesz a vége. Fejezet 1
  7. A FIDESZT DéMONIZáLóK KöZüL MEGLEPőEN SOKAN KéPZELIK úGY, HOGY A

    KORMáNYPáRT VALAMI NINDZSAHADSEREGHEZ HASONLó, T ö K é L E T E S E N K I K é P Z E T T, A R C TA L A N , FEGYELMEZETT KATONáKBóL áLLó SEREG, EGYFAJTA FéLELMETESEN HATéKONY POLITIKAI- éS PROPAGANDAGéPEZET. FeJeZet 1 U G YA N E Z T K é P Z E L I R á A D á S U L , N E M K I S BüSZKESéGGEL, EGY RAKáS FIDESZ-RAJONGó IS. EGY Jó PROPAGANDAMINISZTER VISZONT TUDJA, HOGY EZ AZ IMIDZS EGY HATáRIG KEDVEZő UGYAN A PáRTNAK, DE HA TúLZOTTAN KIZáRóLAGOSSá VáLIK, A VáLASZTóK MáR NEM TUDNAK AZONOSULNI VELE éS A T ú L H A J T O T T P R O F I Z á S N A K M E G KLóNHADSEREGEZéSNEK ELHIDEGüLéS LESZ A VéGE.
  8. sum = 1 + 2 a, b = 1, 2

    [1, 2, 3].each { |e| puts e } class FooError < StandardError; end
  9. BKV

  10. $:

  11. $;

  12. $*

  13. i = 1 res = 0 while i <= 10

    res += i i += 1 end
  14. •Make it right before you make it faster. •Make it

    fail-safe before you make it faster. •Make it clear before you make it faster.
  15. # This method does bla bla bla. # It returns

    an array of results. def bla_bla_bla res = Set.new # ... res end
  16. // // Dear maintainer: // // Once you are done

    trying to 'optimize' this routine, // and have realized what a terrible mistake that was, // please increment the following counter as a warning // to the next guy: // // total_hours_wasted_here = 42 //
  17. Go

  18. PHP