Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > JavaScript guidelines published

Reply
Thread Tools

JavaScript guidelines published

 
 
Laurent Bugnion [MVP]
Guest
Posts: n/a
 
      02-05-2007
Hi group,

In agreement with the head of our R&D department, I published my firm's
JavaScript Coding Guidelines. I work for Siemens Building Technologies.
We developed these guidelines for a web application project in 2004,
based on our C# guidelines.

http://www.galasoft-lb.ch/myjavascri...Guidelines.pdf

Please note the following:

* The purpose of publishing this document on the World Wide Web is to
promote and encourage consistent practices in the JavaScript programming
community.

* We publish this document as information only. Siemens will not accept
any responsibility regarding its content.

* The guidelines are recommendations based on our experience, and may or
may not make sense in the context of a different company, or a different
project. Their intent is to be a source of inspiration for other
JavaScript developers, and nothing more.

* The guidelines are dated 20th of April 2004, which is quite some time
ago. I think that most of the recommendations are still valid, but of
course additions can be made.

HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
 
Reply With Quote
 
 
 
 
Matt Kruse
Guest
Posts: n/a
 
      02-05-2007
Laurent Bugnion [MVP] wrote:
> In agreement with the head of our R&D department, I published my
> firm's JavaScript Coding Guidelines.


Fantastic!
Although I don't agreement with all of the conventions, I think that
publishing documents like this could give someone a good place to start from
in trying to make their coding more consistent, and in the end that will be
nothing but positive. Thank you for sharing.

Do you use any tool to check that js source files adhere to these standards?
What positive impact has this document had in your work environment - do
people follow it? Is it enforced? Was there any push back against it?

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com


 
Reply With Quote
 
 
 
 
Laurent Bugnion [MVP]
Guest
Posts: n/a
 
      02-05-2007
Matt,

Matt Kruse wrote:
> Laurent Bugnion [MVP] wrote:
>> In agreement with the head of our R&D department, I published my
>> firm's JavaScript Coding Guidelines.

>
> Fantastic!
> Although I don't agreement with all of the conventions, I think that
> publishing documents like this could give someone a good place to start from
> in trying to make their coding more consistent, and in the end that will be
> nothing but positive. Thank you for sharing.


To be honest, I also don't agree with all of them (though I strictly
adhere to them in my job, and use my own set in my private projects).
Guidelines like this are a teamwork, and sometimes we had to compromise.


> Do you use any tool to check that js source files adhere to these standards?


We don't, but we used code reviews, where one of the criteria tested was
the enforcement of these guidelines.

> What positive impact has this document had in your work environment - do
> people follow it?


Yes, very much so. In fact, the situation was relatively easy, because
most of my coworkers didn't have much (if any) experience with
JavaScript, so they kind of believed me when I told them that this was
the way to go Seriously, the people I worked with (and coordinated)
in that project did an excellent job. For the records, the application
is an ASP.NET web application used for building automation. The server
part relies on an existing unmanaged C++ product which we extended with
..NET code. We rely on .NET remoting for communication between the web
server and the C++ server, and make quite intensive use of web services
between the client and the web server. We already had the web
application up and running for more than 2 weeks in intensive test
conditions without any trouble. We wrote about 15000 lines of code (not
counting generated code, for which we wrote a JavaScript cross compiler).

The development time was about 1.5 years

> Is it enforced? Was there any push back against it?


