TAB Posted December 29, 2014 Share Posted December 29, 2014 The tutorials should use strict syntax (as a model for those who learn by example). For example, infunction myFunction(p1, p2) { return p1 * p2; // the function returns the product of p1 and p2}the semicolon is useless. The novice who does not know that the semicolon is a separator (not a terminator) will be lead to believe that it is required after the last statement.Furthermore, the equivalent formfunction myFunction (p1, p2) {return p1*p2}//returns the product of p1 and p2is more compact AND more legible. Putting a single brace on the final line may be preferred by some (even though it gobbles editing-window space up), but it should not be used so systematically that the novice will think it is a syntactical requirement. Link to comment Share on other sites More sharing options...
Ingolme Posted December 29, 2014 Share Posted December 29, 2014 Having code on separate lines is more legible. It's a good practice to terminate all your lines with a semi-colon so that when you write a new line after it you don't forget it. If you want to get technical, Javascript will run just fine with no semi-colon on any of the lines. Link to comment Share on other sites More sharing options...
davej Posted December 29, 2014 Share Posted December 29, 2014 Vastly experienced people recommend using semi-colons, and compact code is rather pointless -- since you'll run the final code through a minifier anyway. Link to comment Share on other sites More sharing options...
justsomeguy Posted January 6, 2015 Share Posted January 6, 2015 but it should not be used so systematically that the novice will think it is a syntactical requirement.I'd much rather have the novice assume that well-indented code is a syntactical requirement versus assuming that single-line code is a syntactical requirement. This obviously assumes that the novice will assume that anything they see is a requirement, which is the assumption that you seem to make.Surely you aren't suggesting that something like this: function changeVideoQual(){ if(videoQuality == 'low'){videoQuality = 'high';$('#nav_quality').html('<i class="icon-cog"></i> low band')} else{videoQuality = 'low';$('#nav_quality').html('<i class="icon-cog"></i> high band')} if(runningIntro === true || atMenu){alert('Video Quality has been changed.')} else{replayPage()}}is more legible and maintainable than this: function changeVideoQual(){ if(videoQuality == 'low'){ videoQuality = 'high'; $('#nav_quality').html('<i class="icon-cog"></i> low band'); }else{ videoQuality = 'low'; $('#nav_quality').html('<i class="icon-cog"></i> high band'); } if(runningIntro === true || atMenu){ alert('Video Quality has been changed.'); }else{ replayPage(); }}If that's what you're suggesting, then you're probably the only one. Legibility is subjective, after all, and many programmers prefer the second style. It even has a name. Many programmers prefer K&R style.http://en.wikipedia.org/wiki/Indent_styleThe first form of "putting everything in a block on one line" doesn't have a name. 1 Link to comment Share on other sites More sharing options...
Snigery Posted April 21, 2015 Share Posted April 21, 2015 What exactly is this a critique of and why does this sound biased as an elitist practice? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now