Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > ruby indentantion

Reply
Thread Tools

ruby indentantion

 
 
Alfonso
Guest
Posts: n/a
 
      11-14-2006
I have just started with ruby, and something that I have observed is
that most of the code is indented with 2 spaces. Having programmed some
time with C# and python, it's very strange to me so few identation. To
me 4 spaces is much better to read. Is there something like a style
guide in ruby that says that you should use 2 spaces or is it all right
using 4 or 3 spaces? What do you use in your code?

Thank you for your answers


______________________________________________
LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y móviles desde 1 céntimo por minuto.
http://es.voice.yahoo.com

 
Reply With Quote
 
 
 
 
Robert Spielmann
Guest
Posts: n/a
 
      11-14-2006
--=-0FaM8XbQ0qfMm8ZFnp2O
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

Am Mittwoch, den 15.11.2006, 00:39 +0900 schrieb Alfonso:
> I have just started with ruby, and something that I have observed is=20
> that most of the code is indented with 2 spaces. Having programmed some=20
> time with C# and python, it's very strange to me so few identation. To=20
> me 4 spaces is much better to read. Is there something like a style=20
> guide in ruby that says that you should use 2 spaces or is it all right=20
> using 4 or 3 spaces? What do you use in your code?
>=20


Hi Alfonso,

indentation with 2 spaces is a non-written standard in Ruby. I use 2
spaces.

Regards,
Robert

--=20
Robert Spielmann

Codecentric GmbH
http://www.codecentric.de


--=-0FaM8XbQ0qfMm8ZFnp2O
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: Dies ist ein digital signierter Nachrichtenteil

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

iD8DBQBFWeO/PekiMvb4uacRAs1lAKCvsvulaBpBtBZio+DGjR1OAwLdPwCgju sL
J21nMne7wSb9ehwmUr6vXAs=
=2Qmw
-----END PGP SIGNATURE-----

--=-0FaM8XbQ0qfMm8ZFnp2O--

 
Reply With Quote
 
 
 
 
Brad Tilley
Guest
Posts: n/a
 
      11-14-2006
Quoting Alfonso <>:

> I have just started with ruby, and something that I have observed is
> that most of the code is indented with 2 spaces. Having programmed some
> time with C# and python, it's very strange to me so few identation. To
> me 4 spaces is much better to read.


I use 2, 3 and 4 depending on who I'm working with an what I'm working on. I
think readability studies have shown that 4 is the best for most people, but
some companies (like Google I believe) have style guides that require 2.

 
Reply With Quote
 
Patrick Spence
Guest
Posts: n/a
 
      11-14-2006
I'd say it's mostly a personal preference thing. I started using
2-spaces when I started coding in Clipper many years ago.


 
Reply With Quote
 
dblack@wobblini.net
Guest
Posts: n/a
 
      11-14-2006
Hi --

On Wed, 15 Nov 2006, Alfonso wrote:

> I have just started with ruby, and something that I have observed is that
> most of the code is indented with 2 spaces. Having programmed some time with
> C# and python, it's very strange to me so few identation. To me 4 spaces is
> much better to read. Is there something like a style guide in ruby that says
> that you should use 2 spaces or is it all right using 4 or 3 spaces? What do
> you use in your code?


I use 2 spaces, which is the Ruby tradition and custom. I don't think
there's anything in the standard library that does otherwise.
Whatever language I'm using, I don't like to have my code look like
David Black code, but rather like anonymous, standard, boring code
that uses the most common stylistic conventions for that language. If
you're more into making a statement about your own sense of style, you
can indent more


David

