On Fri, 20 Sep 2013 13:46:03 +0000, ballsystemlord wrote:
> hendersj;2584453 Wrote:
>> On Thu, 12 Sep 2013 17:46:03 +0000, wolfi323 wrote:
>>
>> > But why are you using “switch” instead of a simple “if”?
>>
>> I would concur with this - switch() is typically only used if there are
>> multiple options, not to test equality to one specific value.
>>
>> ballsystemlord, it would be very important to learn to use the proper
>> structures in your coding - forming bad habits like misusing switch()
>> early on (and mixing up equality tests and variable assignment) is not
>> good.
>>
>> Jim
>>
>>
>>
> I never said my code was bug free I think it would at the very least be
> rather arrogant to do so.
And we never said you said that.
> I use switch statements instead of if statements because as far as I
> know it doesn’t matter which you use and I think it would be a good idea
> to practice using the switch statement least, when I actually need it, I
> forget the break or something stupid like that.
It’s not generally a good way to learn to use things improperly - that
reinforces “bad” behaviours.
You want to practice using things the right way - that reinforces “good”
behaviours.
Trust me on this - I’ve worked in technical education for over a decade.
I would never encourage a student to practice something that reinforced
poor practices. Doing so is bad for one’s ability to learn, because it
reinforces doing things in an improper way.
There is a difference in how switch() and conditional if…then code is
compiled, and there are performance implications for both.
There also are program readability implications for using the proper
structures in your coding. If you end up working on a project with
multiple other developers, you want code that they can understand (and
vice versa). Doing things in a non-standard way is going to (a) lose you
respect from the other developers, and (b) make your code more difficult
for them to maintain, because they’ll spend a fair amount of time looking
at the code, shaking their head, and asking “what on earth was he
thinking?”.
It’s always best to learn things and form good habits out the gate when
learning to code - and to avoid learning and reinforcing bad habits.
Jim
Jim Henderson
openSUSE Forums Administrator
Forum Use Terms & Conditions at http://tinyurl.com/openSUSE-T-C