@MasterGy — The important thing is to code in a style which is decipherable for the user base of that code. It’s why many companies have such long, drawn out rulesets for how to properly code a program. As long as you’re coding for yourself, code in the style that makes the most sense to you. If you’re coding a library, or such, for other people to be able to use, or modify, in the future, then you need to adjust your style to be suitable for public consumption.
Someday, I’ll share some of my personal code with you guys. My personal style is a lot like Pete’s — short, compact, and which uses the most amount of real estate on the screen, to reduce scrolling and line count as much as possible. Yet, if I code something to share on the forums, I take time to try to unwind and expand those lines to make them as easily readable as possible.
_PRINTSTRING (bx + (bw - tw) / 2, by + fh * i), t$
For the above, I’ll go into search and replace all in the IDE and swap bx to BoxLeft, bw to BoxWidth, tw to TextWidth, by to BoxTop, fh to FontHeight, and t$ to temp$.
Now all my abbreviated variables, which made perfect sense to me, now hold some self-documenting meaning for others. (The above would basically center multi-line text into a boxed area of the screen for me, while inside a loop.)
Of course, sometimes even the best attempts at making code understandable fails. The other day, on Discord, I was questioned about some code I’d shared which was basically:
IF x THEN IF y THEN do_something ELSE do_other_stuff
To me, this makes perfect sense, and I didn’t think it needed unwinding further. Others had never seen an IF inside an IF and didn’t know how to decipher that. They didn’t know where that ELSE might relate to: the IF x, or the IF y. Breaking it down to the following allowed them to instantly comprehend it:
IF x THEN
IF y THEN do_something ELSE do_other_stuff
END IF
At the end of the day, coding style is all about attempting to code in a manner to make it easy for the user-base to read, understand, and work with the code in the future.