Sunday, December 31, 2017

JavaScript: Style

One of the most important things to remember when writing code is style. Style, in comparison to the real world is simply making the program better and easier to read. Although it can be a small part in the code and how it executes, it makes a huge difference in how the programmer/computer can read and interpret it. There can be many types of styles depending on the programmer, with no true "correct" form. Learning how to properly style your code can be extremely confusing and difficult, but is necessary for successful coding.

Because I am new to programming, this can be one of the most difficult things for me to master and  learn. I often made minute mistakes that cost me quite a bit of time. "Code that appears to mean one thing but actually means another is likely to cause bugs" (Crockford 96). I practiced on SoloLearn and tried to find and fix some of my errors, and see if any of them had a "hidden function" that would interfere with the function I wanted it to run.


Original Code with error
Error code's real output
While searching for errors, I found one of my errors, as the original code on the right was programmed incorrectly, and resulted in the one on the left. It was because I put the brace symbol "}" in the wrong spot, causing the program to misunderstand what you were writing. This can often be confusing, because in JavaScript, the way you write code is extremely important, and even a seemingly insignificant mishap can detract from the code's function.

Style is nearly everything you write in the program to make it easier to read, which includes comments. Code in the form of comments, or lines with two backslashes in front can give readers more information on the program, such as what the programmer was thinking or leaving important to-do messages (Crockford 96). In my code, I often use comments such as these to help me remember what I did with the code, or its functions. As a new programmer, it can be confusing for me to look back and remember what I was thinking/doing. These have helped me greatly, since I am busy with things other than coding, and I spread my programming time over a large period to prioritize other tasks. I often forget my thoughts during the coding session, especially after being away for long periods of time. Comments, however, refresh my memory, so using them can set me on track to finish my code.
Creating a comment in green

Comments do not affect the code, but they can be part of the backbone of the code, since they are there solely for the purpose of clarification. Making effective and useful comments can greatly improve how easily the program can be understood by programmers, and thus play a large part in the code's style.

Through my trial and error, I have learned more about how to style my code to make it as easy as possible for the machine to understand what I am inputting. It may not seem important at first, but as you start creating more advanced programs, it becomes clear how crucial it is to have proper style and formatting.

Question: How does style play a role in your life? Does the way you perform your tasks or work affect its outcome? 
Works Cited:
Crockford, Douglas. JavaScript: The Good Parts. O'Reilly Media, Inc., 2008.


3 comments:

  1. Hi William! Often, when I'm programming, I have a problem with something, so I'll look up some solutions others may have had to the problem. When I do this, I encounter a lot of code from other people in different formatting. At first this was confusing, but different people tend to prefer organizing the code in different ways that make more sense to them. I have to be able to understand any possible coding styles out there in order to understand it myself to learn from it. It is interesting to see so much variety though!

    ReplyDelete
    Replies
    1. Thank you for reading my post Josh! When I have trouble with programming, I also go to other programmers and see what they have done differently, and learn from my own mistakes. As for the formatting and variations of coding, I believe that it is what makes programming so unique, allowing each individual to express themselves in an infinite amount of ways.

      Delete
  2. This comment has been removed by the author.

    ReplyDelete