Conditionals Part III
Today we talked more about conditionals, with the most important takeaway points being:
1) Avoid switches unless you have a compelling reason to use them (at this point in your career you won't have one). Just use if/else if/else blocks instead. Every time I see a new programmer use a switch I immediately assume they've done it wrong. I'm not always right, but I'm not always wrong either.
2) Likewise, if you want to be safe, usually put {}'s around your code blocks (I don't always do this, sometimes readability is more important), and always initialize your variables. Code that works "some of the time" is one of the most frustrating and horrible things to deal with both for programmers and for players of Bethesda games.
3) When comparing floating point numbers, be aware that if you're doing a lot of additions and subtractions error will accumulate in them, and so don't expect == to work when doing comparisons between two floats. Instead you should see if they are close to each other.
4) Never trust any input into your program. Vet everything, double check everything, never assume things will be given to you correctly or in the right order, or that the values will be in a certain range. If your code crashes because someone's cat walked on the keyboard, that's your fault, not the cat's. Even when I write code by myself for myself, I still vet like crazy every input into it.
Other Videos By Bill Kerney
2021-08-27 | Examining Sources |
2021-08-27 | Gaming Psychology and Lerping Materials |
2021-08-27 | Hash Tables |
2021-08-25 | Handling Errors, Cheating, Competency Exams, Chars, Loops |
2021-08-25 | Evaluating Claims |
2021-08-25 | Final Project!!?! |
2021-08-24 | UE4 Material Instances |
2021-08-24 | RSA Encryption Part 2, Computer Security |
2021-08-23 | UNIX Shortcuts, C++ Shortcuts, Bools |
2021-08-23 | Welcome to CSCI 1 @ Fresno State! |
2021-08-20 | Conditionals Part III |
2021-08-20 | Navmesh, Materials, Axis-Aligned Bounding Boxes |
2021-08-19 | Multiplayer Balance and UE4 Materials Pt. 2 |
2021-08-19 | The Optimizer, Bigints, Prime Generation, RSA Encryption, Cryptographic Hashing |
2021-08-18 | Conditionals Part II |
2021-08-17 | Line Rasterization |
2021-08-17 | Game Design Principles and UE4 Materials |
2021-08-17 | Powm, Modular Division, Espionage |
2021-08-16 | Strings, Conditionals, Logical Operators |
2021-08-13 | C++ Variables, Algebra, I/O |
2021-08-12 | Week 1 Day 2 - Introduction to Rendering |