Certain style guides advise against the use of an explicit begin
in method bodies:
# Bad
def method(*args)
begin
# code
rescue
# code
ensure
# code
end
end
# Good
def method(*args)
# code
rescue
# code
ensure
# code
end
Some developers feel the exact opposite and dislike the implicit begin
.
Thoughts?
I prefer the implicit begin
since it is more concise and highlights the fact that the entire method is within a rescue
. I also see begin
as a smell indicating you need to extract a method. Using the explicit begin
removes this indicator.