|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
||||
|
||||
|
Pascal app. feedback
I started programming two weeks ago, and begun with pascal since I've heard that it is a good language to start with. Anyway I made this encryption program and would like some feedback on it. Like are there better ways of doing this and such. Any ideas are appreciated!
/lingon |
|
#2
|
|||||||||||
|
|||||||||||
|
To begin with, you generally don't want to post code as an attachment unless it is actually too large to post in the text of a message; more importantly, you should not post an attachment containing an executable, period. First off, the executable is of little if any help, as you really can't debug it; unless you are having problems with the executable itself, the important material is the source. Second, there have been more than a few jerks who have tried to get people to run viruses or backdoors that way, and most of the regulars, upon seeing a zipped file, will just ignore the discussion thread rather than deal with that. Finally, the zipped executable takes up a lot more space than the source, and you have to go out of your way to download it; even aside from the virus problem, most readers simply would want to hassle with it.
Second, you generally want to indent you code to match the nesting of the expressions, like so: Pascal Code:
While it may seem a bit odd at first, you'll find that it makes a tremendous difference in the readability of the code once you get used to it. If you use an editor or IDE that recognizes Pascal code (e.g., Emacs, Scite, vim, Zeus Edit, EditPad Pro, Delphi, Dev-Pascal, Dr Pascal, etc.), it should indent the code for you, or even allow you to indent a section of existing code automatically. Third, for the menu part in the main program block, since val is a simple scalar variable whose value you are testing against a specific list of possible values, you might want to use a case statement instead of the successive ifs: Pascal Code:
This might make it clearer and easier to change later. Fourth, you are using global variables for everything, rather than local ones; while it is not wrong per se, this is usually considered a bad practice. You should try to have the variable you are using visible in only the parts of the program that use them. You can also use arguments to further reduce the need for globals, by allowing you to pass values to a procedure or function without making them visible elsewhere. Using the scoping rules for nested procedures can also let you share variables between procedures without making them global in scope. (On a side note: using lowercase letter 'l' as a variable name is a Bad Thing, since in some fonts it can too easily be mistaken for either the capitalized 'I' or the numeral '1'; the latter in particular has considerable potential for confusion.) Lastly (for now), you might want to decompose the program into smaller pieces; specifically, it is a good idea to separate the user interface code from the actual computation code. In Pascal, you specifically can nest procedures and functions inside of each other, which makes it easy to break down a single procedure into many sub-components. You could, for example, do something like: Pascal Code:
This particular example is trivial, but with some thought you'll see how this can be applied more generally. I'll try to take a closer look at things later.
__________________
Rev First Speaker Schol-R-LEA;2 JAM LCF ELF KoR KCO BiWM TGIF #define KINSEY (rand() % 7) λ Scheme is the Red Pill Scheme in Short • Understanding the C/C++ Preprocessor Taming Python • A Highly Opinionated Review of Programming Languages for the Novice, v1.1 FOR SALE: One ShapeSystem 2300 CMD, extensively modified for human use. Includes s/w for anthro, transgender, sex-appeal enhance, & Gillian Anderson and Jason D. Poit clone forms. Some wear. $4500 obo. tverres@et.ins.gov Last edited by Schol-R-LEA : April 30th, 2006 at 10:39 AM. |
|
#3
|
||||
|
||||
|
Okay, thanks alot dude. I will definetly follow those tips.
![]() |