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.
3 comments:
Next can you address if it should be dest,src or src,dest in assembler, as well as that whole endianess thing :-)
Joking aside there are several things being addressed here. One is DRY (don't repeat yourself). The other is diagnostics when things aren't going right. You end up littering your code with prints until you figure it out. What would be ideal in this case is some way of annotating that system should take less than a second to execute and always succeed. The language/runtime should then automatically display parameters in the case of error or if it is taking longer than normal to run.
"Next can you address if it should be dest,src or src,dest in assembler"
I've posted on that. Neither.
It should be
dest := OP(src)
or
dest OP= src
or
OP ->dest, <-ssrc
or
OP in out dest, in src
or
...
I think that one of the best things I did for Intel microcode was make it use the
dest := OP( src1, src2 )
notation.
Fewer bugs.
One of the weaknesses was tyhat eventually it becaame
dest := OP( src1, src2 ).special_annotatyions...
where the special annotations were often essentially little instruction streams executed at different pipestages, such as at the renamer and at retirement.
One of the biggest regrets I have is that I acquiesced, let my programming partner win, in a simulator at another company, where the microinstructions ended up looking like
OPCODE r1, r2, r3, r4, r5, ...
I.e. with no syntax helping understand which was which.
Although, to be fair, he later added input/output indications.
OPCODE <>r1, >r2, reg2
although it is silly to have keywords for all operands
COMPARE-AND-BRANCH-AND-LINK-INDIRECT-GE reg1, reg2 target<-reg3, link->reg4
For some reason I find that < and < do not indicate direction as well as <- and ->. Wish I worked in a character set where there were real arrows.
Post a Comment