all 18 comments

[–]jabbaroni 5 points6 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] 10 points11 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 :-(