Skip to content

Add the JerryScript Coding Standards #1459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 13, 2017

Conversation

zherczeg
Copy link
Member

No description provided.

```

All types, constants, and functions require a description in
JerryScript. These comments should start with /**. The starting
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The /**. and /** will make the string between them bold, so what you wanted to write disappears.
example: /. my text / in raw: /**. my text /**.
IMHO we should but such special characters in the description between backticks (`).

part of a comment should focus on explaing "why" rather than
"what".

```diff
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using "diff entries" as separator seems weird for me. Can't we just use a simple header style?


## Conditional preprocessor directives

A comment is required after #else and #endif in JerryScript.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO: #else and #endif should be between backticks so they will appear as inline code. (Also applies to keywords and any other code related pars in the descriptions)

@zherczeg zherczeg force-pushed the coding_guidelines branch 4 times, most recently from 4662b84 to ea0478e Compare November 29, 2016 10:46
@LaszloLango
Copy link
Contributor

LGTM

@zherczeg zherczeg force-pushed the coding_guidelines branch 2 times, most recently from c705b73 to 31e4639 Compare December 5, 2016 08:53
@zherczeg
Copy link
Member Author

zherczeg commented Dec 5, 2016

@LaszloLango added an extra section about expressions. Please check the patch again.

part of a comment should focus on explaing *why* rather than
*what*.

```diff
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not a simple header, like this?

Good

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not visible enough.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @galpeter, can't we have a standard header that is visible enough? E.g. change the color of the font?
Right now it seems you are using code blocks for the headers which seems suboptimal :)

Copy link

@tilmannOSG tilmannOSG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a first round of reviewing, thanks for taking the initiative on this!

@@ -0,0 +1,679 @@
# Coding style guidelines for the JerryScript project

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about changing this to "JerryScript Coding Standards" + changing the filename to "07.CODING-STANDARDS"? "Coding Standards" seems to be the most common term for this kind of document (vs. coding style guide, coding conventions, etc.).

@@ -0,0 +1,679 @@
# Coding style guidelines for the JerryScript project

This text is a brief overview of JerryScript coding style.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JerryScript coding style -> JerryScript Coding Standards


* Indentation is two spaces.
* Tab characters are not allowed.
* Maximum line length is 120 characters long (excluding newline).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-long

* Indentation is two spaces.
* Tab characters are not allowed.
* Maximum line length is 120 characters long (excluding newline).
* No trailing white spaces are allowed.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

white spaces are allowed -> white space is allowed

* Tab characters are not allowed.
* Maximum line length is 120 characters long (excluding newline).
* No trailing white spaces are allowed.
* Run `tools/run-tests.py --check-vera` to check majority of the style rules.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Majority seems a bit of a stretch :) How about "Run tools/run-tests.py --check-vera to check several of the coding conventions automatically."?


Each type in jerryscript must be a lowercase string
which is ended by `_t` characters. Furthermore each type
declaration must be preceeded by a short description

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preceeded -> preceded

Each type in jerryscript must be a lowercase string
which is ended by `_t` characters. Furthermore each type
declaration must be preceeded by a short description
about the type and each field must have a short description

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

about -> of


```c
/**
* Short description about the following structure.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

about -> of

typedef struct
{
/* Field descriptions do not start with capital letters
* and there is no full stops at the end. */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stops -> stop

## Function declarations

Function declarations in JerryScript are verbose but this format
reduces maintenance costs and allows faster understanding of the

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reduces maintenance costs -> reduces the maintenance cost

@zherczeg zherczeg force-pushed the coding_guidelines branch 4 times, most recently from 5ffd972 to e694af9 Compare December 6, 2016 12:32
Copy link

@tilmannOSG tilmannOSG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing my feedback :) Did a second round of reviewing.

is doing.

```diff
+++ Good +++

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you investigate better ways to format this with Markdown?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. According to several sources github markdown does not support colors. I wish to keep this format.


All types, constants and functions require a description in
JerryScript. These comments should start with `/**`. The starting
`/**` and ending `*/` must be in separate line.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in separate line -> on separate lines

## Preprocessor defines

The name of a preprocessor macro must be an uppercase string
and these macros must be preceeded by a description.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preceeded -> preceded

* Only a single newline separator is allowed.
* Source files must be terminated by a newline.
* Global declarations must be separated by a newline.
* Newlines are not allowed after an open brace or before a close brace.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

open brace or before a close brace -> opening curly brace or before a closing curly brace

* Source files must be terminated by a newline.
* Global declarations must be separated by a newline.
* Newlines are not allowed after an open brace or before a close brace.
* No newlines are allowed between control staments (if-else, while,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

staments -> statements

b,
c);
```

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function_c (a,
            b,
            c);

function_c (a,
            b,
            function_c (a,
                        b,
                        c);

Should be moved to the bad section :)


## Variable declarations

JerryScript requires C99 standard support so variable

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JerryScript requires C99 standard support -> JerryScript is a pure C99 codebase

* declarations. A reviewer might request such a change. */
int ***int_p;

/* This rule true for type casting as well. */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rule true for -> This rule applies for


## Types

Each type in jerryscript must be a lowercase string

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jerryscript -> JerryScript

## Types

Each type in jerryscript must be a lowercase string
which is which ends with a `_t` suffix. Furthermore

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the "which is".

@zherczeg zherczeg force-pushed the coding_guidelines branch 2 times, most recently from 28d8b1d to f302710 Compare December 12, 2016 07:54
@tilmannOSG tilmannOSG changed the title Add documentation about the Coding Guidelines Add the JerryScript Coding Standards Dec 12, 2016
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg [email protected]
@jiangzidong
Copy link
Contributor

What's the right style if a function call statement is exceed 120 limit. Only one actual parameter in the function
e.g.

ret_name = function_name (arg_name);

The above thing will happen if the names of ret, function and arg are too long.

@LaszloLango
Copy link
Contributor

I'd say that you should use shorter function and variable names. :) IMHO too long names are as bad as too short ones. But this is only my personal preference.

@zherczeg
Copy link
Member Author

Perhaps we should land this PR sometimes.

@LaszloLango
Copy link
Contributor

Still LGTM from my side.

@jiangzidong
Copy link
Contributor

LGTM

@yichoi
Copy link
Contributor

yichoi commented Apr 13, 2017

Do we need more discussion?

@zherczeg
Copy link
Member Author

I have no more to add.

@yichoi
Copy link
Contributor

yichoi commented Apr 13, 2017

Ok. Landing this. if needed, we can duscuss further.

@yichoi yichoi merged commit 239ae49 into jerryscript-project:master Apr 13, 2017
@zherczeg zherczeg deleted the coding_guidelines branch April 19, 2017 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants