POV-Ray : Newsgroups : povray.off-topic : Coding in ___ is like ___ Server Time
4 Sep 2024 19:17:11 EDT (-0400)
  Coding in ___ is like ___ (Message 31 to 40 of 66)  
<<< Previous 10 Messages Goto Latest 10 Messages Next 10 Messages >>>
From: Invisible
Subject: Re: Coding in ___ is like ___
Date: 26 Feb 2010 11:40:43
Message: <4b87f98b@news.povray.org>
>>> Still, at least it's better than C.
> 
>> Well, it's better than C for experts. For newbies, I think C is probably 
>> easier, since there's less magic going on you need to know.
> 
>   You mean newbies don't need to handle dynamically allocated memory?
> 
>   Exactly which part of C is simpler for newbies than C++?

Simpler /= easier. ;-)

(If anybody out there still thinks simple and easy are in any way 
correlated, try learning the Waltz. It has THREE STEPS IN IT, and yet 
nobody can do it right for at least the first 20 minutes.)


Post a reply to this message

From: Darren New
Subject: Re: Coding in ___ is like ___
Date: 26 Feb 2010 12:19:45
Message: <4b8802b1@news.povray.org>
Kevin Wampler wrote:
> Darren New wrote:
>> Kevin Wampler wrote:
>>> Makes sense.  I think the runtime code generation was what I was 
>>> particularly interested in, 
>>
>> Huh. That's one part I don't think changed that much.
> 
> It's also entirely possible that I'm remembering 
> incorrectly/incompletely here.

It *is* relatively primitive. But then, you *are* creating essentially 
machine code. :-)  I just don't remember hearing of any significant changes.

-- 
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

From: Darren New
Subject: Re: Coding in ___ is like ___
Date: 26 Feb 2010 12:21:03
Message: <4b8802ff$1@news.povray.org>
Warp wrote:
>   Exactly which part of C is simpler for newbies than C++?

You don't have to deal with constructors, destructors, exceptions, the 
difference between casing classes and casting pointers to classes, etc.

It's simpler *because* it's less powerful, in the same way that using an axe 
is simpler for newbies than using a chainsaw.

-- 
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

From: Darren New
Subject: Re: Coding in ___ is like ___
Date: 26 Feb 2010 12:22:06
Message: <4b88033e$1@news.povray.org>
Kevin Wampler wrote:
> One of these days I'm going to learn it just because I'm curious about 
> it, but I haven't gotten around to it yet.

It's sort of like Perl, only more ... tabular, somehow. People don't use it 
any more because computers are powerful enough to run things like Perl now.

-- 
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

From: Warp
Subject: Re: Coding in ___ is like ___
Date: 26 Feb 2010 12:35:13
Message: <4b880650@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> Warp wrote:
> >   Exactly which part of C is simpler for newbies than C++?

> You don't have to deal with constructors, destructors, exceptions, the 
> difference between casing classes and casting pointers to classes, etc.

  Why would a beginner need to deal with constructors, destructors,
exceptions and the like?

> It's simpler *because* it's less powerful, in the same way that using an axe 
> is simpler for newbies than using a chainsaw.

  No, C is a lot more complicated for the beginner precisely because it's
less powerful.

  In C++ the beginner can write things like this:

std::string concatenate(const std::vector<std::string>& strings)
{
    std::string result:
    for(int i = 0; i < strings.size(); ++i)
        result += strings[i];
    return result;
}

  Show me the same function implemented in C and explain how it would be
easier for a beginner (especially without any danger of memory leaks).

  And here I didn't even get to the things that the C standard library
doesn't support.

-- 
                                                          - Warp


Post a reply to this message

From: Kevin Wampler
Subject: Re: Coding in ___ is like ___
Date: 26 Feb 2010 12:37:45
Message: <4b8806e9$1@news.povray.org>
Darren New wrote:
> Kevin Wampler wrote:
>> One of these days I'm going to learn it just because I'm curious about 
>> it, but I haven't gotten around to it yet.
> 
> It's sort of like Perl, only more ... tabular, somehow. People don't use 
> it any more because computers are powerful enough to run things like 
> Perl now.
> 

As I understand it's pattern matching uses a recursive backtracking 
algorithm, which should give it a bit of a Prolog flavor too.  This 
seems distinct from the Perl way of doing things (although historically 
the latter seems to won out as being more useful in practice).

Not that I know SNOBOL or Perl mind you, so I'm talking based mostly on 
my impressions of Icon and Ruby respectively plus a bit of extra reading.


Post a reply to this message

From: Jim Henderson
Subject: Re: Coding in ___ is like ___
Date: 26 Feb 2010 12:52:44
Message: <4b880a6c$1@news.povray.org>
On Thu, 25 Feb 2010 23:11:33 -0800, Kevin Wampler wrote:

