- Joined
- Feb 1, 2015
You are correct. Using a configuration file that contains all of these values would be much more optimal as it allows for you to easily find the values, as well as reducing read time (if you're using UNIX style IO where you access a single line). If you're too scared to use config files (like you should!), there's always the switch statement that performs slightly better than if/elseif pyramids. The nice thing about switch statements is that the compiler can optimize them, as it behaves like an index in a book (you only need to go to the page with the key word, not every other page in the index). Note that switch statements are a major hallmark of C languages. Even the conditions that get evaluated within the if/elseif pyramid are bad. "if (Male == false)" can just be written as "if (!Male)". I actually wouldn't by surprised if a couple "code pyramids" (abusing if/elseif makes the indenting look like a pyramid) were lying around.Or, at the very least, it looks like it would make the computer chug running it because it's constantly having to check for several variables every time it loads a character.
This is entirely subjective, but I find the following equally as valid, and it saves useless indents. But anything that isn't self explanatory should be in blocks for easier commenting.Here's the if-else statement shit if you're interested. I know I'm not worth judging code since I'm a newbie but who and why the fuck would you code that in a single line instead of just simple blocks it's hard to read
Code:
if (!PhoneRegex.test(phonenumber)) window.alert("Please enter a valid phone number.")
Last edited: