DJPlaya / Forlix-Floodcheck-Redux

An maintained Version of Forlix Floodcheck
GNU General Public License v3.0
8 stars 3 forks source link

MakeStringPrintable might be broken #12

Closed Forlix closed 2 years ago

Forlix commented 2 years ago

Compare lines 161 and 184 of stocks.sp - what happened to the do...while loop? Take a look at my original code... since you're no longer using #pragma semicolon 1 for whatever reason (but have only removed some of the semicolons and without considering the impact) it may still work this way (the while below may still be considered part of the do...while by the compiler, leaving the following block statement without effect), but it's certainly ambiguous/misleading formatting.

DJPlaya commented 2 years ago

Hi, You where the last one i where expecting to see when opening this Issue, glad to see you caring about your Projects even after soo many Years <3

There is no need for Semicolons since the default Compiler Value is 0. I still place it behind everything except for: if/else/case/switch/function names/block lines like { } - just because, there is no good Reason, just me being Autistic ^^, but youre right, i probably should remove them from all 1.8+ Projects

I try to make an consistent Codestyle, ive documented the basics over my other Project > https://github.com/DJPlaya/Kigen-AC-Redux/blob/master/CONTRIBUTING.md

When comparing the original V1.73 Code with the latest Redux Commit, i can see the following Changes which i will ref. from another Project for easy Access:

Forlix commented 2 years ago

I admit I may have an unusually compact coding style and I'm coming from C/C++ (which is my favorite language), that should give you some perspective. That's also why I embraced the semicolon in all of my SourceMod projects because it gives you more freedom and in my opinion allows you to write more concise and more readable code. I often split up conditional statements onto multiple lines instead of putting everything in a single line - the latter to me just looks cluttered and harder to read. As the code was originally written with mandatory semicolons enabled, there had to be a semicolon after the "while", because the "while" was part of the "do" block. As a matter of fact, I believe I actually wrote this function in Visual C++, using its debugger to step through the code. Once it was complete and working I simply copied it over to my plugin, replacing just the C-style declarations and function prototypes. Nowadays and to my delight SourceMod even uses the C-style declarations which would have made this even easier.

Your code definitely looks better now, although I'd remove the empty line 185 just to make it clear that the "while" is part of the block above it (if your styling guidelines permit). That's the advantage of semicolons - looking at your code now, one might come to the conclusion that the "while" actually loops the assignment beneath it (with an awkward empty line in between). With semicolons you would start to wonder if it was just an empty loop (rare) or maybe look up to realize it is part of a "do...while".

Hopefully that answers your questions. By the way I am not sure how experienced a programmer you are, but your rule of not placing a semicolon after those things you mentioned should be rooted deeper than "no good reason". The semicolon (in C, and in SourceMod, if enabled) is not just something put at the end of a line for fun. It is used to terminate a statement. If you were to write "if(...); something" then "something" would always be done because it would not be part of the "if".

Take a look at the Wiki for SourcePawn (that's what the language for SourceMod plugins is actually called): https://wiki.alliedmods.net/Introduction_to_SourcePawn_1.7#While_Loops Note that they use semicolons in all the examples there and I also warmly recommend you do too. It helps a lot to avoid errors and ambiguities in the code if you use "#pragma semicolon 1". The compiler warnings should be your friend, not your enemy. You would have been made aware of this issue by the compiler and could have resolved it on your own.

DJPlaya commented 2 years ago

I am aware of the previous Usage of the Semicolon, its kind of a Leftover from converting since ime still learning with my Projects. I mainly left it for readability since many Coders dont like the 1.7/1.8 Change, but its a good Idea to use it for catching some typo Errors.