The use of parenthesis; "dsl methods" and multi-line invocations
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.
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).
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.
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
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.
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.
There's no such thing as class macros. There are just methods.
@pedrorolo True, but many people call them "macros". (e.g. https://codeburst.io/ruby-macros-18bb67e051c7)
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?