473,395 Members | 1,616 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Javascript coding guidelines & conventions

Hi,

Found these coding guidelines for C#, HTML, Javascript, Java, HTML,
PL/SQL, T-SQL, VB and VBScript.

Well written and free to download.

www.demachina.com/products/swat

Jeroen

Jul 23 '05 #1
1 3822
ja***@xs4all.nl wrote:
Found these coding guidelines for C#, HTML, Javascript, Java, HTML,
PL/SQL, T-SQL, VB and VBScript.

Well written [...]


But still not good enough, e.g.:

| 2.4.5 Naming conventions
| [...]
| JavaScript supports the encapsulation of functions into classes.

Wrong. JavaScript before version 2.0 is an object-oriented programming
language that uses only _prototype-based inheritance_. Functions make
up Function objects that serve as constructors for objects when used as
operand of the `new' operator:

function Foo(x)
{
this.y = x;
}

var f = new Foo(42);

In JavaScript 2.0 which also provides class-based inheritance, but of
which currently only available a test implementation codenamed Epimetheus
is available, the `class' keyword is used to define classes, not the
`function' keyword:

<http://www.mozilla.org/js/language/js20/core/classes.html>

| Our standard is to prefix all member function definitions with
| the class name followed by an underscore as the following example
| will make clear:
|
| // Class definition, full comments omitted for clarity
| function CProducts
--------------------^
SyntaxError: missing ( before formal parameters

| {
| // ** Methods
| this.render = CProducts_Render;
| this.load = CProducts_Load;
| }
|
| function CProducts_Render()
| {
| ...
| }

This way of implementing methods counteracts proper object-oriented
programming style as the methods also become available as global methods.
Sometimes this is intended (e.g. for the purpose of backwards compatibility
to previous versions of a library that did not use OOP properly), however
here it obviously is not. Thus it is much better to write

function CProducts()
{
// ...
}

CProducts.prototype = {
render: function CProducts_Render()
{
...
}

// ...
};

here, or, if the prototype of CProducts should extend another prototype:

CProducts.prototype.render = function CProducts_Render()
{
...
};

| [...]
| 2.4.10 Including files
|
| Including JavaScript files is easy as this is supported by HTML.
| It will be no surprise that the syntax is:
|
| <SCRIPT LANGUAGE="JavaScript" SRC="javascript/library.js"></SCRIPT>

But it should be in fact a surprise to find that in a guideline for
commercial scripts since it is from deprecated to wrong. New projects
should use at least HTML 4.01 and in HTML 4 (and XHTML) the `type'
attribute is required for the `script' element while the `language'
attribute is deprecated (Transitional) or not even valid (Strict).

| 2.4.11 Clean up your objects
|
| Even though JavaScript has a built in garbage collector to reclaim
| resources from un-references objects and variables, it is good practive
| destroy your objects as soon as possible. This will result in a lower
| memory footprint in the customer's browser.
|
| The JavaScript syntax to dereference an object is
|
| objectName = null;

Wrong. JavaScript and Java have garbage collection for a good reason, that
is, an object may be referenced by more than one identifier. Assigning
`null' to an variable that previously referenced an object neither in Java
nor in ECMAScript, JScript or JavaScript forces the garbage collector to
destroy the referenced object; it is only destroyed if there is no further
reference to it *and* the garbage collection algorithm decides that it
should be destroyed. So using that statement does not reliably reduce the
memory footprint, instead it wastes computing time for the unnecessary
assignment.

| 2.4.12 Reading & writing configuration settings
|
| JavaScript in the browser can not directly access either the registry or a
| configuration database, therefore configuration settings need to be passed
| by JavaScript using ASP. [...]

Wrong. Even JScript in ASP can only access databases using a server-side
API, that is, in most cases, but not restricted to, that of the Internet
Information Server. So it is rather a question whether a client-side API
for the described processes is available which in turn depends on the
environment client-side scripts run; e.g. if running within a HyperText
Application (HTA), it is entirely possible to access the Registry via
objects of Windows Script Host using client-side JScript; the best example
for this is probably the Windows NT 5.0 (2k/XP) Control Panel where e.g.
the "Add/Remove Application" dialog is based on an HTA.

Furthermore, ASP is definitely not required server-side, there are
other platforms that enable one to perform the described processes.
I second many other recommendations of the Demachina Coding conventions &
guidelines (such as the indentation style), however it has to be pointed
out that it in its current form cannot be recommended as viable reference
material.
PointedEars
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Scott Meddows | last post by:
Does anyone know of a document that Microsoft produces that has the suggested coding standards for naming tables in a Database, fields in a database, objects in a VB project and so on? Maybe one...
4
by: Dotnetjunky | last post by:
Hi, So far, I've found tons of documents describing recommended coding standards for C#, but not a single piece on VB.NET yet. Anybody here knows such a coding standards guideline on VB.NET...
3
by: Dan Schaertel | last post by:
Does anybody have a good VB coding standards documnet? I need to generate one and I am looking for examples. Thanks email: dschaertel@hotmail.com
10
by: Ren | last post by:
Hi All, I'm still rather new at vb.net and would like to know the proper way to access private varibables in a class. Do I access the variable directly or do I use the public property? ...
60
by: Dave | last post by:
I'm never quite sure whether to use "this." or not when referring to fields or properties in the same class. It obviously works just fine without it but sometimes I wonder if using this....
27
by: Tom Cole | last post by:
I'm starting to do more quantity of javascript coding and thought this might be a good time to investigate code styling. I primarily develop in Java and currently use the code styling techniques...
26
by: Laurent Bugnion [MVP] | last post by:
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...
19
by: auratius | last post by:
http://www.auratius.co.za/CSharpCodingStandards.html Complete CSharp Coding Standards 1. Naming Conventions and Styles 2. Coding Practices 3. Project Settings and Project Structure 4....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.