No push back. All the developers are professionals with many years
experience in other languages (C++, Java, C# mostly) and all of them
understand the value of guidelines.

Greetings,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
 
Reply With Quote
 
-Lost
Guest
Posts: n/a
 
      02-05-2007
"Laurent Bugnion [MVP]" <(E-Mail Removed)> wrote in message
news:45c74b36$(E-Mail Removed)...
> Hi group,
>
> In agreement with the head of our R&D department, I published my firm's JavaScript
> Coding Guidelines. I work for Siemens Building Technologies. We developed these
> guidelines for a web application project in 2004, based on our C# guidelines.
>
> http://www.galasoft-lb.ch/myjavascri...Guidelines.pdf


Awesome! This has been a long time coming and quite frankly I am glad to see it.

Thanks, Laurent.

-Lost


 
Reply With Quote
 
-Lost
Guest
Posts: n/a
 
      02-05-2007
"Matt Kruse" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Laurent Bugnion [MVP] wrote:
>> In agreement with the head of our R&D department, I published my
>> firm's JavaScript Coding Guidelines.

>
> Fantastic!
> Although I don't agreement with all of the conventions, I think that publishing
> documents like this could give someone a good place to start from in trying to make
> their coding more consistent, and in the end that will be nothing but positive. Thank
> you for sharing.


Really? What conventions do you not agree with and why?

I would love to keep a running tally of all the amendments "the JavaScript gurus" like
yourself, <and you know who you are guys>, think should be modified in this document.

I would be glad to publish the revisions in whatever format was deemed acceptable
(assuming Laurent does not have the time to update it himself). I figured it could be a
separate project unto the Siemens guidelines.

-Lost


 
Reply With Quote
 
Dr J R Stockton
Guest
Posts: n/a
 
      02-05-2007
In comp.lang.javascript message <45c74b36$(E-Mail Removed)>, Mon, 5
Feb 2007 16:20:17, "Laurent Bugnion [MVP]" <(E-Mail Removed)>
posted:
>
>In agreement with the head of our R&D department, I published my firm's
>JavaScript Coding Guidelines. I work for Siemens Building Technologies.
>We developed these guidelines for a web application project in 2004,
>based on our C# guidelines.


Good, largely. But :-

Does Siemens not use ISO 8601 date format? "08.11.2004" is a form not
commonly used in English, either.

3-101, 4-103 are bad choices <g>.

3-204 - that's nothing : in Pascal one can do
const true = false ; false = not true ;

4-101 - often disregarded elsewhere. I suggest that each file should
also have a trailer block, as a guard against accidental incomplete
copies. "// End" would suffice.

4-102 - The meaning is clear, and good; but the statement is defective.

11-203 - How about continuation lines (where FORTRAN would use a C)?

Especially for the benefit of those using slow links, ISTM worth
indicating size by a link to a PDF. Some PDFs are big!. Yours is 70kB.


Could/should the document be cited in the newsgroup FAQ?

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.merlyn.demon.co.uk/clpb-faq.txt> RAH Prins : c.l.p.b mFAQ;
<URL:ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.
 
Reply With Quote
 
Matt Kruse
Guest
Posts: n/a
 
      02-05-2007
-Lost wrote:
> Really? What conventions do you not agree with and why?


As a doc specifically for their project, I can't comment. But if this doc
were to be morphed into a more general document, I would make the following
observations:

- "new Object()" in code should be discouraged but it's in an example in
2.2.3

- alert(), confirm(), and prompt() have their place and shouldn't
necessarily be avoided in production code

- Prefixing variable names to indicate type is Old School, and is
questionable in a non-typed language like JS.

- Use XML tags for documenting? I would prefer jsdoc syntax.

- Combining variable declaration shouldn't be avoided.

- The comment in 5.2.1 of "A variable ought to be declared within the
smallest possible scope to improve the readability of the code and so that
variables are not unnecessarily allocated" seems misguided. A "var i",
whether at the beginning of a function or declared in a for loop, will still
be allocated:
function() {
var i;
if (false) {
for (var j=0; j<10; j++) { alert('unreachable'); }
}
alert(i);
alert(j);
alert(k);
}
Although I often 'var' variables close to where they are used, it would
probably be a better recommendation to declare them at the top of functions.

In general, it's not a bad place to start and a group would be better off
with these conventions than none, IMO. But much could be added to this doc
that would be more practical than variable naming conventions, for example.
I intended to extend my own "Best Practices" document at some point to
include more syntax suggestions like those found in this doc, so this may be
a good starting point.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com


 
Reply With Quote
 
VK
Guest
Posts: n/a
 
      02-05-2007
On Feb 5, 6:20 pm, "Laurent Bugnion [MVP]" <(E-Mail Removed)>
wrote:
> Hi group,
>
> In agreement with the head of our R&D department, I published my firm's
> JavaScript Coding Guidelines. I work for Siemens Building Technologies.
> We developed these guidelines for a web application project in 2004,
> based on our C# guidelines.
>
> <http://www.galasoft-lb.ch/myjavascript/Siemens_SBT_JavaScript_Coding_Guidelines.pdf>


Thanks for that.

 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      02-06-2007
On Feb 6, 1:20 am, "Laurent Bugnion [MVP]" <(E-Mail Removed)>
wrote:
> Hi group,
>
> In agreement with the head of our R&D department, I published my firm's
> JavaScript Coding Guidelines. I work for Siemens Building Technologies.
> We developed these guidelines for a web application project in 2004,
> based on our C# guidelines.
>
> http://www.galasoft-lb.ch/myjavascri...Script_Coding_...


As others have said, a very good start. Of course I have some
personal dislikes here and there but none worth arguing over.

Chapter 6 Flow Control references another document that isn't
provided. Any chance you can make that available too?


--
Rob

 
Reply With Quote
 
Douglas Crockford
Guest
Posts: n/a
 
      02-06-2007
Laurent Bugnion [MVP] wrote:
> Hi group,
>
> In agreement with the head of our R&D department, I published my firm's
> JavaScript Coding Guidelines. I work for Siemens Building Technologies.
> We developed these guidelines for a web application project in 2004,
> based on our C# guidelines.
>
> http://www.galasoft-lb.ch/myjavascri...Guidelines.pdf


5.2.1 Rec. 5-101 Declare and initialize variables close to where they are used.

This would be good advice for languages with block scope. JavaScript does not
have block scope, only function scope, so the recommendation should be to
declare variables at the beginning of the function.

Also see http://javascript.crockford.com/code.html
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I would like to create a vertical cascading menu using javascript and css - looking for guidelines Terry Javascript 14 10-05-2007 12:57 PM
JavaScript guidelines published Laurent Bugnion [MVP] ASP .Net 5 02-06-2007 05:29 AM
Case Gallery rules and Guidelines Silverstrand Case Modding 0 06-20-2005 11:38 PM
Javascript coding guidelines & conventions jarit@xs4all.nl Javascript 1 05-28-2005 04:49 PM
Javascript coding guidelines & conventions jarit@xs4all.nl Javascript 0 05-22-2005 01:13 AM



Advertisments