It's a form of Code Golf, but instead of creating the smallest possible program you are packing as much functionality into the fewest lines (or one line) as possible.
@MasterGy:
It was a real eye opener when I realized that comparison operations could be used mathematically.
For instance using
y = y- (y<0) : y = y+ (y>5)
to bound y to the range of 0..5. Much faster and more compact than IF..THENs, and more readable once you know the trick. I was so proud of myself as I started finding ways to improve my existing programs.
Re LOC: I'll often combine two or more closely related operations on a single line, because I find it to be much more readable when I can take in more of the program on a single editor screen or printed page. Also, grouping the code up physically helps to clarify the program logic in my mind.
A dusty old one-liner:
Model III Basic had a line length limit of 255 characters. One trick I "discovered" was to type in as many characters as possible, hit <ENTER> and let the interpreter tokenize the line, then edit the line to add even more.
This one-line drawing program for the Model III weighs in at 220 characters, so no problem there. Note that no target line number is given to the GOTOs. 0 was the default target if none was given. Also, the THEN keyword was not strictly required:
The two POKEs make this a self-modifying program. The SET...PEEK...RESET sequence which provides a flashing cursor in "erase" mode becomes RESET...PEEK...SET in "draw" mode. (The PEEK reads the Model III's keyboard matrix to get the status of the arrow keys, spacebar (draw/erase toggle), and CLEAR key (clears screen).
(I later wrote a full drawing program in Basic, using every trick up my sleeve to get near machine-language speed wherever possible. Although I once had just about every line of that program memorized, looking at it all these years later even I cannot figure out what my own program is doing at some points. That program in dense!)
@MasterGy:
It was a real eye opener when I realized that comparison operations could be used mathematically.
For instance using
y = y- (y<0) : y = y+ (y>5)
to bound y to the range of 0..5. Much faster and more compact than IF..THENs, and more readable once you know the trick. I was so proud of myself as I started finding ways to improve my existing programs.
Re LOC: I'll often combine two or more closely related operations on a single line, because I find it to be much more readable when I can take in more of the program on a single editor screen or printed page. Also, grouping the code up physically helps to clarify the program logic in my mind.
A dusty old one-liner:
Model III Basic had a line length limit of 255 characters. One trick I "discovered" was to type in as many characters as possible, hit <ENTER> and let the interpreter tokenize the line, then edit the line to add even more.
This one-line drawing program for the Model III weighs in at 220 characters, so no problem there. Note that no target line number is given to the GOTOs. 0 was the default target if none was given. Also, the THEN keyword was not strictly required:
The two POKEs make this a self-modifying program. The SET...PEEK...RESET sequence which provides a flashing cursor in "erase" mode becomes RESET...PEEK...SET in "draw" mode. (The PEEK reads the Model III's keyboard matrix to get the status of the arrow keys, spacebar (draw/erase toggle), and CLEAR key (clears screen).
(I later wrote a full drawing program in Basic, using every trick up my sleeve to get near machine-language speed wherever possible. Although I once had just about every line of that program memorized, looking at it all these years later even I cannot figure out what my own program is doing at some points. That program in dense!)