Advertisement
CodingComputing

In the age of AI, is writing clean code worth it? Essay by @CodingComputing

Dec 26th, 2022 (edited)
462
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.57 KB | Software | 0 0
  1. In the age of AI, is writing clean code worth it?
  2. =================================================
  3.  
  4. Author:@CodingComputing Word Count: 923
  5.  
  6. ---
  7.  
  8. Artificial Intelligence (AI) is transforming all walks of life today,
  9. and the field of software development is also feeling this wave of
  10. change; AI is now able to assist in writing code. A valued skill in
  11. software development is to write clean code: code that is easily
  12. understandable and maintainable. Such developments in AI lead to a
  13. question, that, if AI assists in writing code, does it make clean code
  14. obsolete? In this essay, I explore the ways in which AI can help in
  15. coding, and argue that writing clean code is very much a necessity, in
  16. spite of AI assisting us in coding.
  17.  
  18.  
  19. Let us take a closer look at some characteristics of AI, and of clean
  20. code.
  21.  
  22. ChatGPT, a recently developed AI system, has demonstrated capabilities
  23. of producing code, commenting on code, and even explaining the working
  24. of certain code snippets. Although it is capable of remarkable feats, AI
  25. is limited in certain respects. The limitations are:
  26. 1. it does not have real-life experiences,
  27. 2. it does not have a fundamental understanding of the world. Due to
  28. these limitations, it can only process its training data, and
  29. synthesize it as per the input request.
  30.  
  31. Clean coding is about understanding and following certain principles,
  32. that make the code easier to read and maintain. The principles include
  33. practices such as factoring code appropriately, and using correct
  34. indentation. Writing clean code takes time, effort, and discipline.
  35. Developers often shy away writing clean code, and ultimately pay the
  36. price of dealing with bad code [1].
  37.  
  38. The question we are trying to address is: Now that AI can assist in
  39. writing code, do human developers still need to learn and follow the
  40. principles of clean code?
  41.  
  42. Let us examine in what way AI can assist in writing code. Primarily, AI
  43. can help with the following tasks, which might raise the question of
  44. relevance of clean code:
  45. 1. Producing code from a given prompt
  46. 2. Explaining what certain pieces of code do
  47.  
  48. Let us now explore some objections against clean code that can arise
  49. from the above points, and address the objections.
  50.  
  51.  
  52. 1) AI can produce code for us
  53. -----------------------------
  54.  
  55. Some might think that if AI can produce code for us, human developers
  56. need not learn and practice the principles of clean code. However, there
  57. are two points as counter-arguments to this:
  58.  
  59. 1. AI's results are only as good as the training data it gets. It can
  60. produce low-quality code that has bugs. The code may appear to be all
  61. right in spite of being wrong [2]. This will make it hard for humans
  62. to debug and maintain such code. It is a common observation that it
  63. is harder to debug and maintain code that someone else has written,
  64. compared to code that you wrote by yourself.
  65.  
  66. 2. Programming is a creative process. At a very basic level, a
  67. programmer has to understand the requirements of a real-world
  68. problem, and develop a solution based on their understanding of the
  69. underlying mathematics, algorithms, and domain-specific experience.
  70. Since AI has no inherent understanding of any of these, it cannot be
  71. expected to produce programs on novel problems. At best it can mimic
  72. some solutions from its training data.
  73.  
  74. The above two points imply that although AI can produce code, it is
  75. still not at a stage where it can produce code that is guaranteed to
  76. work. Therefore, human intervention is required at some stage.
  77.  
  78. Coding is about understanding a problem and implementing it in software.
  79. It will have to continue to be done by humans for some time to come.
  80. Clean coding remains important as long as humans have to deal with code.
  81.  
  82.  
  83. 2) AI can explain what any code does
  84. ------------------------------------
  85.  
  86. Some others might think that if AI can explain what any piece of code
  87. does, why should a human bother with writing clean code? Whatever is not
  88. understood, can be explained by the AI.
  89.  
  90. The point to understand here is that AI is fundamentally ignorant of the
  91. purpose of the program.
  92.  
  93. AI can perhaps describe what a piece of code does. However,
  94. understanding code is not limited to understanding only *what* the code
  95. does. To really understand the code, it is important to grasp the intent
  96. of the programmer. It is necessary to understand *why* a programmer
  97. wrote the code that way. What logic has he implemented?
  98.  
  99. In the clean code paradigm, the answers to these questions are
  100. communicated by means of properly named objects, and by comments. The
  101. code is written such that it is clear to the reader what the intent of
  102. the programmer was.
  103.  
  104. Therefore, even if AI can explain what any piece of code does, a
  105. programmer can understand the code better if the code is written well.
  106.  
  107. It is essential to understand the logic behind a program. That is what
  108. helps to effectively debug, test, and maintain the code in question.
  109. clean code can do that better for us than AI can.
  110.  
  111.  
  112. Conclusion
  113. ----------
  114.  
  115. Clean code communicates the logic of the program, and that is what helps
  116. understand and maintain the code. AI is, as of now, not able to produce
  117. perfectly working code, nor is it able to understand the programmer's
  118. intent. Thus, in spite of the ability of AI to help us with programming,
  119. it is still essential for developers to learn writing clean code.
  120.  
  121.  
  122. ---
  123.  
  124.  
  125. References
  126. ----------
  127.  
  128. [1] Robert C. Martin, *Clean Code*
  129.  
  130. [2] Rodrigo (Twitter:@mathsppblog), *Running Python inside ChatGPT*.
  131. Online: https://mathspp.com/blog/running-python-inside-chatgpt
  132.  
Advertisement
Comments
  • Themadhatter1999
    364 days
    # text 0.16 KB | 0 0
    1. Your essay is spot on regarding A.I. it simply can't do everything. Even though everyone likes to assume it can be used on any subject. I'd prefer human written code.
Add Comment
Please, Sign In to add comment
Advertisement