POV-Ray : Newsgroups : povray.off-topic : Coding in ___ is like ___ : Re: Coding in ___ is like ___ Server Time
4 Sep 2024 21:20:53 EDT (-0400)
  Re: Coding in ___ is like ___  
From: Darren New
Date: 26 Feb 2010 14:31:32
Message: <4b882194$1@news.povray.org>
Warp wrote:
>   You don't have to deal with constructors. You can simply say "if you create
> a string without initializing it, it defaults to an empty string".

And they ask "what does an integer default to?"  And then they ask why.

>   As opposed to char*, which defaults to... what?

Uninitialized. Like every single automatic variable in C, nothing gets 
initialized before you assign to it.

>   You seriously claim that eg. pointer arithmetic, null-terminated strings
> and the standard C string manipulation functions are easier for a beginner
> to understand than C++'s std::string? (And that's just one example.)

Yes, if you actually want to understand it. If you want to treat std::string 
as magic, then no.

>> It would be easier to explain what's happening.
> 
>   Does the beginner really need to know what the compiler is doing under
> the hood in this case?

If you want to treat the standard template library as magic, no.

>> I don't have to explain the syntax for method invocation
> 
>   There was no method invocation in my example. (Ok, operator+() *is* a
> method, and it's being called, but the beginner doesn't need to know that
> in order to use string concatenation.)

strings.size() isn't a method invocation? And in this case, += and [] are as 
well, but I agree you could probably skip over that bit.

>> the differences between method invocations on 
>> references and pointers
>   My example didn't need any such thing.
>> overloaded operators
>   The beginner doesn't need to know that to implement that example.

So you're arguing that the complexity can be brushed off as "magic you don't 
have to worry about."  That's OK, but in my experience that's not a good way 
to teach beginners.

I wasn't talking specifically about your example in some of these cases, but 
about the difference between teaching C++ and C in general.

>> or what namespaces are.
> 
>   Is it really a bad thing that the beginner is introduced to namespaces
> from the very beginning? It's not like they are very hard to understand.

To beginning programmers, *everything* is hard to understand.

>   No. The C version would require explaining lots of things about how C
> null-terminated strings work internally 

True.

>   You would also need to explain that if the function returns a pointer to
> a new C string it allocated itself, how the calling code needs to make sure
> that it's not leaked. (Again, no such need with std::string.)

Yes yes and yes.

>   So the C++ version is enormously simpler than the C version in all possible
> regards. The newbie needs to learn a lot less and can start doing some
> practical (and safer) code much more quickly.

We'll just have to disagree.

>> Basically, in the C equivalent, the 
>> only *confusing* part is that C doesn't allocate multi-word objects for you.
> 
>   No, it isn't. You have to understand null-terminated strings, how to
> calculate the length of strings, and how to manually manage the memory
> for the strings before you could write such a function in C.

Yep. Those aren't confusing, tho. They're tedious, and may seem like silly 
rules, but not *confusing*. You can explain that stuff with pictures.

Based on my experience teaching classes, treating something as "magic you 
don't have to understand", and having several elements that perform the same 
role differently, is what leads to confusion. You immediately start down the 
cargo-cult programming path, where you do it like this not because it's 
right, but because that's what the teacher said to do and you don't know why.

Plus, the concatenate example is a terrible example for teaching. There's no 
I/O, it's not a stand-alone program, and it's not complete.

-- 
Darren New, San Diego CA, USA (PST)
   The question in today's corporate environment is not
   so much "what color is your parachute?" as it is
   "what color is your nose?"


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.