ruby-style-guide icon indicating copy to clipboard operation
ruby-style-guide copied to clipboard

The use of parenthesis; "dsl methods" and multi-line invocations

Open pedrorolo opened this issue 11 years ago • 8 comments

I think that the rule about dsl methods and the absense of parenthesis should be removed from this guide, since what is or not a dsl method is highly subjective.

On the other hand, I'd like to propose that multi-line method invocations should indeed use parenthesis, since it is the only way to make them be auto-indented in emacs.

pedrorolo avatar Sep 01 '14 10:09 pedrorolo

I think that the rule about dsl methods and the absense of parenthesis should be removed from this guide, since what is or not a dsl method is highly subjective.

Might be a bit subjective, but it's commonly accepted.

On the other hand, I'd like to propose that multi-line method invocations should indeed use parenthesis, since it is the only way to make them be auto-indented in emacs.

That's not true. This was just a long-standing bug, that was finally fixed in Emacs 24.4 (soon to be released).

bbatsov avatar Sep 01 '14 10:09 bbatsov

Zdravej

again regarding the dsl_methods: should a multi_line "dsl method" invocation have parens or not? I'd be for optionaly using parens regardless of the method nature.

again, something as subjective and vage as dsl method can't be commonly accepted, since "dsl method" is an empty term. It could be defined as: class method invocation within the class body; a method invocation within a block with modified self; an invocation to a method from a lib that does not belong in your code. It's simply a too complicated rule that is prone to create discussions.

pedrorolo avatar Sep 01 '14 11:09 pedrorolo

module MyDSL

  def task name, &action
  end

  def iff(condition)
  end

end

Or, using docs:

module MyDSL

  # :call-seq:
  #   task :name do ... end
  #
  def task(*args, &block)
  end

  # :call-seq:
  #   iff(condition).then { ... }.else { ... }
  # 
  def iff(*args, &block)
  end

end

LavirtheWhiolet avatar Sep 08 '15 18:09 LavirtheWhiolet

Might be a bit subjective, but it's commonly accepted.

More than a bit subjective; it's downright inconsistent.

Should it be sleep(100) or sleep 100? This example says the latter, though IDK why.

And how are puts or attr_reader keywords? There is nothing special about them. A developer can define identically behaving puts2 and attr_reader2 methods.

pauldraper avatar Oct 18 '16 15:10 pauldraper

I'm not arguing. Apart from class "macros" I use parens for pretty much everything myself. I was just saying that we can't have a community resource discourage a very common community-established practice. What we can do is to extend the rule with more information, which I think would solve the concerns that were brought up here.

bbatsov avatar Jun 12 '19 08:06 bbatsov

There's no such thing as class macros. There are just methods.

pedrorolo avatar Aug 21 '23 07:08 pedrorolo

@pedrorolo True, but many people call them "macros". (e.g. https://codeburst.io/ruby-macros-18bb67e051c7)

bbatsov avatar Aug 21 '23 09:08 bbatsov

That idea, and consequently this rule, harms newcomers to the ruby language, in the sense that it passes the idea that there's something special or magic about those method invocations. If the language semantics are orthogonal why to enforce style rules that create the illusion that they are not?

pedrorolo avatar Aug 21 '23 10:08 pedrorolo