E.g.
let x = y + z where z = some log and complicated expressionsHere's an example from writing "shell scripts" - although here I am doing the shell script in Perl: Start off with:
system("command with some long and complicated command line");Realize that you want to repeat the command in a pre-announcement of what you are doing, and in an error message: Start off with:
print "RUNNING: command with some long and complicated command line\n"; my $exitcode = system("command with some long and complicated command line"); print "error: exitcode=$exitcode: command with some long and complicated command line\n" if there_is_a_problem($exitcode);Now avoid repetition: Standard way:
my $cmd = command with some long and complicated command line"; print "RUNNING: $cmd"; my $exitcode = system("cmd"); print "error: exitcode=$exitcode: $cmd\n" if there_is_a_problem($exitcode);In my opinion the non-code ordered way is more readable:
{ my $cmd; # maybe some declaration to say it is not ordered? print "RUNNING: $cmd"; my $exitcode = system($cmd = "command with some long and complicated command line"); print "error: exitcode=$exitcode: $cmd\n" if there_is_a_problem($exitcode); }I think it is more readable because you see the value set at the point where it matters, where it is used most intensely (the other uses are mild, just prints). Note that I have used a scope.