Conditionals Part III

Channel:
Subscribers:
2,650
Published on ● Video Link: https://www.youtube.com/watch?v=IWCPDixw20c



Duration: 58:27
152 views
1


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.







Tags:
csci 40
conditionals
c++
vetting code
floating point comparison