> Jim Henderson wrote:
>> On Thu, 25 Feb 2010 19:15:40 -0800, Kevin Wampler wrote:
>> 
>>> On 02/25/2010 05:20 PM, Jim Henderson wrote:
>>>>> http://web.mit.edu/~axch/www/writing_rant.html
>>>> He missed "Pseudocode", which I'd write as:
>>>>
>>>> Coding in pseudocode is like a metaphor.
>>> I like it! (although given your sentence construction shouldn't that
>>> be "simile", or alternatively "Coding in pseudocode is a metaphor"?)
>> 
>> Technically, I guess "simile" would be correct there - I always get the
>> two mixed up.  :-)
> 
> At least I have something to show for all the effort my teachers spent
> hammering the difference into my head!

LOL


Post a reply to this message

From: Darren New
Subject: Re: Coding in ___ is like ___
Date: 26 Feb 2010 13:08:26
Message: <4b880e1a$1@news.povray.org>
Warp wrote:
>   Why would a beginner need to deal with constructors, destructors,
> exceptions and the like?

Because they'll be using libraries that require such.  Even in your example, 
you'd have to talk about the std::string constructor and how it creates an 
empty string if you don't pass it arguments. As opposed to (say) integers, 
that don't get initialized to zero. And what happens if you run out of 
memory in your concatenate function.

>   No, C is a lot more complicated for the beginner precisely because it's
> less powerful.

I disagree. It's more complicated to get things done, but easier to understand.

> std::string concatenate(const std::vector<std::string>& strings)
> {
>     std::string result:
>     for(int i = 0; i < strings.size(); ++i)
>         result += strings[i];
>     return result;
> }



>   Show me the same function implemented in C and explain how it would be
> easier for a beginner (especially without any danger of memory leaks).

It would be easier to explain what's happening. I don't have to explain the 
syntax for method invocation, const, references, the difference between 
references and pointers, the differences between method invocations on 
references and pointers, overloaded operators, or what namespaces are. The 
function will be longer and more dangerous, but the only "unusual" things to 
be explained are pointers and strings. Basically, in the C equivalent, the 
only *confusing* part is that C doesn't allocate multi-word objects for you.

I take it you've never actually taught beginner computer programming 
classes, yes?

It's not "how much power do you have."  It's "how much do you have to 
dismiss as magic before you have a full understanding of the entire language."

-- 
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

From: Warp
Subject: Re: Coding in ___ is like ___
Date: 26 Feb 2010 13:59:50
Message: <4b881a25@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> Warp wrote:
> >   Why would a beginner need to deal with constructors, destructors,
> > exceptions and the like?

> Because they'll be using libraries that require such.  Even in your example, 
> you'd have to talk about the std::string constructor and how it creates an 
> empty string if you don't pass it arguments.

  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".

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

> As opposed to (say) integers, that don't get initialized to zero.

  Well, in C++ they decided that if you don't initialize an integer, its
value is not guaranteed. Bummer, but nothing to do with constructors.

> And what happens if you run out of 
> memory in your concatenate function.

  Your program will be ended because it ran out of memory.

> >   No, C is a lot more complicated for the beginner precisely because it's
> > less powerful.

> I disagree. It's more complicated to get things done, but easier to understand.

  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.)

> 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?

> 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.)

> const, references

  The C version will also have a const (the function should take a const
pointer) if it's well written. So it's not all that different.

  If you really want to avoid the reference in the C++ version, you can:

    std::string concatenate(std::vector<string> strings)
    {
        ...
    }

  It will still work (although will probably be less efficient). No such
luck in C, though. You can't pass an array of strings by value. You'll
have to have a pointer (a const one, preferably).

> the difference between references and pointers

  You don't need to know the difference between references and pointers in
order to implement the "concatenate" function in my example. (And as
mentioned, you don't *necessarily* even need references at all if you
really want to avoid them.)

> 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.

> 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.

> The 
> function will be longer and more dangerous, but the only "unusual" things to 
> be explained are pointers and strings.

  No. The C version would require explaining lots of things about how C
null-terminated strings work internally (which you don't have to with
std::string), how you allocate space for them in your code (which you don't
have to with std::string), how you make sure you have allocated enough space
for the result (again, no need with std::string) and how you concatenate
the strings with strcat (the only thing more or less equivalent to the
+ operator of std::string).

  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.)

  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.

> 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.

-- 
                                                          - Warp


Post a reply to this message

From: Darren New
Subject: Re: Coding in ___ is like ___
Date: 26 Feb 2010 14:09:44
Message: <4b881c78$1@news.povray.org>
Kevin Wampler wrote:
> As I understand it's pattern matching uses a recursive backtracking 
> algorithm, 

Now that you mention it, yes, I remmber that.

-- 
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

<<< Previous 10 Messages Goto Latest 10 Messages Next 10 Messages >>>

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