lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Wed, Apr 26, 2017 at 5:07 PM, Sean Conner <> wrote:
>   Perhaps it's because of my extensive background in Assembly and C, but
> what exactly *is* the difference between a pointer and a reference, other
> than hiding the pointer behind some syntactic surgar?

The main difference is that references can't be null or
uninitialized/invalid/pointing to a deleted object, and you can't do
pointer arithmetic on a reference. The syntax gives you no way to do
arithmetic without explicitly converting it to a pointer, and since
you can't delete or reassign a reference it's hard to get a bogus one
without explicitly doing things with pointers somewhere or taking a
reference to a temporary that goes out of scope. Admittedly the latter
one is a problem that can happen, but it's a MUCH smaller surface for

>> As mentioned upthread, there's no point in teaching C when you could
>> be teaching C++. C++ can do literally everything C can, and it can do
>> it with syntax that's much friendlier and much less error-prone.
>   Even coroutines?  Such as
> (okay, granted, it's implemented in assembly, but it works quite well for C;
> I wouldn't even know how to begin to adapt that for C++)


>   And C++ hurts your ability to reason about non-object oriented code I've
> found.  Yes, C++ is technically a multi-paradigm programming language where
> you don't *have* to use classes, but come on ... it's OOP (I am not a fan of
> OOP, just so you know where my biases lie).

This isn't really a meaningful analogy. The problem isn't a question
of changing paradigms. The problem is that C++ will let you write C
code and have it work more-or-less unchanged. When you're switching
between more distinct languages, the syntactic shift is usually enough
to defuse most of the most problematic habits, but you don't get that
benefit in the case of C -> C++, where doing C things is the fastest
way to violate all of the safety mechanisms built into C++. (C++ -> C
on the other hand works fine; your C code has structs and function
pointers where other people wouldn't use them, but you never break the
language's fundamental assumptions.)

>> High level language -> C -> assembly is really a pretty bad path
>> nowadays. The demand for assembly skill is ridiculously small. I'm a
>> CS major myself, and I've only ever written assembly for the fun of it
>> on retro systems (and an attempt to write a C++ compiler, which got
>> aborted due to the instructor vanishing).
>   What did the instructor vanishing have to do with not finishing a C++
> compiler?  Unless it was a (rather ridiculously large) class project.

It was the entire premise of the class -- the promise was that the
class would teach you every last nook and cranny of the C++ standard
by building a (eventually self-hosting) C++ compiler from the ground
up. But after first term ended, and my compiler could parse any
standards-compliant C++ code and generate symbol tables and ASTs from
it, and my assembler could take a mock language and generate x86_64
code for it, the second term never started. The instructors just
stopped answering e-mails and the site languishes abandoned to this

>> Meanwhile, modern C++ is a sufficiently high-level language that if
>> you come at it with an open mind (instead of with prejudices derived
>> from the disaster that was pre-C++11 in a world that had to support
>> Visual Studio 6 long past its obsolescence) you'll find a much more
>> modern and comfortable experience than you might have expected.
>   I still find it more verbose than Ada ever was, even today.
>   Then again, I'm old school when it comes to this stuff anyway.

No, no, verbosity is one criticism that C++ has no answer for. I agree
with you here, and that's why I think C# would be better than C++ as a
teaching language if the standard libraries weren't so obviously
influenced by Windows APIs.

>> Lua is a good lightweight general-purpose language, don't get me
>> wrong, and there's probably nothing wrong with exposing fledgling
>> programmers to it. But in terms of actually building engineering
>> skill, I think starting off with a statically-typed object-oriented
>> language is a better choice.
>   Remove "object oriented" and I would probably agree.
>   -spc (At the very least, come up with some better examples of OOP than
>         animals, vehicles or shapes)

I definitely agree that the stereotypical OOP examples are lame and I
avoided them when building my own OO curriculum for tutoring a
student. Building a GUI is a MUCH better and much more realistic
application of object-oriented code than animals, vehicles, and

/s/ Adam