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

はじめようきれいなコード

 はじめようきれいなコード

D96c7e61d2f394f1d0af66945181a230?s=128

きりみん

June 01, 2018
Tweet

Transcript

  1. ͸͡ΊΑ͏ ͖Ε͍ͳίʔυ @kirimin

  2. Α͘ʮྑ͍ίʔυʯͱ͔ ʮ͖Ε͍ͳίʔυʯͱ͔͍͏ ݴ༿ΛݟΔ͚Ͳ

  3. ಉ͡ॲཧΛ͢ΔϓϩάϥϜʹ ͦΜͳҧ͍ͳΜͯ͋Δͷ͔ͳʁ

  4. ͋ΔΑ

  5. ͖Ε͍ͳίʔυͷఆٛ ͖Ε͍ͳσʔλઃܭ ͖Ε͍ͳΞʔΩςΫνϟઃܭ ͖Ε͍ͳΫϥεઃܭ ͖Ε͍ͳؔ਺ ͖Ε͍ͳॲཧ

  6. ͖Ε͍ͳίʔυͷఆٛ ͖Ε͍ͳσʔλઃܭ ͖Ε͍ͳΞʔΩςΫνϟઃܭ ͖Ε͍ͳΫϥεઃܭ ͖Ε͍ͳؔ਺ ͖Ε͍ͳॲཧ ࠓ೔ͷςʔϚ

  7. ͖Ε͍ͳॲཧ

  8. ྫ୊ w -JTUͷத਎͕B C DͷॱʹฒΜͰ͍Δ͔Λ ௐ΂Δɻ w ਖ਼͚͠Ε͹ʮTVDDFTTʯɺҧ͍ͬͯΕ͹ ʮ'BJMFEʯͱग़ྗ͢Δɻ

  9. ྫ୊ public static void main(String[] args) { List<String> list =

    new ArrayList<>(); list.add("a"); list.add("b"); list.add("c"); boolean flag; if (list.isEmpty()) { flag = false; } else { if (list.get(0).equals("a")) { if (list.size() > 2) { if (list.get(1).equals("b")) { if (list.size() > 3) { if (list.get(2).equals("c")) { flag = true; } else { flag = false; } } else { flag = false; } } else { flag = false; } } else { flag = false; } } flag = false; } if (flag == true) { System.out.println("Success!!!"); } else { System.out.println("Failed!!!"); } }
  10. ໰୊఺ w Πϯσϯτ͕ਂ͍ w ൑ఆॲཧ͕ແବʹΘ͔Γʹ͍͘ w ม਺໊͕Θ͔Γʹ͍͘

  11. վળͰ͖Δ͔ͳʁ

  12. ྫ୊ public static void main(String[] args) { List<String> list =

    new ArrayList<>(); list.add("a"); list.add("b"); list.add("c"); boolean flag; if (list.isEmpty()) { flag = false; } else { if (list.get(0).equals("a")) { if (list.size() > 2) { if (list.get(1).equals("b")) { if (list.size() > 3) { if (list.get(2).equals("c")) { flag = true; } else { flag = false; } } else { flag = false; } } else { flag = false; } } else { flag = false; } } flag = false; } if (flag == true) { System.out.println("Success!!!"); } else { System.out.println("Failed!!!"); } }
  13. FMTFʹॲཧ͕ͨ͘͞Μ͋Δ public static void main(String[] args) { List<String> list =

    new ArrayList<>(); list.add("a"); list.add("b"); list.add("c"); boolean flag; if (list.isEmpty()) { flag = false; } else { if (list.get(0).equals("a")) { if (list.size() > 2) { if (list.get(1).equals("b")) { if (list.size() > 3) { if (list.get(2).equals("c")) { flag = true; } else { flag = false; } } else { flag = false; } } else { flag = false; } } else { flag = false; } } flag = false; } if (flag == true) { System.out.println("Success!!!"); } else { System.out.println("Failed!!!"); } }
  14. ൑ఆΛٯʹ public static void main(String[] args) { List<String> list =

    new ArrayList<>(); list.add("a"); list.add("b"); list.add("c"); boolean flag; if (!list.isEmpty()) { if (list.get(0).equals("a")) { if (list.size() > 2) { if (list.get(1).equals("b")) { if (list.size() > 3) { if (list.get(2).equals("c")) { flag = true; } else { flag = false; } } else { flag = false; } } else { flag = false; } } else { flag = false; } } } else { flag = false; } if (flag == true) { System.out.println("Success!!!"); } else { System.out.println("Failed!!!"); } }
  15. ಉ͡ྲྀΕͳͷʹผʑʹ൑ఆͯ͠Δ public static void main(String[] args) { List<String> list =

    new ArrayList<>(); list.add("a"); list.add("b"); list.add("c"); boolean flag; if (!list.isEmpty()) { if (list.get(0).equals("a")) { if (list.size() > 2) { if (list.get(1).equals("b")) { if (list.size() > 3) { if (list.get(2).equals("c")) { flag = true; } else { flag = false; } } else { flag = false; } } else { flag = false; } } else { flag = false; } } } else { flag = false; } if (flag == true) { System.out.println("Success!!!"); } else { System.out.println("Failed!!!"); } }
  16. ൑ఆΛͰ·ͱΊΔ public static void main(String[] args) { List<String> list =

    new ArrayList<>(); list.add("a"); list.add("b"); list.add("c"); boolean flag; if (!list.isEmpty()) { if (list.get(0).equals("a")) { if (list.size() > 2 && list.get(1).equals("b")) { if (list.size() > 3 && list.get(2).equals("c")) { flag = true; } else { flag = false; } } else { flag = false; } } else { flag = false; } } else { flag = false; } if (flag == true) { System.out.println("Success!!!"); } else { System.out.println("Failed!!!"); } }
  17. ࠷ॳͷํ΋ಉ͡൑ఆͰΑͦ͞͏ public static void main(String[] args) { List<String> list =

    new ArrayList<>(); list.add("a"); list.add("b"); list.add("c"); boolean flag; if (!list.isEmpty()) { if (list.get(0).equals("a")) { if (list.size() > 2 && list.get(1).equals("b")) { if (list.size() > 3 && list.get(2).equals("c")) { flag = true; } else { flag = false; } } else { flag = false; } } else { flag = false; } } else { flag = false; } if (flag == true) { System.out.println("Success!!!"); } else { System.out.println("Failed!!!"); } }
  18. ̏ͭͷ൑ఆʹ̏ͭͷJGจ public static void main(String[] args) { List<String> list =

    new ArrayList<>(); list.add("a"); list.add("b"); list.add("c"); boolean flag; if (!list.isEmpty() && list.get(0).equals("a")) { if (list.size() > 2 && list.get(1).equals("b")) { if (list.size() > 3 && list.get(2).equals("c")) { flag = true; } else { flag = false; } } else { flag = false; } } else { flag = false; } if (flag == true) { System.out.println("Success!!!"); } else { System.out.println("Failed!!!"); } }
  19. Ͱ΋͜ͷ൑ఆ͢͜͠෼͔Γʹ͍͘ public static void main(String[] args) { List<String> list =

    new ArrayList<>(); list.add("a"); list.add("b"); list.add("c"); boolean flag; if (!list.isEmpty() && list.get(0).equals("a")) { if (list.size() > 2 && list.get(1).equals("b")) { if (list.size() > 3 && list.get(2).equals("c")) { flag = true; } else { flag = false; } } else { flag = false; } } else { flag = false; } if (flag == true) { System.out.println("Success!!!"); } else { System.out.println("Failed!!!"); } }
  20. ม਺ʹ੾Γग़໊ͯ͠લΛ͚ͭͨ public static void main(String[] args) { List<String> list =

    new ArrayList<>(); list.add("a"); list.add("b"); list.add("c"); boolean flag; boolean isFirstA = !list.isEmpty() && list.get(0).equals("a") boolean isSecondB = !list.isEmpty() && list.get(1).equals("b") boolean isThirdC = !list.isEmpty() && list.get(2).equals("c") if (isFirstA) { if (isSecondB) { if (isThirdC) { flag = true; } else { flag = false; } } else { flag = false; } } else { flag = false; } if (flag == true) { System.out.println("Success!!!"); } else { System.out.println("Failed!!!"); } }
  21. ͦ΋ͦ΋࣮͸͜ͷJGจ public static void main(String[] args) { List<String> list =

    new ArrayList<>(); list.add("a"); list.add("b"); list.add("c"); boolean flag; boolean isFirstA = !list.isEmpty() && list.get(0).equals("a") boolean isSecondB = !list.isEmpty() && list.get(1).equals("b") boolean isThirdC = !list.isEmpty() && list.get(2).equals("c") if (isFirstA) { if (isSecondB) { if (isThirdC) { flag = true; } else { flag = false; } } else { flag = false; } } else { flag = false; } if (flag == true) { System.out.println("Success!!!"); } else { System.out.println("Failed!!!"); } }
  22. ͍Βͳ͍ΜͩΑͶ public static void main(String[] args) { List<String> list =

    new ArrayList<>(); list.add("a"); list.add("b"); list.add("c"); boolean isFirstA = !list.isEmpty() && list.get(0).equals("a") boolean isSecondB = !list.isEmpty() && list.get(1).equals("b") boolean isThirdC = !list.isEmpty() && list.get(2).equals("c") boolean flag = isFirstA && isSecondB && isThirdC; if (flag == true) { System.out.println("Success!!!"); } else { System.out.println("Failed!!!"); } }
  23. CPPMFBOΛͰ൑ఆͯ͠Δ public static void main(String[] args) { List<String> list =

    new ArrayList<>(); list.add("a"); list.add("b"); list.add("c"); boolean isFirstA = !list.isEmpty() && list.get(0).equals("a") boolean isSecondB = !list.isEmpty() && list.get(1).equals("b") boolean isThirdC = !list.isEmpty() && list.get(2).equals("c") boolean flag = isFirstA && isSecondB && isThirdC; if (flag == true) { System.out.println("Success!!!"); } else { System.out.println("Failed!!!"); } }
  24. ৑௕ͳͷͰ GMBH Ͱ͍͍ public static void main(String[] args) { List<String>

    list = new ArrayList<>(); list.add("a"); list.add("b"); list.add("c"); boolean isFirstA = !list.isEmpty() && list.get(0).equals("a") boolean isSecondB = !list.isEmpty() && list.get(1).equals("b") boolean isThirdC = !list.isEmpty() && list.get(2).equals("c") boolean flag = isFirstA && isSecondB && isThirdC; if (flag) { System.out.println("Success!!!"); } else { System.out.println("Failed!!!"); } }
  25. ͦ΋ͦ΋͜ͷGMBH໊ͬͯલ public static void main(String[] args) { List<String> list =

    new ArrayList<>(); list.add("a"); list.add("b"); list.add("c"); boolean isFirstA = !list.isEmpty() && list.get(0).equals("a") boolean isSecondB = !list.isEmpty() && list.get(1).equals("b") boolean isThirdC = !list.isEmpty() && list.get(2).equals("c") boolean flag = isFirstA && isSecondB && isThirdC; if (flag) { System.out.println("Success!!!"); } else { System.out.println("Failed!!!"); } }
  26. ҙຯͷΘ͔Δ໊લΛ͚ͭΑ͏ public static void main(String[] args) { List<String> list =

    new ArrayList<>(); list.add("a"); list.add("b"); list.add("c"); boolean isFirstA = !list.isEmpty() && list.get(0).equals("a") boolean isSecondB = !list.isEmpty() && list.get(1).equals("b") boolean isThirdC = !list.isEmpty() && list.get(2).equals("c") boolean isABC = isFirstA && isSecondB && isThirdC; if (isABC) { System.out.println("Success!!!"); } else { System.out.println("Failed!!!"); } }
  27. Έ͘Β΂Δ

  28. CFGPSF public static void main(String[] args) { List<String> list =

    new ArrayList<>(); list.add("a"); list.add("b"); list.add("c"); boolean flag; if (list.isEmpty()) { flag = false; } else { if (list.get(0).equals("a")) { if (list.size() > 2) { if (list.get(1).equals("b")) { if (list.size() > 3) { if (list.get(2).equals("c")) { flag = true; } else { flag = false; } } else { flag = false; } } else { flag = false; } } else { flag = false; } } flag = false; } if (flag == true) { System.out.println("Success!!!"); } else { System.out.println("Failed!!!"); } }
  29. BGUFS public static void main(String[] args) { List<String> list =

    new ArrayList<>(); list.add("a"); list.add("b"); list.add("c"); boolean isFirstA = !list.isEmpty() && list.get(0).equals("a") boolean isSecondB = !list.isEmpty() && list.get(1).equals("b") boolean isThirdC = !list.isEmpty() && list.get(2).equals("c") boolean isABC = isFirstA && isSecondB && isThirdC; if (isABC) { System.out.println("Success!!!"); } else { System.out.println("Failed!!!"); } }
  30. ݁Ռ͸͔Θͬͯͳ͍͚Ͳ ͘͢͝Θ͔Γ΍͘͢ͳͬͨ

  31. Θ͔Γ΍͍͢ ʹ มߋ͠΍͍͢ όάΛ࡞Γʹ͍͘ ͸΍͘ॻ͚Δ

  32. ͔͍͍ͬ͜ϓϩάϥϚ ʹ ೉ͦ͠͏ͳίʔυΛॻ͘ʁ

  33. ͔͍͍ͬ͜ϓϩάϥϚ ʹ Θ͔Γ΍͍͢ίʔυΛॻ͘ʂ

  34. Θ͔Γ΍͍͢ίʔυΛॻ͜͏ʂ