When you write something like
def foo(var)
if test(var)
bar(…)
log(…)
else
bar(…)
log(…)
end
end
tools like reek complain (two duplications, long method,…), and
somehow push you to write
def foo(var)
test(var) ? do_this : do_that
end
def do_this … end
def do_that … end
I still do prefer the first variant which shows more clearly the
parallel intentions.
What do you people think ?
_md
On Thu, Apr 26, 2012 at 1:33 PM, Michel D. [email protected]
wrote:
end
I still do prefer the first variant which shows more clearly the
parallel intentions.
What do you people think ?
I think the conditional is completely superfluous. Or are there any
differences in the two branches? I can’t see any…
What does the real code look like?
Kind regards
robert
Robert K. wrote in post #1058456:
What does the real code look like?
One example :
def create_report
report = @recipe.run_with_logger(@parameter_values)
if report
@report = report
J2R.logger.info("report created")
bottom_message "Nombre de lignes #{@report.size}"
else
J2R.logger.error("error creating report")
bottom_message "Erreur à la création du rapport"
end
end
_md
Michel D. wrote in post #1058458:
Robert K. wrote in post #1058456:
There is even a static analyser for which “else” is a smell.
_md
Robert K. wrote in post #1058460:
On Thu, Apr 26, 2012 at 1:47 PM, Michel D. [email protected]
wrote:
J2R.logger.info("report created")
bottom_message "Nombre de lignes #{@report.size}"
else
J2R.logger.error(“error creating report”)
bottom_message “Erreur la cration du rapport”
end
end
Looks perfectly OK to me. Creating two additional methods seems like
a lot of overkill which hinders readability. My 0.02 EUR…
Kind regards
robert
Glad you agree ! reek can be overstuffed.
(I guess you are somewhere farther on the Loire. Sun in Tours for the
time being…).
_md
On Thu, Apr 26, 2012 at 1:47 PM, Michel D. [email protected]
wrote:
J2R.logger.info("report created")
bottom_message "Nombre de lignes #{@report.size}"
else
J2R.logger.error(“error creating report”)
bottom_message “Erreur la cration du rapport”
end
end
Looks perfectly OK to me. Creating two additional methods seems like
a lot of overkill which hinders readability. My 0.02 EUR…
Kind regards
robert