Jump to content

Always put semicolons at the end of the line in javascript


I am Bored

Recommended Posts

After noticing that Firefox was using 25% CPU almost constantly with MD open (Opera uses 0-3%), I did a bit of digging. I noticed that updatetime was taking most of the time. Naturally, I went to look at the function. It has nothing that should be nearly that expensive. I then noticed by complete chance that there were no semicolons at the end of the line. Wondering if this could, for some absurd reason, be the cause, I promptly re-defined the functions to be semi-colon terminated. No sooner had I done that than the CPU usage (and absurd amount of memory allocation thrashing) disappeared. 

 

The morale of the story? Always terminate your statements in Javascript with semicolons, because, although it will still work in most browsers, you never know how a browser will handle it.

 

 

The pair of functions, with semicolons added:

function padlength(what){

    var output=(what.toString().length==1)? "0"+what : what;

    return output;

}



function displaytime(){

    serverdate.setSeconds(serverdate.getSeconds()+1);

    var datestring=montharray[serverdate.getMonth()]+" "+padlength(serverdate.getDate()); //+", "+serverdate.getFullYear()

    var timestring=padlength(serverdate.getHours())+":"+padlength(serverdate.getMinutes())+":"+padlength(serverdate.getSeconds());

    document.getElementById("servertime").innerHTML=datestring+" "+timestring;//datestring+" "+

}
Link to comment
Share on other sites

  • Root Admin

Im unconvinced that this is the issue. Semi colons at the end of a line is not required in javascript as it will tokenize the newline.

I think your combined efforts of hacking around MD has finally got to your browser. I have told you bored that if you are modifying MD I dont want your reports because then you are running some custom thing that I cannot debug.

I will eventually get around to cleaning that up but I think there is no evidence to say it has any effect on CPU time.

Link to comment
Share on other sites

I think your combined efforts of hacking around MD has finally got to your browser. I have told you bored that if you are modifying MD I dont want your reports because then you are running some custom thing that I cannot debug.

This is just mean and you know it. We all know that MD is filled with bugs. Lets see how IaB explains / prove it.

 

I too have some issues with MD. When it is running too long I have to refresh the page to make it run smoother.

But I've always attributed this to the flash usage.

Link to comment
Share on other sites

  • Root Admin

This is just mean and you know it. We all know that MD is filled with bugs. Lets see how IaB explains / prove it.
 
I too have some issues with MD. When it is running too long I have to refresh the page to make it run smoother.
But I've always attributed this to the flash usage.


We are talking about it on yim, he has been bombarding me with him hacking apart MD.

If we can see some stats, I will implement the changes sooner than planned, but I dont see any reason for it to make a difference due to how it works.

also: https://www.youtube.com/watch?v=WGoi1MSGu64
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Forum Statistics

    17.5k
    Total Topics
    182.5k
    Total Posts
  • Recently Browsing

    • No registered users viewing this page.
  • Upcoming Events

    No upcoming events found
  • Recent Event Reviews

×
×
  • Create New...