--
David A. Black |
Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3]
DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4]
[1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com
[2] http://dablog.rubypal.com | [4] http://www.rubycentral.org

 
Reply With Quote
 
Trans
Guest
Posts: n/a
 
      11-14-2006

Alfonso wrote:
> I have just started with ruby, and something that I have observed is
> that most of the code is indented with 2 spaces. Having programmed some
> time with C# and python, it's very strange to me so few identation. To
> me 4 spaces is much better to read. Is there something like a style
> guide in ruby that says that you should use 2 spaces or is it all right
> using 4 or 3 spaces? What do you use in your code?


This is just an guestimation but I think Ruby went 2-space because the
most common keyword that takes a block is only three letters long:
'def'. So any more than 2 spaces of indention and you're past the end
of that word, which makes it look a little off kilter.

T.

 
Reply With Quote
 
Morton Goldberg
Guest
Posts: n/a
 
      11-14-2006
On Nov 14, 2006, at 10:39 AM, Alfonso wrote:

> I have just started with ruby, and something that I have observed
> is that most of the code is indented with 2 spaces. Having
> programmed some time with C# and python, it's very strange to me so
> few identation. To me 4 spaces is much better to read. Is there
> something like a style guide in ruby that says that you should use
> 2 spaces or is it all right using 4 or 3 spaces? What do you use in
> your code?


Use whatever indentation looks right to you, and don't let anyone
bully you into doing it otherwise. I indent by three spaces and don't
intend to change.

Regards, Morton

 
Reply With Quote
 
James Edward Gray II
Guest
Posts: n/a
 
      11-14-2006
On Nov 14, 2006, at 1:13 PM, Morton Goldberg wrote:

> On Nov 14, 2006, at 10:39 AM, Alfonso wrote:
>
>> I have just started with ruby, and something that I have observed
>> is that most of the code is indented with 2 spaces. Having
>> programmed some time with C# and python, it's very strange to me
>> so few identation. To me 4 spaces is much better to read. Is there
>> something like a style guide in ruby that says that you should use
>> 2 spaces or is it all right using 4 or 3 spaces? What do you use
>> in your code?

>
> Use whatever indentation looks right to you, and don't let anyone
> bully you into doing it otherwise. I indent by three spaces and
> don't intend to change.


At the risk of being labeled a bully, "When in Rome..."

James I-Use-To-Use-Four-Spaces Gray


 
Reply With Quote
 
Brad Tilley
Guest
Posts: n/a
 
      11-14-2006
Quoting Morton Goldberg <>:

> Use whatever indentation looks right to you, and don't let anyone
> bully you into doing it otherwise. I indent by three spaces and don't
> intend to change.


I agree. Use what you like on your personal projects and of course follow your
company's indentation policies when coding at work. I think this is common.
I've heard that Guido Van Rossum (of Python fame) indents 4 spaces for his own
personal programs and 2 spaces when coding for Google.

Best of luck,
Brad

 
Reply With Quote
 
dblack@wobblini.net
Guest
Posts: n/a
 
      11-14-2006
Hi --

On Wed, 15 Nov 2006, James Edward Gray II wrote:

> On Nov 14, 2006, at 1:13 PM, Morton Goldberg wrote:
>
>> On Nov 14, 2006, at 10:39 AM, Alfonso wrote:
>>
>>> I have just started with ruby, and something that I have observed is that
>>> most of the code is indented with 2 spaces. Having programmed some time
>>> with C# and python, it's very strange to me so few identation. To me 4
>>> spaces is much better to read. Is there something like a style guide in
>>> ruby that says that you should use 2 spaces or is it all right using 4 or
>>> 3 spaces? What do you use in your code?

>>
>> Use whatever indentation looks right to you, and don't let anyone bully you
>> into doing it otherwise. I indent by three spaces and don't intend to
>> change.

>
> At the risk of being labeled a bully, "When in Rome..."


That's what it's really about: that there is a traditional coding
style -- a "Rome". I think it's useful for it to be mentioned, not so
that no one ever deviates from it, but so that people who prefer to
use a language's traditional style will know that Ruby has one. That
sometimes gets overlooked amidst the excitement of how liberal the
parser is, etc.

One of my favorite things about Rails, and I think one of the
shrewdest things the Rails team has done, is that it's written for the
most part in a very vanilla coding style. Not all the code is
vanilla, of course But it blends very well with the standard
library and so forth in style.


David

--
David A. Black |
Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3]
DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4]
[1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com
[2] http://dablog.rubypal.com | [4] http://www.rubycentral.org

 
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
Ruby extension (C++) on OS X [ruby 1.8.2] and Google-Sketchup [ruby 1.8.5] Nicholas Ruby 3 01-28-2007 01:48 AM
The Ruby Edge - Digg for Ruby and Ruby On Rails roschler Ruby 0 10-15-2006 11:35 PM
ruby-talk, comp.lang.ruby, ruby-talk-google Phrogz Ruby 4 09-05-2006 08:19 PM
#!/usr/bin/ruby , #!/usr/bin/ruby -w , #!/usr/bin/ruby -T?, #!/usr/bin/ruby -T1... anne001 Ruby 1 04-23-2006 03:02 PM
[ANN] ruby-freedb, ruby-serialport, ruby-mp3info moved to Rubyforge guillaume.pierronnet@ratp.fr Ruby 0 08-31-2003 11:57 PM



Advertisments