Wednesday, February 22, 2017

Just Don't Write Ambigous Code

I've stopped putting semicolons in my javascript, at least for my own projects. It makes code so much easier to read. But wait?  Don't we need semicolons in cases where the code is ambigous?

Sure. But why write ambigous code? Unless you are competing to write the longest one line program, there is no point.

If I need a semicolon to make my javascript work, then my code isn't clear. And when I come back to it in 6 months, I'm going to be Say What? Semicolons are like a yellow flag saying 'Why are you doing it this way'.

Actually, like nost best practices, the real best practice is don't blindly follow the best practice, instead you should think.

There are actually some places I still use a semicolon. For loops for one. And switches:


switch(op) {
 case 0: doZero(); break
 case 1: doOne(); break
...

And of course, if maintaining existing code where the style guide calls for semicolons, please respect it.

Here is an actually informative posting on the subject: http://mislav.net/2010/05/semicolons/

9 comments:

  1. Pleasant to visit your site page once more, it has been months for me. Well this article i have been sat tight for so long. I require this piece to finish my task in school, and it has same theme with your piece. Much appreciated, incredible offer… .
    essay writing service reviews

    ReplyDelete
  2. A typical day on the job varies dramatically depending on the size of the organization and the scope of the position. Assignment Help

    ReplyDelete
  3. It is a compacted arrangement and does not consume up much room. writable-pdf

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Good to read such an informative post. I find it interesting and is pretty fascinating, By reading your post I got very useful information. Thanks for sharing this post. Keep posting more content like this, it is a very nice blog. I recommend you to visit https://www.ace4sure.com/Avaya-exams.html

    ReplyDelete
  6. Thanks for highlighting the importance of using clear and descriptive variable names, which I think is often overlooked in a rush to get code written quickly. It's so important to take the time to choose names that accurately reflect the purpose of the variable or function, as it can make a huge difference in how easily others can understand and work with the code. Dissertation Help Online

    ReplyDelete
  7. When discussing coding practices, clarity is key. Ambiguous code can lead to confusion and errors. Similarly, for those seeking structured support, order dissertation online can provide valuable assistance.

    ReplyDelete
  8. I really enjoyed reading your post about writing unclear code; it's such an important but often overlooked aspect of programming! Ambiguous code, like an aviator's jacket, can look nice at first, but it can be a pain to deal with later. It can be tempting to leave things open-ended for the sake of brevity, but clarity should always come first. Thank you for your observations; I will surely think again before going too creative with my code.

    ReplyDelete