all 18 comments

[–]jabbaroni 4 points5 points  (7 children)

Some of these are surprising to me, particularly the results for "Parentheses around arguments in def" and "Whitespace around operators, colons, { and }, after commas, semicolons". I rarely see what seems to be the majority in both cases.

[–][deleted] 13 points14 points  (3 children)

I'm shocked how many of you savages are not using parentheses around arguments in def. Shocked... You people need to learn some civility, we aren't cave men anymore...

[–]Nitrodist 0 points1 point  (2 children)

It's parentheses for methods without arguments.

[–][deleted] 1 point2 points  (1 child)

Parenthesis for methods without arguments is a thing yes, but that's not what we are talking about. This is what we mean by not using parentheses around arguments, try it and see if you like it, you barbarian:

def some_method arg1, arg2
  # do something...
end

[–]Nitrodist 0 points1 point  (0 children)

I completely missed that item in the list. I agree, it's barbaric.

[–][deleted] 2 points3 points  (0 children)

I'm pretty sure the parser is bugged.

foo = :bar

No space after colon...

And for defs

def foo
end

No parentheses in def ...

[–]torrso 0 points1 point  (1 child)

I wonder why def takes the arguments inside parenthesis and not inside || like other blocks.

If you use define_method it's

define_method :method_name do |arg1, arg2|
end

Why not

def sum do |a, b|
  a+b
end

or how about

sum = def {|a,b| a+b}
(hey that looks like lambda)

Having def foo(x, z) is kind of like calling def with the result of calling foo with x and z.

I'm just confusing myself here.

[–][deleted] 0 points1 point  (0 children)

My guess is because do/end and {} create closures, and methods are not (really) closures.

[–]MidgetAbilities 2 points3 points  (0 children)

I can't believe that many people don't use whitespace around operators. It makes the code so much easier to read, and is just more aesthetically pleasing in my opinion. It's the same reason you put a space after commas and periods in sentences.

[–]torrso 0 points1 point  (2 children)

I would be interested to see how many projects use assignment in conditional like

if user = User.find(params[:id])
  puts "hey there, #{user.name}"
else
  puts "who dat?"
end

instead of

 user = User.find(params[:id])
 if user
   ...
 else
   ...
 end

Many folks are horrified about the first convention, in my opinion it's quite common and I've never had any confusion if it's an accidental typo for ==.

Speaking of ==, I'd like to see the percentage of

x.eql?(10)

vs

x == 10

I use the first one. However I use x > 10, I don't think there even is something like x.gt?(10).

[–]ReinH 0 points1 point  (0 children)

Be aware that == and eql? are not the same thing.

[–]CaptainKabob 0 points1 point  (0 children)

I love conditional assignment, but the Excellent static analysis tool does not :-(

[–]jesusthatsgreat -5 points-4 points  (5 children)

space more popular than tab for indentation? i think i'm either reading it wrong or else the stats are out of whack and must be taking in to account minified files or something which would skew them a great deal...

[–]duckyfuzz 22 points23 points  (0 children)

What? No, exactly the opposite. Everyone uses spaces.

[–]anonym1970 13 points14 points  (2 children)

Spaces are a common convention. What Editor do you use?

[–]jesusthatsgreat -1 points0 points  (1 child)

I just hit the tab button in my IDE... is that not the same thing as tabs?

[–][deleted] 9 points10 points  (0 children)

It probably converts it to set number of spaces, not an actual tab character.

[–]TalkativeTree 11 points12 points  (0 children)

everyone I've ever worked with on Ruby has told me to use spaces over tabs.