How NOT to Code

By angros47

 

  • Use a lot of SHELL commands, always. For example, if you need to play a sound, don't use built-in commands, libraries or system API: it's much easier to use SHELL “sndrec32.exe /embedding /play /close laser.wav”. It's much easier, expecially if you need to use it many times (i.e., in a game, if you want to play a sound at every shot); every time you'll need to reload both the sound player and the wav file, but don't worry: modern computer are fast enough.

 

  • If you need to use a file from a subdirectory, always use absolute paths: never use BLOAD “images\tiles.bmp” when you could use a more specific BLOAD “C:\Program files\basic compiler\new folder\program1\temp\images\tiles.bmp” or similar: so, you'll encourage your users to put the files in the correct directory.

 

  • GOTO is useful, but a bit embarrassing: so, if you need to use it, try to hide it: use few line numbers, and only where is difficult to spot them:
arg=Trim(arg)
If Instr("0123456789+-.(",Left(Arg,1)) Then
If Instr(Arg,".") Then Return 2 Else Return 1
End If
1 If Left(Arg,1)=Chr$(34) Then Return 3
If Instr(Arg," ") Then arg=Left(arg,Instr(arg," "))
For var.variable=Each variable
If Upper(Trim(var\name))=Upper(Trim(arg)) Then Return var\optype
Next

(can you see the “1” at a first glance?)

An even better solution is to use line labels, disguising them as subs:

if a=1 then test
print “a is not 1”
test: print “a=1”

also, if you have a sub called “test_1” or so, the trick works better.

 

  • Instead of using GOTO, you can use function calls:
sub Menu
print “1: Item 1”
print “2: Item 2”
print “3: Item 3”
print 
input “enter your choice”,a
if a <1 or a >3 then Menu
end sub

In LOGO it works perfectly, so it has to work in basic too, right?

 

  • Never use system API or dedicate libraries to build a GUI: built-in commands are more than enough, and re-inventing all the GUI writing everything in basic, and drawing all controls with CIRCLE, LINE, PAINT and PRINT will give you a better look.

 

  • If you are writing a game, you can save a lot of time by downloading all graphic resources from different sites: don't be afraid to mix pixel-art sprites (at different resolutions) with photo used as a background: nobody will notice it: 

  • If you want to create art for your game, Microsoft Paint is the way to go.

 

  • If you need to use some include files, customize them, so your program won't work anymore with include files provided with a fresh install of the compiler, and you won't be able to compile programs made by others that use the same include files.   Of course, when you distribute your program, you don't need to provide also the modified include files: your users will surely be able to guess what you changed, and to modify their include files by themselves.

 

  • Always use graphic mode, even for text-only programs. There is no need to use console, when you can do your own console in the graphic mode.

 

  • Don't mess with integers or floating-point variables to store your data: a string can do just as well, with a wise use of STR$ and VAL; instead of using:

 

For I=0 to 640
 X(i)=SIN(I/10)*10
NEXT
For I=0 to 640
 PSET (I,X(i))
NEXT

You could do:

For I=0 to 640
 X$(i)=STR$(SIN(I/10)*10)
NEXT
For I=0 to 640
  PSET (I, VAL(X$(i)))
NEXT

 

  • If you made many small, unrelated programs, merge them in a single program with a menu that allows you to choose what you want to do: so, your users will never need to leave your software. To encourage users not to leave your program, you shouldn't put an “exit” command: the only way to leave your program must be to terminate it by force.

 

  • Don't distribute your program as a zip file: a Setup.exe looks cooler, and you will be sure that your users will always install all the files provided, even if they only want a single file. Also, don't provide a way to uninstall it: your program is cool, so nobody needs to uninstall it anyway. 

 

Powered by CMSimple | CMSimple Legal Notices | (X)html | css | Login | Template-Design: Lars Ellmauer | Template-Modified: Imortisoft ISD