|
|
>> Given that I could bearly produce working code in C with the tutor's
>> help, my chances of getting anywhere with C++ are basically nil.
>
> On the contrary: C++ makes it much easier to write working safe code.
> You just need a few rules of thumb:
>
> 1) If you ever get the temptation of using the keyword 'new', don't.
> (And no, "malloc()" is not good either. See rule 3.)
>
> 2) If possible, avoid using pointers.
>
> 3) If possible, avoid functions in the C standard library.
>
> 4) If you want, use the at() method to access data in random access data
> containers.
>
> That's it. With these simple rules you will be writing clean safe code
> in no time.
Rule 3 should be easy - assuming C++ provides good replacements. (Seems
like a safe assumption to me.) Rule 1 looks fairly easy.
Rule 2 is the one that puzzles me. At least in C, *anything* larger than
a machine register is a pointer. So "avoid pointers" is pretty much
impossible as soon as you want to touch anything larger than 32 bits. No
strings, no arrays, no structs, nothing. Unless C++ radically changes
the rules in this respect, I'm not sure I see a way round that.
Regarding rule 4... does this mean C++ at least manages to provide some
standard containers *other* than arrays? (And that you can *query the
size* of an array?)
> These rules should be broken only when you get very fluent
> with the language and know what you are doing.
But you can 100% guarantee that any code you read that was written by
somebody else will be full of such exceptions. ;-)
>>> I
>>> had a lot of fun with C++ and OpenGL in college. It's really not that hard
>>> to learn for someone like you.
>
>> As I say, the trouble is that if your program doesn't work, there is no
>> way you can ever find out why.
>
> Modern compilers and profilers do a quite good job at catching typical
> beginner mistakes in C++ programs.
Well, perhaps. I doubt they'll help you fix OpenGL issues though...
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|