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

ソフトウェア工学11 コードフォーマット

ソフトウェア工学11 コードフォーマット

コードフォーマット

コード規約,PEP8,チェッカー,フォーマッタ,難読化

99b434b001cd93fe73322f764d73372c?s=128

Toru Tamaki

August 05, 2021
Tweet

Transcript

  1. ιϑτ΢ΣΞ޻ֶ nίʔυϑΥʔϚοτ • ίʔυن໿ɼPEP8ɼνΣοΧʔɼϑΥʔϚολɼ೉ಡԽ ۄ໦పʢ໊޻େʣ

  2. ίʔυن໿

  3. ίʔσΟϯάن໿ nίʔυελΠϧΛ౷Ұ͢Δ • ίʔυͷॻ͖ํΛ౷Ұ͠ՄಡੑΛߴΊΔ͜ͱ͕໨త • ༷ʑͳྲྀ೿͕͋Δ • ௨ৗ͸ϓϩδΣΫτຖʹࢦఆ͞ΕΔ • ݴޠຖʹඪ४͕͋Δ৔߹΋͋Δ

    nՄಡੑ͕ॏཁͳཧ༝ • ʮίʔυ͸ॻ͘ΑΓ΋ಡ·ΕΔ͜ͱͷํ͕ଟ͍ʯ PEP8υΩϡϝϯτ https://pep8-ja.readthedocs.io/ja/latest/#id4
  4. ίʔσΟϯάن໿ͷྫ nΠϯσϯτͷݸ਺ int main(void){ int i; for(i = 0; i

    < 10; i++){ printf(“hello world”); } return 0; } int main(void){ int i; for(i = 0; i < 10; i++){ printf(“hello world”); } return 0; } Πϯσϯτ2จࣈ෼ • 1ߦ͕୹͍ Πϯσϯτ4จࣈ෼ • ϒϩοΫ͕Θ͔Γ΍͍͢ ஫ɿλϒʢ1จࣈʣͰ΋ΤσΟλ্Ͱ͸͓ ͳ͡ʹݟ͑ͯ͠·͏ • ൒֯εϖʔεΛ4จࣈ෼࢖͏ʢ௨ৗʣ • λϒΛ1จࣈ෼࢖͏ʢී௨͸΍Βͳ ͍ʣ ͪ͜Β͕ඪ४త
  5. ίʔσΟϯάن໿ͷྫ n{}Λ͚ͭΔҐஔ int main(void){ int i; for(i = 0; i

    < 10; i++){ printf(“hello world”); } return 0; } int main(void) { int i; for(i = 0; i < 10; i++) { printf(“hello world”); } return 0; } ʮ{ʯ͸ߦ຤ • ίʔυߦ਺͕গͳ͍ ʮ{ʯ͸ߦ಄ • είʔϓ͕Θ͔Γ΍͍͢ ͪ͜Β͕ඪ४త
  6. ίʔσΟϯάن໿ͷྫ n()΍ԋࢉࢠͷલޙͷۭനͷ༗ແ int main(void){ int i; for(i = 0; i

    < 10; i++){ printf(“hello world”); } return 0; } int main (void) { int i; for (i=0; i<10; i++) { printf (“hello world”); } return 0; } ۭനΛۭ͚ͳ͍ • 1ߦ͕୹͍ ۭനΛۭ͚Δ • Θ͔Γ΍͍͢ ͪ͜Β͕ඪ४త
  7. ίʔσΟϯάن໿ͷྫ nۭനߦͷ਺ int main(void){ int i; for(i = 0; i

    < 10; i++){ printf(“hello world”); } return 0; } int main(void){ int i; for(i = 0; i < 10; i++){ printf(“hello world”); } return 0; } ۭߦΛೖΕͳ͍ • ίʔυߦ਺͕গͳ͍ ۭߦΛೖΕΔ • ·ͱ·Γ͕Θ͔Γ ΍͍͢ ͪ͜Β͕ඪ४త
  8. ໋໊نଇɿม਺໊ͷ෇͚ํͷ໿ଋ n έʔεɿେจࣈʢupper caseʣ΍খจࣈʢlower caseʣͷ͜ͱ n େจࣈখจࣈͰͭͳ͛ΔΩϟϝϧέʔεʢCamelɿΒͩ͘ʣ • camelCase (lowerCamelCase)

    • CamelCase (UpperCamelCase, PascalCase) n ΞϯμʔείΞͰͭͳ͛ΔεωʔΫέʔεʢsnaleɿϔϏʣ • snake_case • UPPER_SNAKE_CASE n ϋΠϑϯͰͭͳ͛Δʢkebabɿέόϒ͸۲ࢗ͠ྉཧʣ • kebab-case (chain-case) n ܕΛ๯಄ʹ෇͚Δ • ϋϯΨϦΞϯه๏ɿpCamelCase • p͸ϙΠϯλɼi͸intܕɼb͸boolܕɼͳͲ
  9. ౷ҰతͳίʔσΟϯάن໿ nϓϩδΣΫτຖͷن໿Ͱ͸ • ଞͷϓϩδΣΫτͰ͸ίʔυن໿Λ֮͑௚͢͜ͱʹͳΔ nݴޠͰ౷Ұͨ͠΋ͷ͕͋Δ • ୭΋͕ͦΕʹै͑͹ඪ४తͳίʔυΛॻ͚Δ • PythonɿPEP8ʢPython Enhancement

    Proposalʣ • PHP: PSR-0/1/2ʢPHP Standards Recommendationsʣ nඪ४తͳن໿Λ࢖͏͜ͱ͕ଟ͍ • Ұൠతʹଟ͘ͷϓϩδΣΫτͰΑ͘࢖ΘΕ͍ͯΔ΋ͷ • Google Style Guides https://google.github.io/styleguide/ • ֤छݴޠ༻͋ΓʢC, C++, Java, Python, etcʣ
  10. 1&1ղઆ https://pep8-ja.readthedocs.io/ja/latest/ ΑΓ Public Domain © Copyright 2014, Yoshinari Takaoka

  11. Πϯσϯτ # ਖ਼͍͠: # ։͖ׅހʹଗ͑Δ foo = long_function_name(var_one, var_two, var_three,

    var_four) # Ҿ਺ͱͦΕҎ֎Λ۠ผ͢ΔͨΊɺεϖʔεΛ4ͭ(ΠϯσϯτΛ͞Βʹ)Ճ͑Δ def long_function_name( var_one, var_two, var_three, var_four): print(var_one) # ಥ͖ग़͠Πϯσϯτ͸ΠϯσϯτͷϨϕϧΛਂ͘͢Δ foo = long_function_name( var_one, var_two, var_three, var_four) 1ϨϕϧΠϯσϯτ͢Δ͝ͱʹɺεϖʔεΛ4ͭ࢖͍·͠ΐ͏ɻ
  12. Πϯσϯτ # ؒҧ͍: # ંΓฦ͞ΕͨཁૉΛॎʹଗ͑ͳ͍৔߹ɺ1ߦ໨ͷҾ਺͸ېࢭ foo = long_function_name(var_one, var_two, var_three,

    var_four) # Πϯσϯτ͕۠ผͰ͖ͳ͍ͷͰɺ2ߦ໨Ҏ߱Ͱ͞ΒʹΠϯσϯτ͕ඞཁ def long_function_name( var_one, var_two, var_three, var_four): print(var_one) 1ϨϕϧΠϯσϯτ͢Δ͝ͱʹɺεϖʔεΛ4ͭ࢖͍·͠ΐ͏ɻ
  13. ԋࢉࢠͷલͰվߦ͢΂͖͔ɺޙͰվߦ͢΂͖͔ # ؒҧ͍: # ԋࢉࢠ͕Φϖϥϯυͱ཭Εͯ͠·͍ͬͯΔ income = (gross_wages + taxable_interest

    + (dividends - qualified_dividends) - ira_deduction - student_loan_interest)
  14. ԋࢉࢠͷલͰվߦ͢΂͖͔ɺޙͰվߦ͢΂͖͔ # ਖ਼͍͠: # ԋࢉࢠͱΦϖϥϯυΛҰகͤ͞΍͍͢ income = (gross_wages + taxable_interest

    + (dividends - qualified_dividends) - ira_deduction - student_loan_interest)
  15. ߦ͸จࣈҎԼ n1ߦͷ௕͞ • ͢΂ͯͷߦͷ௕͞Λɺ࠷େ79จࣈ·Ͱʹ੍ݶ͠·͠ΐ͏ɻ • ΄ͱΜͲͷπʔϧͷσϑΥϧτͷંΓฦ͠ಈ࡞͸ɺίʔυͷݟͨ໨ͷߏ଄Λյ ͠ɺཧղ͢ΔͷΛ೉͘͠͠·͢ɻ79จࣈͱ͍͏੍ݶ͸ɺ΢Οϯυ΢ͷ෯Λ80 ʹ੍ݶ͠ɺߦΛંΓฦ͢ͱ͖ʹπʔϧ͕ߦ຤ʹϚʔΧʔΛஔ͍ͨͱͯ͠΋ɺΤ σΟλʹંΓฦ͢ಈ࡞Λͤ͞ͳ͍໨తͰબ͹Ε͍ͯ·͢ɻ ΤσΟλͷઃఆʹ

    Αͬͯ͸80จࣈͷͱ ͜Ζʹઢ͕ग़Δ
  16. ࣜ΍จதͷۭനจࣈ nׅހ΍ϒϥέοτɺ೾ׅހ ͷ͸͡Ίͷ௚ޙͱɺऴΘΓͷ௚લ: • # ਖ਼͍͠: spam(ham[1], {eggs: 2}) •

    # ؒҧ͍: spam( ham[ 1 ], { eggs: 2 } ) n຤ඌͷΧϯϚͱɺͦͷޙʹଓ͘ด͡Χοίͷؒ: • # ਖ਼͍͠: foo = (0,) • # ؒҧ͍: bar = (0, ) nΧϯϚ΍ηϛίϩϯɺίϩϯͷ௚લ: • # ਖ਼͍͠: if x == 4: print x, y; x, y = y, x • # ؒҧ͍: if x == 4 : print x , y ; x , y = y , x ༨ܭͳۭനจࣈΛ࢖͏ͷ͸΍Ί·͠ΐ͏
  17. ࣜ΍จதͷۭനจࣈ n# ਖ਼͍͠: • ham[1:9], ham[1:9:3], ham[:9:3], ham[1::3], ham[1:9:] •

    ham[lower:upper], ham[lower:upper:], ham[lower::step] • ham[: upper_fn(x) : step_fn(x)], ham[:: step_fn(x)] • ham[lower + offset : upper + offset] n# ؒҧ͍: • ham[lower + offset:upper + offset] • ham[1: 9], ham[1 :9], ham[1:9 :3] • ham[lower : : upper] • ham[ : upper] ༨ܭͳۭനจࣈΛ࢖͏ͷ͸΍Ί·͠ΐ͏
  18. ࣜ΍จதͷۭനจࣈ nؔ਺ݺͼग़͠ͷҾ਺ϦετΛ͸͡ΊΔ։͖ׅހͷ௚લ: • # ਖ਼͍͠: spam(1) • # ؒҧ͍: spam

    (1) nΠϯσοΫε΍εϥΠεͷ։͖ׅހͷ௚લ: • # ਖ਼͍͠: dct['key'] = lst[index] • # ؒҧ͍: dct ['key'] = lst [index] n୅ೖ(΍ଞͷ)ԋࢉࢠΛଗ͑ΔͨΊʹɺԋࢉࢠͷपғʹ1ͭҎ্ͷε ϖʔεΛೖΕΔ: • # ਖ਼͍͠: x = 1 y = 2 long_variable = 3 ༨ܭͳۭനจࣈΛ࢖͏ͷ͸΍Ί·͠ΐ͏ • # ؒҧ͍: x = 1 y = 2 long_variable = 3
  19. ࣜ΍จதͷۭനจࣈ nؔ਺ݺͼग़͠ͷҾ਺ϦετΛ͸͡ΊΔ։͖ׅހͷ௚લ: • # ਖ਼͍͠: spam(1) • # ؒҧ͍: spam

    (1) nΠϯσοΫε΍εϥΠεͷ։͖ׅހͷ௚લ: • # ਖ਼͍͠: dct['key'] = lst[index] • # ؒҧ͍: dct ['key'] = lst [index] n୅ೖ(΍ଞͷ)ԋࢉࢠΛଗ͑ΔͨΊʹɺԋࢉࢠͷपғʹ1ͭҎ্ͷε ϖʔεΛೖΕΔ: • # ਖ਼͍͠: x = 1 y = 2 long_variable = 3 ༨ܭͳۭനจࣈΛ࢖͏ͷ͸΍Ί·͠ΐ͏ • # ؒҧ͍: x = 1 y = 2 long_variable = 3 • ͜Ε΋ؒҧ͍ʂʂʂ x=1 y=2 if a>0 and b<0: z = 2*y + 4/b • ਖ਼͘͠͸ x = 1 y = 2 if a > 0 and b < 0: z = 2 * y + 4 / b ԋࢉࢠલޙͷۭന͸ʮ༨ܭ ͳۭനʯͰ͸ͳ͍ʂ
  20. कΔ΂໋໊͖ن໿ n͜Μͳ໊લ͸ݏͩ • ୯Ұͷจࣈ 'l' (খจࣈͷΤϧ)ɺ'O' (େจࣈͷΦʔ)ɺ'I'(େจࣈͷΞΠ) Λܾͯ͠ ม਺ʹ࢖Θͳ͍Ͱ͍ͩ͘͞ɻ •

    ϑΥϯτʹΑͬͯ͸ɺ͜ΕΒͷจࣈ͸਺ࣈͷ1΍0ͱ۠ผ͕෇͔ͳ͍৔߹͕͋Γ ·͢ɻ'l'(খจࣈͷΤϧ) Λ࢖͍ͨ͘ͳͬͨΒɺ'L' Λ୅ΘΓʹ࢖͍·͠ΐ͏ɻ nϑΥϯτʹ͸ͩ͜ΘΕ ϑΥϯτɿArial class TestMyAdd(unittest.TestCase): def test_add(self): val = myadd(1, 2) self.assertEqual(3, val) def test_add_pp(self): val = myadd(2, 6) self.assertTrue(val > 0) def myadd(l, I): if l > 0 and I > 0: return l + I if l < 0 and I < 0: return l + I Arial͸࢖Θͳ͍ʂ • ϓϩϙʔγϣφϧϑΥϯτ͔ͩΒଗΘͳ͍ • lͱIɼ0ͱO͕ฆΒΘ͍͠
  21. कΔ΂໋໊͖ن໿ n͜Μͳ໊લ͸ݏͩ • ୯Ұͷจࣈ 'l' (খจࣈͷΤϧ)ɺ'O' (େจࣈͷΦʔ)ɺ'I'(େจࣈͷΞΠ) Λܾͯ͠ ม਺ʹ࢖Θͳ͍Ͱ͍ͩ͘͞ɻ •

    ϑΥϯτʹΑͬͯ͸ɺ͜ΕΒͷจࣈ͸਺ࣈͷ1΍0ͱ۠ผ͕෇͔ͳ͍৔߹͕͋Γ ·͢ɻ'l'(খจࣈͷΤϧ) Λ࢖͍ͨ͘ͳͬͨΒɺ'L' Λ୅ΘΓʹ࢖͍·͠ΐ͏ɻ nϑΥϯτʹ͸ͩ͜ΘΕ ϑΥϯτɿTimes / Times New Roman class TestMyAdd(unittest.TestCase): def test_add(self): val = myadd(1, 2) self.assertEqual(3, val) def test_add_pp(self): val = myadd(2, 6) self.assertTrue(val > 0) def myadd(l, I): if l > 0 and I > 0: return l + I if l < 0 and I < 0: return l + I Times͸࢖Θͳ͍ʂ • ϓϩϙʔγϣφϧϑΥϯτ͔ͩΒଗΘͳ͍ • ͦ΋ͦ΋ηϦϑܥͷϑΥϯτͰίʔσΟϯά͠ͳ͍
  22. कΔ΂໋໊͖ن໿ n͜Μͳ໊લ͸ݏͩ • ୯Ұͷจࣈ 'l' (খจࣈͷΤϧ)ɺ'O' (େจࣈͷΦʔ)ɺ'I'(େจࣈͷΞ Π) Λܾͯ͠ม਺ʹ࢖Θͳ͍Ͱ͍ͩ͘͞ɻ •

    ϑΥϯτʹΑͬͯ͸ɺ͜ΕΒͷจࣈ͸਺ࣈͷ1΍0ͱ۠ผ͕෇͔ͳ͍৔߹͕͋ Γ·͢ɻ'l'(খจࣈͷΤϧ) Λ࢖͍ͨ͘ͳͬͨΒɺ'L' Λ୅ΘΓʹ࢖͍· ͠ΐ͏ɻ nϑΥϯτʹ͸ͩ͜ΘΕ ϑΥϯτɿCourier class TestMyAdd(unittest.TestCase): def test_add(self): val = myadd(1, 2) self.assertEqual(3, val) def test_add_pp(self): val = myadd(2, 6) self.assertTrue(val > 0) def myadd(l, I): if l > 0 and I > 0: return l + I if l < 0 and I < 0: return l + I Courier͸·ͩ·͠ • ౳෯ϑΥϯτ͔ͩΒଗͬͯOK • ·ͩ0ͱO͕ฆΒΘ͍͠
  23. कΔ΂໋໊͖ن໿ n͜Μͳ໊લ͸ݏͩ • ୯Ұͷจࣈ 'l' (খจࣈͷΤϧ)ɺ'O' (େจࣈͷΦʔ)ɺ'I'(େจࣈͷΞ Π) Λܾͯ͠ม਺ʹ࢖Θͳ͍Ͱ͍ͩ͘͞ɻ •

    ϑΥϯτʹΑͬͯ͸ɺ͜ΕΒͷจࣈ͸਺ࣈͷ1΍0ͱ۠ผ͕෇͔ͳ͍৔߹͕͋ Γ·͢ɻ'l'(খจࣈͷΤϧ) Λ࢖͍ͨ͘ͳͬͨΒɺ'L' Λ୅ΘΓʹ࢖͍· ͠ΐ͏ɻ nϑΥϯτʹ͸ͩ͜ΘΕ ϑΥϯτɿMenlo class TestMyAdd(unittest.TestCase): def test_add(self): val = myadd(1, 2) self.assertEqual(3, val) def test_add_pp(self): val = myadd(2, 6) self.assertTrue(val > 0) def myadd(l, I): if l > 0 and I > 0: return l + I if l < 0 and I < 0: return l + I MenloͳΒΑ͠ • ౳෯ϑΥϯτ͔ͩΒଗͬͯOK • 0ͱOͷ۠ผ͕ͭ͘
  24. कΔ΂໋໊͖ن໿ n͜Μͳ໊લ͸ݏͩ • ୯Ұͷจࣈ 'l' (খจࣈͷΤϧ)ɺ'O' (େจࣈͷΦʔ)ɺ'I'(େจࣈͷΞ Π) Λܾͯ͠ม਺ʹ࢖Θͳ͍Ͱ͍ͩ͘͞ɻ •

    ϑΥϯτʹΑͬͯ͸ɺ͜ΕΒͷจࣈ͸਺ࣈͷ1΍0ͱ۠ผ͕෇͔ͳ͍৔߹͕͋ Γ·͢ɻ'l'(খจࣈͷΤϧ) Λ࢖͍ͨ͘ͳͬͨΒɺ'L' Λ୅ΘΓʹ࢖͍· ͠ΐ͏ɻ nϑΥϯτʹ͸ͩ͜ΘΕ ϑΥϯτɿSource Code Pro class TestMyAdd(unittest.TestCase): def test_add(self): val = myadd(1, 2) self.assertEqual(3, val) def test_add_pp(self): val = myadd(2, 6) self.assertTrue(val > 0) def myadd(l, I): if l > 0 and I > 0: return l + I if l < 0 and I < 0: return l + I Source Code ProͳΒΑ͠ • ౳෯ϑΥϯτ͔ͩΒଗͬͯOK • 0ͱOͷ۠ผ͕ͭ͘
  25. कΔ΂໋໊͖ن໿ n͜Μͳ໊લ͸ݏͩ • ୯Ұͷจࣈ 'l' (খจࣈͷΤϧ)ɺ'O' (େจࣈͷΦʔ)ɺ'I'(େจࣈͷΞ Π) Λܾͯ͠ม਺ʹ࢖Θͳ͍Ͱ͍ͩ͘͞ɻ •

    ϑΥϯτʹΑͬͯ͸ɺ͜ΕΒͷจࣈ͸਺ࣈͷ1΍0ͱ۠ผ͕෇͔ͳ͍৔߹͕͋ Γ·͢ɻ'l'(খจࣈͷΤϧ) Λ࢖͍ͨ͘ͳͬͨΒɺ'L' Λ୅ΘΓʹ࢖͍· ͠ΐ͏ɻ nϑΥϯτʹ͸ͩ͜ΘΕ ϑΥϯτɿSource Code Pro class TestMyAdd(unittest.TestCase): def test_add(self): val = myadd(1, 2) self.assertEqual(3, val) def test_add_pp(self): val = myadd(2, 6) self.assertTrue(val > 0) def myadd(l, I): if l > 0 and I > 0: return l + I if l < 0 and I < 0: return l + I Source Code ProͳΒΑ͠ • ౳෯ϑΥϯτ͔ͩΒଗͬͯOK • 0ͱOͷ۠ผ͕ͭ͘ ࣗ෼ͰϑΥϯτΛΠϯετʔϧ͠Α͏ • ϓϩάϥϛϯά͕௙Γ͗͢ΔʂίʔσΟϯάʹ ࠷దͳϑΥϯτબ • গ͠Ͱ΋ίʔσΟϯά͢ΔͳΒlίʔσΟϯά༻ ϑΥϯτzΛಋೖ͠Α͏ • Top Programming Fonts
  26. कΔ΂໋໊͖ن໿ nύοέʔδͱϞδϡʔϧͷ໊લ • Ϟδϡʔϧͷ໊લ͸ɺશͯখจࣈͷ୹໊͍લʹ͢΂͖Ͱ͢ɻಡΈ΍͘͢ͳΔͳ ΒɺΞϯμʔείΞΛϞδϡʔϧ໊ʹ࢖ͬͯ΋ߏ͍·ͤΜɻPython ͷύο έʔδ໊͸ɺશͯখจࣈͷ୹໊͍લΛ࢖͏΂͖Ͱ͕͢ɺΞϯμʔείΞΛ࢖͏ ͷ͸ਪ঑͞Ε·ͤΜɻ nΫϥεͷ໊લ •

    Ϋϥεͷ໊લʹ͸௨ৗ CapWords ํࣜΛ࢖͏΂͖Ͱ͢ɻ nܕม਺ͷ໊લ • PEP484Ͱಋೖ͞Εͨܕม਺ͷ໊લʹ͸ɺ௨ৗCapWordsํࣜΛ࢖͏΂͖Ͱ͢ɻ ·ͨɺT΍AnyStr΍NumͷΑ͏ͳ୹໊͍લ͕޷·͍͠Ͱ͢ɻ CamelCase CamelCase snakecase
  27. कΔ΂໋໊͖ن໿ nؔ਺΍ม਺ͷ໊લ • ؔ਺ͷ໊લ͸খจࣈͷΈʹ͢΂͖Ͱ͢ɻ·ͨɺಡΈ΍͘͢͢ΔͨΊʹɺඞཁʹ Ԡͯ͡୯ޠΛΞϯμʔείΞͰ۠੾Δ΂͖Ͱ͢ɻ • ม਺ͷ໊લʹ͍ͭͯ΋ɺؔ਺ͱಉ͡ن໿ʹै͍·͢ɻ nϝιου໊ͱΠϯελϯεม਺ • ؔ਺ͷ໋໊ن໿Λ࢖͍ͬͯͩ͘͞ɻͭ·Γɺ໊લ͸খจࣈͷΈʹͯ͠ɺಡΈ΍

    ͘͢͢ΔͨΊʹඞཁʹԠͯ͡୯ޠΛΞϯμʔείΞͰ۠੾Γ·͢ɻ nఆ਺ • શͯͷఆ਺͸େจࣈͰॻ͖ɺ୯ޠΛΞϯμʔείΞͰ۠੾Γ·͢ɻྫͱ͠ ͯ MAX_OVERFLOW ΍ TOTAL ͕͋Γ·͢ɻ snake_case snake_case SNAKE_CASE
  28. ࣮ࡍͷྫɿςετίʔυ ύοέʔδ໊ snakecase Ϋϥε໊ CamelCase ؔ਺໊ snake_case Ϋϥε໊ CamelCase ϝιου໊

    snake_case ϝιου໊ camelCase ʢPEP8ʹ͕͍ͨͬͯ͠ͳ͍ʂʣ test_integration.py
  29. DPEF DIFDLFSGPSNBUUFS

  30. νΣοΧʔͱϑΥʔϚολ nνΣοΧʔ • ن໿ʹԊ͍ͬͯΔ͔Ͳ͏͔ΛνΣοΫ • flake8 • Python༻PEP8νΣοΧʔ nϑΥʔϚολʔ •

    ن໿ʹԊͬͨίʔυʹमਖ਼ • ผ໊ɿbeautifier • मਖ਼Λformatting΍beautificationͱ΋ݴ͏ • autopep8 • Python༻PEP8ϑΥʔϚολʔ ن໿Λक͍ͬͯͳ͍ ΠϚΠνͳίʔυ
  31. 'MBLFʹΑΔίʔυνΣοΫ νΣοΫ͢ΔϑΝΠ ϧ໊ʢࢦఆ͠ͳ͚Ε ͹pwdͷϑΝΠϧΛ͢ ΂ͯʣ

  32. 'MBLFʹΑΔίʔυνΣοΫ ରԠ͢Διʔ εߦΛදࣔ

  33. BVUPQFQʹΑΔϑΥʔϚοςΟϯά मਖ਼͢Διʔ εϑΝΠϧ मਖ਼લͷίʔυ मਖ਼ޙͷίʔυ ʢඪ४ग़ྗʹදࣔ ͞ΕΔ͚ͩʣ

  34. BVUPQFQʹΑΔϑΥʔϚοςΟϯά मਖ਼͢ΔιʔεϑΝΠϧΛ௚઀ॻ͖׵ ͑Δʢ্ॻ͖ɼ--in-placeʣ -aͳ͠ -a͋Γ -aΛ͚ͭΔͱԋࢉࢠલޙͷۭന·Ͱݫ ີʹमਖ਼

  35. 74DPEFͰGMBLF

  36. ֦ுػೳΛೖΕ Α͏ pythonͰݕࡧ Microsoftͷ python֦ுΛΠϯε τʔϧ

  37. ίϚϯυύϨοτ͔Β select linter Λݕࡧͯ͠ɽɽɽ

  38. flake8Λબ୒

  39. ίʔυதʹflake8݁Ռ͕ ೾ઢͰදࣔ͞ΕΔ Ϛ΢εΦʔόʔͰ಺༰͕ දࣔ͞ΕΔ

  40. 74DPEFͰ BVUPQFQ

  41. ઃఆը໘Λ։͘

  42. formatonsave Ͱݕࡧͯ͠ Format On Save ʹνΣοΫΛೖΕΔͱɼϑΝΠϧΛอଘ͢ Δͨͼʹautopep8͕૸Δ

  43. อଘલ ·ͩϑΥʔϚοτ͞Εͯ ͍ͳ͍

  44. อଘͨ͠ॠؒʹϑΥʔ Ϛοτ͕࣮ߦ͞ΕΔ

  45. ࣗಈอଘͷઃఆ autosaveͰݕࡧ ઃఆΛ։͍ͯ σϑΥϧτ1000msΛ 200msఔ౓ʹมߋ͠Α͏

  46. auto save͞ΕΔλΠϛϯάΛʮafterDelayʯʹ͠Α͏ɽ ͜͏͢Δͱ΄΅ϦΞϧλΠϜͰautopep8͕૸Δʂ ஫ҙɿେن໛ͳίʔυͷ৔߹ʹ͸autopep8ͷ࣮ߦ͸ ஗͍ͷͰɼafterDelayͷઃఆͰ͸ͳ͘ɼ onFocusChangeͳͲผͷઃఆʹͨ͠΄͏͕ྑ͍

  47. ԋࢉࢠલޙ΋ϑΥʔϚοςΟϯά͢Δઃఆ autopep8Ͱݕࡧ Autopep8 Argsʹ -a Λ௥Ճ͢Δͱ΋ͬͱݫີʹमਖ਼͢Δ -aͳ͠ -a͋Γ

  48. ߦจࣈͷઢͷઃఆ editor.rulerͰݕࡧ jsonͰฤूΛΫϦοΫ

  49. ͜ͷ༷ʹ80Λ௥ Ճ͢Δ

  50. ֤छΦϯϥΠϯπʔ ϧ python online formatter ͳͲͰݕࡧ͢Δͱଟ਺ݟ͔ͭΔ

  51. ΦϯϥΠϯπʔϧ https://www.tutorialspoint.com/online_python_formatter.htm

  52. ΦϯϥΠϯπʔϧ https://black.now.sh

  53. ೉ಡԽ

  54. Ϗϧυͱ͸ nίʔυΛίϯύΠϧ࣮ͯ͠ߦܗࣜϑΝΠϧͳͲΛ࡞੒͢Δ͜ͱ • C, C++ͳͲ ίϯύΠϥ ϦϯΧ ιʔε ϑΝΠϧ ΦϒδΣΫτ

    ϑΝΠϧ ੩తϥΠϒϥϦ ʢ*.aʣ ࣮ߦ ϑΝΠϧ ੩త ϦϯΫ ίϯύΠϧ ࣮ߦ ϑΝΠϧ ڞ༗ϥΠϒϥϦ (*.so) DLL ಈత ϦϯΫ Ϗϧυ ࣮ߦ
  55. ϦόʔεΤϯδχΞϦϯά n࣮ߦܗࣜʢόΠφϦʣϑΝΠϧ͔Βιʔείʔυʹ໭͢͜ͱ ίϯύΠϥ ϦϯΧ ιʔε ϑΝΠϧ ΦϒδΣΫτ ϑΝΠϧ ੩తϥΠϒϥϦ ʢ*.aʣ

    ࣮ߦ ϑΝΠϧ ੩త ϦϯΫ ίϯύΠϧ Ϗϧυ ϦόʔεΤϯδχΞϦϯά • ࣦΘΕͨιʔείʔ υΛ෮چ͍ͨ͠ • ٕज़Λ౪Έ͍ͨ • ίϐʔͯ͠ແྉͰ࢖ ͍͍ͨ େ఍ͷϥΠηϯεͰ͸ ϢʔβʔͷϦόʔεΤ ϯδχΞϦϯάΛېࢭ ͍ͯ͠Δ
  56. Ϣʔβʔ nೲ඼ઌʢൃ஫ଆʣͷϢʔβʔ͕ ϦόʔεΤϯδχΞϦϯά • ࠶౓ൃ஫͠ͳͯ͘Α͍ɽɽɽ • ʢ஫ɿҧ๏Ͱ͢ʂʣ ൃ஫ଆ ड஫ଆ อकͷֹۚߴ

    ͍Ͱ͢Ͷ ྃղ ϦόʔεΤϯ δχΞϦϯά ͯ͠मਖ਼͸ࣗ ෼ୡͰ΍Ε͹ ແྉʂ ೲ඼ޙ΋อकमਖ਼ ͢Δܖ໿Λͱͬͯ ͍͜ ϏϧυͰ͖ͨͷͰ ϦϦʔεͰ͖·͢ ࣮ߦϑΝΠϧ Ͱೲ඼͠·͢ อकमਖ਼΋ঝ Γ·͕͢ ࣮ߦϑΝΠϧ ड͚औΓ·͠ ͨ อकमਖ਼ͷґ པ͸ݕ౼͠· ͢
  57. ݩ੥͚ nݩ੥͚͕ϦόʔεΤϯδχΞϦϯά • ͍҆ݩ੥͚ʹྲྀ͢ɽɽɽ • ʢ஫ɿҧ๏Ͱ͢ʂʣ • ٕज़ͷྲྀग़ ൃ஫ऀ ݩ੥͚

    ೲ඼͠·͢ ड͚औΓ·͠ ͨ ࠷ॳͷԼ੥͚ Ͱ͖·ͨ͠ ೲ඼͠·͢ ड͚औΓ·͠ ͨ
  58. ݩ੥͚ nݩ੥͚͕ϦόʔεΤϯδχΞϦϯά • ͍҆ݩ੥͚ʹྲྀ͢ɽɽɽ • ʢ஫ɿҧ๏Ͱ͢ʂʣ • ٕज़ͷྲྀग़ ൃ஫ऀ ݩ੥͚

    ࠷ॳͷԼ੥͚ ͍҆Լ੥͚ ͋Γ͕ͱ͏͝ ͍͟·͢ʂ ͜ͷγεςϜ Λ·ͨൃ஫͠ ·͢ ͦ͏Ͱ͢ ͔ɽɽɽ ࢒೦Ͱ͕͢ࠓ ճ͸ɽɽɽ ྃղͰ͢ લճͷϕϯμͷόΠ φϦΛϦόʔεΤϯ δχΞϦϯάͯ͠ ࢖ͬͯ҆ͯ͘͠
  59. ೉ಡԽ nC, C++ͳͲίϯύΠϧ͢Δݴޠ • ࣮ߦόΠφϦΛೲ඼ • ϦόʔεΤϯδχΞϦϯά͸ࠔ೉ nPythonͳͲεΫϦϓτݴޠ • εΫϦϓτʹιʔείʔυΛೲ඼

    • ϦόʔεΤϯδχΞϦϯάͲ͜Ζ ͔ίʔυ͕ͦͷ··ೲ඼෺ʂ n೉ಡԽʢobfuscationʣ • ιʔείʔυΛਓ͕ؒ಺༰Λཧղ Ͱ͖ͳ͍Α͏ʹվม͢Δ • ٕज़ྲྀग़ͷϦεΫΛԼ͛Δ • ࣮ͨͩ͠ߦ݁Ռ͸ಉҰ • ೲ඼෺ͱͯ͠ͷ඼࣭͸อͭ nํ๏ʢPython༻ʣ • ίʔυͷվม • pyminifier, pyobfuscateͳͲ • ݶք͋Γ • ίϯύΠϧ • Cython • ݩʑ͸ߴ଎ʹ࣮ߦ͢ΔͨΊ • όΠφϦม׵ • PyArmor • ഑෍༻ • ϥΠηϯεظݶͳͲΛ͚ͭ ΒΕΔ
  60. QZNJOJGJFSͷ݁Ռ docker-compose exec mypython pyminifier --obfuscate-builtins --obfuscate main.py > main.obs.py

    ·ͩಡΊΔ
  61. QZPCGVTDBUFͷ݁Ռ docker-compose exec mypython pyobfuscate -i main.py > main.obs.py ಡΊͳ͍ɽɽɽʁ

  62. QZPCGVTDBUFͷ݁Ռ docker-compose exec mypython pyobfuscate -i main.py > main.obs.py ్த͔ΒಡΊΔ

  63. 0OMJOF0CGVTDBUPS https://pyob.oxyry.com ಡΊΔ͕ม਺໊͕ ΄΅۠ผෆՄೳ

  64. 1Z"SNPSʹΑΔ೉ಡԽ ೉ಡԽ͢ΔϑΝΠϧ໊ ೉ಡԽͷࢦఆ ੜ੒͞ΕΔ ഑෍༻ (dist) ͷ೉ಡԽ ίʔυͱ࣮ ߦ༻ϥΠϒ ϥϦ

  65. 1Z"SNPSʹΑΔ೉ಡԽ ੍໿ɿ෇ଐϥΠϒϥϦ͕ඞཁ • OS΍Pythonͷόʔδϣϯ͕ มΘΔͱ࣮ߦͰ͖ͳ͍ • dockerΛ࢖͑͹ղܾ • ͜ͷ੍໿͸ίϯύΠϧͱಉ͡ •

    pyarmorͳΒϥΠηϯεظ ݶ͕དྷͨΒ࣮ߦͰ͖ͳ͘ ͢Δ͜ͱ΋Ͱ͖Δ main.py dist/main.py
  66. ੈքҰ ಡΈʹ͍͘ίʔυબखݖ

  67. ࠃࡍ೉ಡԽ$ίʔυίϯςετ nίʔυͷಡΈ೉͞Λڝ͏ί ϯςετ • Cݴޠݶఆ • C͸࢓༷͕؇͍͔ΒͻͲ ͍ίʔυͰ΋ίϯύΠϧ ࣮ͯ͠ߦͰ͖Δ https://www.ioccc.org

    https://www.ioccc.org/years.html#2020
  68. 8JOOFST https://www.ioccc.org/2020/burton/prog.c https://www.ioccc.org/2020/burton/index.html

  69. 8JOOFST https://www.ioccc.org/2020/carlini/prog.c https://www.ioccc.org/2020/carlini/index.html

  70. 8JOOFST https://www.ioccc.org/2020/endoh1/prog.c https://www.ioccc.org/2020/endoh1/index.html

  71. 8JOOFSWTGPSNBUUFS #include /**/ < time.h > #include <ncurses.h> #include <stdlib.h>

    /** */ #define O() for ( y -= !!y; y < H && /*...Semi-Automatic.*/ y < p / W + 2; y++) for (x = p % W, x -= !!/*..MineSweeper...*/ x; x < W && x < p % W + 2; x++) #define _(x, y) COLOR_##x, COLOR_##y /* click / (R)estart / (Q)uit */ #define Y(n)attrset(COLOR_PAIR(n)),mvprintw(/* IOCCC2019 or IOCCC2020 */ typedef int I; I *M, W, H, S, C, E, X, T, c, p, q, i, j, k; char G[] = " x", U[256]; I F(I p) { I r = 0, x, y = p / W, q; O() q = y * W + x, r += M[q] ^= p - q ? (M[q] & 16) << 8 : 0; return r; } I K(I p, I f, I g) { I x = (g + f / 256) % 16 - (f + g / 256) % 16, y = p / W, c = 0, n = g / 4096, m = x == n ? 0 : x == g / 16 % 16 - f / 16 % 16 - n ? 256 : -1; if (m + 1) O() if ((4368 & M[n = y * W + x]) == 4112) { M[c = 1, n] = (M[n] & ~16) | m; } return c; } void D() { I p, k, o = 0, n = C, m = 0, q = 0; if (LINES - 1 < H || COLS / 2 < W)clear (),Y(4)LINES/2,COLS/2-16,"Make the ter¥ minal bigger!"); else { for (p = 0; p < S; o += k == 3, Y(k) p / W + 1, p % W * 2, G),p++)G[1]="" "_*!..12345678"[k=E?256&M[p ]?n--,2:E-2||M[p]%2<1?M[p]&16?q=p,m++,3:4+F(p)%16: 1:3]; k = T + time(0); T = o || T >= 0 || E - 1 ? T : k; k = T < 0 ? k : T;Y(7)0,0,"%03d%*s%03d",n>999?999:n,W* 2-6,"",k>999?999:k);Y(9)0,W-1,E>1?"X-(":E-1||o?":-)":"8-)"); M[q] |= 256 * (n == m && n); } refresh(); } short B[] = {_(RED, BLACK), _(WHITE, BLUE), _(GREEN, RED), _(MAGENTA, YELLOW), _(CYAN, RED)}; I main(I A, char** V) { https://www.ioccc.org/2020/endoh1/prog.c https://github.com/KrzaQ/cppformat http://format.krzaq.cc ͰGoogleελΠϧ΁ϑΥʔϚοτ ͨ͠Βɽɽɽ ແཧͳ΋ͷ͸ແཧ
  72. None
  73. ՝୊ nࣗ෼ͷաڈʹॻ͍ͨίʔυ͕Ͳͷ Α͏ͳن໿ʹै͍͔ͬͯͨɼ΋͠ ͘͸ै͍ͬͯͳ͔͔ͬͨɼΛ۩ମ ྫΛ্͛ͯઆ໌͢Δ nͦͷίʔυʹରͯ͠ن໿ʹ४ڌ͠ ͨίʔυʹमਖ਼͢Δ • ม਺໊͸खಈͰमਖ਼ •

    pythonͳΒautopep8Λར༻ɼͦΕҎ ֎ͷݴޠ͸ԿΒ͔ͷϑΥʔϚολΛ ར༻ʢҎԼ͸ࢀߟྫɽ࢖༻ͨ͠πʔ ϧɾαΠτΛ໌ه͢Δ͜ͱʣ • Java • https://www.tutorialspoint.com /online_java_formatter.htm • https://codebeautify.org/javavi ewer • https://jsonformatter.org/java- formatter • C/C++ • https://www.tutorialspoint.com /online_c_formatter.htm • http://format.krzaq.cc • https://codebeautify.org/cpp- formatter-beautifier • Perl • https://www.tutorialspoint.com /online_perl_formatter.htm
  74. ૝ఆࢼݧ໰୊ nίʔσΟϯάن໿ͱ͸Կ͔ɼͦͷॏཁੑΛઆ໌ͤΑ nίʔσΟϯάن໿ͷྫΛ۩ମྫΛ্͛ͯઆ໌ͤΑ nม਺ͷ໋໊نଇʹ͸ͲͷΑ͏ͳ΋ͷ͕͋Δͷ͔ɼ۩ମྫΛ্͛ͯઆ໌ ͤΑ nPEP8Ͱࢦఆ͞Ε͍ͯΔΠϯσϯτɾۭനจࣈɾ໋໊ن໿ͷ࢖͍ํ͸ Կ͔Λઆ໌ͤΑ nflake8΍autopep8ͷ࢖͍ํΛઆ໌ͤΑ n೉ಡԽͱ͸Կ͔ɼͦͷඞཁੑͱɼ೉ಡԽ͠ͳ͍৔߹ʹੜ͡Δ໰୊Λઆ ໌ͤΑ