D-Bug & Automation Forum
D-Bug & Automation Forum >> Coding >> Quick Extract 0.4 source code.
http://d-bug.mooo.com/dbugforums/cgi-bin/yabb2/YaBB.pl?num=1269690191

Message started by Christos on 27.03.10 at 11:43:10

Title: Re: Quick Extract 0.5 source code.
Post by ggn on 14.03.12 at 20:03:56
WTFPL \o/

In a more serious note, I had a quick glance over the source code and would like to make a few suggestions. They are more or less of aesthetic purposes, but maybe they will help Christos (or anyone else) in bigger projects.

(hope they won't come out as too pretentious ;))



Code (]~SHEL_READ(cmd$,tail_str$)
tail$=RIGHT$(tail_str$,(LEN(tail_str$)-1))[/code):



Oh dear, my first comment is really nitpicking :). Anyway, since tail_str$ is a throwaway string (i.e. not used anywhere else in the code) you could safely replace the above code with

[code]~SHEL_READ(cmd$,tail$)
tail$=RIGHT$(tail$,(LEN(tail$)-1))


There, this must have saved at most 128 bytes of RAM :).

Next up:


Code (]IF ext$="zip" OR ext$="ZIP"
  @unzip
ENDIF
IF ext$="rar" OR ext$="RAR"
  @unrar
ENDIF
IF ext$="lzh" OR ext$="LZH" OR ext$="lha" OR ext$="LHA"
  @unlzh
ENDIF
IF ext$="zoo" OR ext$="ZOO"
  @unzoo
ENDIF
IF ext$="tar" OR ext$="TAR"
  @untar
ENDIF
...
etc
[/code):



Since each time the program is run only one of those if/endifs will be executed, you can shorten the code a bit by using if/elseif/endif (this way you can fit more code that has the same functionality in your editor screen, giving you a better overview). Program execution will also be slightly faster :).

Also, you could reduce the amount of checks if you do something like
[code]...
if upper$(ext$)="ZOO"
...


Finally you could also replace all ifs with select/case:


Code (]select upper$(ext$)
case "ZIP"
  @unzip
case "RAR"
  @unrar
case "LZH"
  @unlzh
case"LHA"
  @unlzh
case "ZOO"
  @unzoo
case "TAR"
  @untar
....
endselect[/code):



Again, this is a matter of coding style I guess, it just looks neater in my eyes.


Last one:

[code]    EXEC 0,progdir$+"arc\unzip.ttp",CHR$(LEN(cmdl2$))+cmdl2$,""
  ...
  ' I should probably find a way to check whether the program completed succesfuly
  ' and not just write it
  ALERT 1,"Operation completed",1,"OK",ending


All those years I used the ~exec(...) syntax, i.e. discarding the program's exit code. You could use this to your advantage here:


Code (]return&=EXEC(0,progdir$+"arc\unzip.ttp",CHR$(LEN(cmdl2$))+cmdl2$,"")
if return&=0
   'program exited successfully
else
   'oops, something bad happened
endif[/code):



or

[code]if EXEC(0,progdir$+"arc\unzip.ttp",CHR$(LEN(cmdl2$))+cmdl2$,"")=0
   'program exited successfully
else
   'oops, something bad happened
endif


Anyway, that's my xunty suggestions regarding the code.

About program functionality now... How about if the program scanned (for example) for control pressed at startup and if that's true then extract the contents of the archive in a new folder and if (again for example) alt was pressed then it'd extract the contents in a new folder? That would (imho) reward frequent users with a more usable program, since they won't have to move the mouse to select an option they know by heart.


D-Bug & Automation Forum » Powered by YaBB 2.6.0!
YaBB Forum Software © 2000-2024. All Rights Reserved.