Just A Summary : A quick Javascript formatting tip http://www.bofh.org.uk/articles/2008/04/16/a-quick-javascript-formatting-tip.rss en-us 40 Piers Cawley Practices Punditry Comment on A quick Javascript formatting tip by Philip Newton <p>That reminds me of a coding convention I&#8217;ve seen for Pascal, where &#8211; as in Perl &#8211; semicolon is used as a statement separator (rather than as a statement terminator, as &#8211; for example &#8211; in C).</p> <p>So one place put semicolons at the beginning of each line but the first, rather than at the end of each line but the last. (The latter would have been legal in most places, but it would have introduced an empty statement.)</p> Wed, 16 Apr 2008 07:34:16 -0500 urn:uuid:331a1249-6763-4495-9573-8d98cb07136f http://www.bofh.org.uk/articles/2008/04/16/a-quick-javascript-formatting-tip#comment-1391 Comment on A quick Javascript formatting tip by rhesa <p>reminds me a bit of <a href="http://perl.4pro.net/pcs.html" rel="nofollow">Perlish coding style</a> (<a href="http://www.perlmonks.org/?node_id=592616" rel="nofollow">mentioned briefly on PerlMonks</a> by brian d foy).</p> <p>Maybe it&#8217;ll grow on you, but I think it&#8217;s icky.</p> Wed, 16 Apr 2008 07:43:33 -0500 urn:uuid:b2174057-ce62-4811-a1a4-c33293d6d1ed http://www.bofh.org.uk/articles/2008/04/16/a-quick-javascript-formatting-tip#comment-1392 Comment on A quick Javascript formatting tip by nicholas a. evans I&#8217;ve been using the same trick when formatting my <span class="caps">SQL</span>. e.g: <pre>select a.foo as a_foo , b.bar as b_foo , c.blatz as c_foo from table1 a inner join table2 b on a.id = b.a_id left outer join table3 c on b.c_id = c.id where a.foo is not null and b.bacon = "chunky" </pre> ... using the same technique with the join operators and the boolean operators. I&#8217;ve found that it not only makes it easier to comment out a line or add a new line, but it also makes it easier (for me) to read than most other <span class="caps">SQL</span> formatting techniques. It&#8217;s still mildly annoying whenever you deal with the <strong>first</strong> item in the list though: you need to make sure to remove that leading join operator (comma, etc). If I&#8217;m editing the query a lot, I&#8217;ll add a &#8220;dummy&#8221; item to the front, just to alleviate that specific pain. e.g: <pre>where true and a.foo is not null and b.bacon = "chunky" </pre> <p>But I haven&#8217;t used this style as comprehensively as you have (&#8220;pretty much everywhere else that I’ve got a comma separated list of things&#8221;), or as the Perlish coding style&#8230; yet. :-)</p> Wed, 16 Apr 2008 15:40:51 -0500 urn:uuid:95f8eaff-d4e3-40a2-b161-dfa31afbec61 http://www.bofh.org.uk/articles/2008/04/16/a-quick-javascript-formatting-tip#comment-1393 Comment on A quick Javascript formatting tip by Piers Cawley <p>The &#8216;Perlish coding style&#8217; is definitely a misnomer and also barking mad. If you have leading punctuation on <em>every</em> line, then you start to lose the differences. If you keep your semicolons as statement terminators, then the presence of a <code>,</code> tells you that the new line is in some sense a continuation of the previous line. Same goes for things like:</p> <pre><code>clone[property] = YAHOO.lang.isObject(source[property]) ? deepCopy(source[property]) : source[property];</code></pre> <p>symbol on the first non-blank column? This line is a continuation of the previous one. Leading semicolons would break that rule.</p> <p>It&#8217;s definitely weird the first few times you see it, but it doesn&#8217;t take long before code that doesn&#8217;t follow this convention starts looking odd.</p> <p>Now, if I can just persuade Steve Yegge&#8217;s excellent js2-mode.el to get the indentation right first time when I&#8217;m writing javascript in this style&#8230;</p> Wed, 16 Apr 2008 16:21:48 -0500 urn:uuid:dc0b2d94-95cf-427c-8470-beddc81020e4 http://www.bofh.org.uk/articles/2008/04/16/a-quick-javascript-formatting-tip#comment-1394 Comment on A quick Javascript formatting tip by Asbjørn Ulsberg <p>I use this coding convention in <span class="caps">SQL</span>, because it&#8217;s possible to vertically align stuff so it looks neat, but with all other languages I think it just looks strange.</p> <p>I&#8217;ve tried to write code like that in every C-inspired language I&#8217;ve ever written, but it has never grown on me and it probably never will. I just don&#8217;t like it. :-)</p> Thu, 17 Apr 2008 03:35:58 -0500 urn:uuid:b4c86886-005e-45b6-b8be-26a54d4a857b http://www.bofh.org.uk/articles/2008/04/16/a-quick-javascript-formatting-tip#comment-1395 Comment on A quick Javascript formatting tip by Eric Suen <p>Hi, you should try <a href="http://www.spket.com" rel="nofollow">Spket <span class="caps">IDE</span></a>, Its JavaScript editor has an option &#8220;Report Unnecessary Trailing Comma&#8221;, and it has a very powerful JavaScript formatter which has an option &#8220;remove unnecessary trailing comma&#8221;...</p> Thu, 17 Apr 2008 09:49:55 -0500 urn:uuid:9b6f8128-b092-41c6-9ee9-619abc981be3 http://www.bofh.org.uk/articles/2008/04/16/a-quick-javascript-formatting-tip#comment-1396 Comment on A quick Javascript formatting tip by Brian Dillard <p>This convention was a lifesaver back in the days before there were any decent IE debugging tools I used it for years when I was a JavaScript soloist. But when I started working on large teams at Fortune 500 companies, everybody else freaked out on me about it and I had to stop. Luckily, I&#8217;m back to projects where I work on my own and can follow any coding convention I wish.</p> Thu, 17 Apr 2008 10:58:54 -0500 urn:uuid:8d630cb1-592e-4009-b75a-0e6fcc0bc2bf http://www.bofh.org.uk/articles/2008/04/16/a-quick-javascript-formatting-tip#comment-1397 Comment on A quick Javascript formatting tip by Piers Cawley <p>@Eric: Thanks, but I have 20 years of Emacs; I&#8217;m unlikely to go changing now.</p> <p>@Brian: Dang! So I&#8217;m not original. I&#8217;m still in the process of retraining my fingers.</p> Thu, 17 Apr 2008 11:36:23 -0500 urn:uuid:1badbc94-42ca-46d8-be6d-9d33025a2334 http://www.bofh.org.uk/articles/2008/04/16/a-quick-javascript-formatting-tip#comment-1398 Comment on A quick Javascript formatting tip by Bjorn <p>Can I just say&#8230; eeewwh! So instead of remembering a simple syntax rule, you make all your code look crappy? I&#8217;m guessing your indentation is equally &#8216;creative&#8217;... (thank goodness Python saves us from much random code vomit like this!)</p> Fri, 09 May 2008 03:16:18 -0500 urn:uuid:69cc958e-f083-40fd-9633-855c91d4cda6 http://www.bofh.org.uk/articles/2008/04/16/a-quick-javascript-formatting-tip#comment-1402 Comment on A quick Javascript formatting tip by Piers Cawley <p>Well, you can say it, but it does leave the rest of us to wonder what publicly insulting somebody&#8217;s taste (and <em>de gustibus non est disputandum</em> and all that) is supposed to contribute to a discussion.</p> <p>I suppose I should be grateful that you haven&#8217;t also inferred from my post that my momma wears army boots. Or maybe you did, but were too polite to mention it.</p> Sun, 11 May 2008 01:24:39 -0500 urn:uuid:d4d4ea8c-7c33-4e85-912e-d4e53f85c20e http://www.bofh.org.uk/articles/2008/04/16/a-quick-javascript-formatting-tip#comment-1404