You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by Kevin Brown <et...@apache.org> on 2008/02/18 04:14:56 UTC

Initial Java and javascript style guides.

Hi everyone,

I've drawn up some initial style guides based on the current code base as
well as some well-known best practices. I fully expect much debate over
these, so I suggest we hash out these differences on the mailing list and
then update the site accordingly.

Java: http://cwiki.apache.org/confluence/display/SHINDIGxSITE/Java+Style

javascript:
http://cwiki.apache.org/confluence/display/SHINDIGxSITE/Javascript+Style

-- 
~Kevin

If you received this email by mistake, please delete it, cancel your mail
account, destroy your hard drive, silence any witnesses, and burn down the
building that you're in.

Re: Initial Java and javascript style guides.

Posted by Kevin Brown <et...@google.com>.
On Feb 19, 2008 2:26 PM, Cassie <do...@google.com> wrote:

> Awesome Kevin!
>
> I just wanted to point out that right now our code doesn't follow this
> Java
> very well:


I know :) -- once we get consensus we'll go through and fix conformance
issues. I was looking at what the "most prevalent" usage was for now. My
main motivation for starting style discussions now was to avoid even more
inconsistency in the future.


>
>
> "Always use 2 space indents, unless you're wrapping a line in which case
> you
> should indent 4 spaces or indent to line up arguments. 4 space indentation
> is generally preferred, but line up arguments if it makes that bit of code
> more readable. Never use tabs."
>
> A lot of arguments are being lined up even when a 4 space indent would be
> "better". I prefer the 4 space indent as described in your doc but it
> might
> be good to just go one way or the other. "if it makes that bit of code
> more
> readable" is a little vague and can't be coded into an ide style guide.
>
>
> Also, at the very bottom of the js style guide it says this:
> "Alternative: Use array concatenation, or violate the 80-column rule if
> the
> string is only a little over the limit."
>
> I don't think we should advocate the breaking of our own style guides. Can
> we just take this bit out and address it on a case by case basis?


Sure. This was actually only there to account for some existing long
strings.


>
> Thanks.
>
> - Cassie
>
>
>
> On Tue, Feb 19, 2008 at 2:01 PM, Zhen Wang <zh...@apache.org> wrote:
>
> > Thanks for writing up the Wikis!
> >
> > A few things on the tip of my mind that could be added to the JS style
> > guide:
> >
> > * Use the || and && shortcuts liberally (e.g. z = x || y; even if x is
> > not a boolean value).
> > Avoid code verbosity such as:
> > if (x) {
> >  z = x;
> > } else {
> >  z = y;
> > }
> > or
> > z = x ? x : y;
> >
> > * Use strict equals (i.e. "===") to avoid type coercion.
> >
> > On Feb 17, 2008 7:14 PM, Kevin Brown <et...@apache.org> wrote:
> > > Hi everyone,
> > >
> > > I've drawn up some initial style guides based on the current code base
> > as
> > > well as some well-known best practices. I fully expect much debate
> over
> > > these, so I suggest we hash out these differences on the mailing list
> > and
> > > then update the site accordingly.
> > >
> > > Java:
> http://cwiki.apache.org/confluence/display/SHINDIGxSITE/Java+Style
> > >
> > > javascript:
> > >
> http://cwiki.apache.org/confluence/display/SHINDIGxSITE/Javascript+Style
> > >
> > > --
> > > ~Kevin
> > >
> > > If you received this email by mistake, please delete it, cancel your
> > mail
> > > account, destroy your hard drive, silence any witnesses, and burn down
> > the
> > > building that you're in.
> > >
> >
>



-- 
~Kevin

If you received this email by mistake, please delete it, cancel your mail
account, destroy your hard drive, silence any witnesses, and burn down the
building that you're in.

Re: Initial Java and javascript style guides.

Posted by Cassie <do...@google.com>.
Awesome Kevin!

I just wanted to point out that right now our code doesn't follow this Java
very well:

"Always use 2 space indents, unless you're wrapping a line in which case you
should indent 4 spaces or indent to line up arguments. 4 space indentation
is generally preferred, but line up arguments if it makes that bit of code
more readable. Never use tabs."

A lot of arguments are being lined up even when a 4 space indent would be
"better". I prefer the 4 space indent as described in your doc but it might
be good to just go one way or the other. "if it makes that bit of code more
readable" is a little vague and can't be coded into an ide style guide.


Also, at the very bottom of the js style guide it says this:
"Alternative: Use array concatenation, or violate the 80-column rule if the
string is only a little over the limit."

I don't think we should advocate the breaking of our own style guides. Can
we just take this bit out and address it on a case by case basis?

Thanks.

- Cassie



On Tue, Feb 19, 2008 at 2:01 PM, Zhen Wang <zh...@apache.org> wrote:

> Thanks for writing up the Wikis!
>
> A few things on the tip of my mind that could be added to the JS style
> guide:
>
> * Use the || and && shortcuts liberally (e.g. z = x || y; even if x is
> not a boolean value).
> Avoid code verbosity such as:
> if (x) {
>  z = x;
> } else {
>  z = y;
> }
> or
> z = x ? x : y;
>
> * Use strict equals (i.e. "===") to avoid type coercion.
>
> On Feb 17, 2008 7:14 PM, Kevin Brown <et...@apache.org> wrote:
> > Hi everyone,
> >
> > I've drawn up some initial style guides based on the current code base
> as
> > well as some well-known best practices. I fully expect much debate over
> > these, so I suggest we hash out these differences on the mailing list
> and
> > then update the site accordingly.
> >
> > Java: http://cwiki.apache.org/confluence/display/SHINDIGxSITE/Java+Style
> >
> > javascript:
> > http://cwiki.apache.org/confluence/display/SHINDIGxSITE/Javascript+Style
> >
> > --
> > ~Kevin
> >
> > If you received this email by mistake, please delete it, cancel your
> mail
> > account, destroy your hard drive, silence any witnesses, and burn down
> the
> > building that you're in.
> >
>

Re: Initial Java and javascript style guides.

Posted by Zhen Wang <zh...@apache.org>.
Thanks for writing up the Wikis!

A few things on the tip of my mind that could be added to the JS style guide:

* Use the || and && shortcuts liberally (e.g. z = x || y; even if x is
not a boolean value).
Avoid code verbosity such as:
if (x) {
  z = x;
} else {
  z = y;
}
or
z = x ? x : y;

* Use strict equals (i.e. "===") to avoid type coercion.

On Feb 17, 2008 7:14 PM, Kevin Brown <et...@apache.org> wrote:
> Hi everyone,
>
> I've drawn up some initial style guides based on the current code base as
> well as some well-known best practices. I fully expect much debate over
> these, so I suggest we hash out these differences on the mailing list and
> then update the site accordingly.
>
> Java: http://cwiki.apache.org/confluence/display/SHINDIGxSITE/Java+Style
>
> javascript:
> http://cwiki.apache.org/confluence/display/SHINDIGxSITE/Javascript+Style
>
> --
> ~Kevin
>
> If you received this email by mistake, please delete it, cancel your mail
> account, destroy your hard drive, silence any witnesses, and burn down the
> building that you're in.
>