|
C and C++ are very different from C# and Java - both in purpose and semantics.
|
|
|
|
|
The same could be said of C++ and C.
Len
|
|
|
|
|
LeonardReinhart wrote: The same could be said of C++ and C.
Not really - they are both system languages and C++ is designed to be a "better C" among other things.
C# and Java on the other hand are both geared towards enterprise application development, they run on virtual machines, have garbage collectors and similar object models.
|
|
|
|
|
C++ is object oriented. That is a completely new concept. I use C and C++ for very different things. Java, C# and VB.net I would use for similar things (conceptually) I prefer C# and VB.net.
Len
|
|
|
|
|
LeonardReinhart wrote: C++ is object oriented.
C++ is not "object oriented". It supports OO among other things[^], but it is designed to be multi-paradigm.
LeonardReinhart wrote: I use C and C++ for very different things.
Why? The only reason I would compile anything with a C compiler today would be the lack of a C++ compiler for that platform. It is perfectly OK to use C++ as a "better C" without writing any object-oriented or generic code.
LeonardReinhart wrote: Java, C# and VB.net I would use for similar things (conceptually)
That is understandable - they are designed to be used for similar purposes.
|
|
|
|
|
C++ is designed to support object oriented programming. It is much more complex than C. I use C for small embedded projects. I believe there was some effort at producing an Embedded C++. Reading the rational for what was stripped out of C++ to get to Embedded C++ would lead to a better understanding of why C and C++ are different enough not to mix.
Len
|
|
|
|
|
LeonardReinhart wrote: C++ is designed to support object oriented programming
...among other things.
LeonardReinhart wrote: It is much more complex than C.
It is, but nothing mandates the use of these complex features. You can use C++ the same way you would use C with a benefit of the stronger type system.
LeonardReinhart wrote: why C and C++ are different enough not to mix.
I am not talking about "mixing" them, but using C++ as a better C.
|
|
|
|
|
The C++ compiler does unexpected things, there are a number of features introduced in the C++ language that is not good for a deterministic, fast, small embedded system. Spend a little time looking at what was stripped from C++ to make Embedded C++. C++ is not a better C. One of problems with C++ is that it tried to maintain some backward compatability with the C language.
Len
|
|
|
|
|
|
jlac1024 wrote: Ah, but semantically they're all nearly identical.
C# and Java, yes. C++ is very different from them.
jlac1024 wrote: The whole point is to learn how to define variables, use logic and logic tables for if/else/whatever statements, and basics of loops.
How about scopes and lifetime of objects? Then passing by value vs. reference? Destructors? Copy semantics?
jlac1024 wrote: Define an 32 bit integer in all 4 languages and tell me which one is different.
C: int32_t i;
C++: // no way to portably declare a 32-bit integer in standard C++ (will be the same as in C soon)
C#: int i;
Java int i;
|
|
|
|
|
|
jlac1024 wrote: However, if I say "define an integer variable" in all 4, would you be complacent enough to define it in the simplest terms and without fuss? This is, after all, a means for learning how to program and not the ins and outs of it.
How about declaring a string in all 4 languages?
|
|
|
|
|
jlac1024 wrote: Learning how to program would be nearly the same in everything based from C-style syntax.
Oh, no. No, that's just not true.
You might as well say, learning to write poetry is nearly the same for every verse form provided you use English words.
Citizen 20.1.01 'The question is,' said Humpty Dumpty, 'which is to be master - that's all.'
|
|
|
|
|
|
jlac1024 wrote: Again, we're not talking about making a full fledged application or tools associated with it, merely an understanding of the fundamentals in what you need to know to accomplish those things
C supports pointer arithmetic and preprocessor macros - Javascript and C# do not. JS and C# support lambda expressions - C does not. Floating-point arithmetic differs widely. C# supports initializer lists for objects, JS is built on associative containers and first-class functions with literal syntax for both, C supports static initializers for structures... Both C# and JS have some sort of garbage-collection as an integral part of the language, while C requires library support for any heap-allocated storage and leaves both allocation and deallocation to the programmer. Etc...
Writing C#-style code in C is a great way to write terrible, flaky software. Writing C-style code in C# is a great way to write terrible, verbose, unsafe, and unreadable C# code. Using either style when writing JS code is gonna produce slow, ultra-verbose code. Worse yet, all of these practices exchange the advantages of the respective target language for the limitations of the source language. The worst [C|C++|Java|Javascript|C#|...] programmers tend to be those that think they already know the language because they've learned some other C-style language in the past. The fact that you can write C-style code in C++ without serious penalty is the only reason why they can be grouped, but even then you're obviously failing to take advantage of the language even if you aren't actually suffering any real harm in not using a dedicated C compiler.
Citizen 20.1.01 'The question is,' said Humpty Dumpty, 'which is to be master - that's all.'
|
|
|
|
|
|
jlac1024 wrote: Reads: Learn the >_fundamentals_< of programming.
Which fundamentals are those?
Want to demonstrate a loop? C and C# support goto , Java and JS do not. C#, JS, and Java support labelled continue s, while C does not.
Want to demonstrate a conditional statement? Evaluation of expressions and boolean types differs, sometimes subtly, between languages.
Want to demonstrate subroutines? C has functions. JS has a totally different sort of function. Java has methods, which are similar - but not at all identical - to functions in C. C# has methods which are probably closest to Java methods than they are to anything else, and lambda expressions which are implememted by the compiler as methods on annoymous types...
jlac1024 wrote: I don't know about you, but I didn't start out writing commercial applications. Unless, "Hello world!" is commercial.
"Hello World" often depends on some library support as well, and therefore differs greatly across languages and platforms. Rarely does it actually demonstrate any useful programming concepts beyond those required to represent a simple program - in the target language - and call a library method with a string - using the target language and platform.
Citizen 20.1.01 'The question is,' said Humpty Dumpty, 'which is to be master - that's all.'
|
|
|
|
|
|
jlac1024 wrote: Declare an integer variable.
Eight or so integer types in C; nine in C#; five in Java; one in Javascript (but JS doesn't really use anything close to the same type system, so the comparison is even less straightforward).
jlac1024 wrote: Compare to integer variables and do an action of your choice if they are the same.
Which languages will this work in: if ( !(a-b) ) action();
Which languages will this work in: if ( a === b ) action();
Which languages might this not work in: if ( a == b ) action();
jlac1024 wrote: Give me an example of a loop of your choice.
Which languages will this work in: for each (var o in ['yes', 'no', 'maybe', 'so']) action(o);
How about this one: foreach (string s in (new string[] {"yes", "no", "maybe", "so"})) action(s);
Those two are both fundamental constructs in at least one C-syntax language.
Citizen 20.1.01 'The question is,' said Humpty Dumpty, 'which is to be master - that's all.'
|
|
|
|
|
|
jlac1024 wrote: What does that get you in all of them?
Javascript: SyntaxError: missing ; before statement
Others: an integer variable of system- and platform-defined size, with storage and scope dependent language and context.
jlac1024 wrote: What does that get you in all of them? An integer variable(regardless of the type -- being 8 bit, 16 bit, 32 bit, 64 bit, 1024 bit, etc)
How are you going to talk about the fundamentals of programming and then imply that it's ok to ignore the size of an integer?!
jlac1024 wrote: All of them, however, if you pick up a "learn C++\Java\C#\C in 25 seconds!" they will nearly teach you the same syntax for all of them. So grouping them up for a learning purpose is moot.
And if you don't understand the fundamental differences between what appears to be similar syntax, then you're going to be in for a world of hurt[^].
jlac1024 wrote: When teaching, you don't usually teach how to build a house without starting at how to use a hammer and nails.
Ideally, you'd start with basic things like squaring up a foundation. And I suspect you'd be remiss in not mentioning the advantages screws have over nails in many common scenarios, although i don't build houses so perhaps not. Still, i'm pretty sure that if you're gonna be using nail guns then it's probably not as important that your new worker becomes an old pro WRT the hammer method.
I expect though, that you'd really stress the difference between 3" siding nails and shingle tacks.
Citizen 20.1.01 'The question is,' said Humpty Dumpty, 'which is to be master - that's all.'
|
|
|
|
|
The difference is one of perspective.
If you just take the raw language definition, then the big difference between C and C++ is classes and templates. Its an addendum really. Certainly you can make use of C++ just like C except in Embedded applications (as noted above), but its important to note that embedded C compilers also have special aspects to them that a C compiler on Unix does not need (since issues around where the stack lives and how ram is used are much more important in embedded than they are in Unix or Windows or etc..).
The big differences aren't language differences, they are environment differences. C/C++/Embedded C/Embedded C++ are very close to the hardware, in comparison to C# and Java, which are intended to isolate the programmer more from the considerations of hardware. There is still a blend, since there is still a lot of language support for bit manipulations, etc... but its still the environmental difference which stands out to me.
|
|
|
|
|
C and C++ are totally different languages! If you ever programmed with them before you would know.
|
|
|
|
|
I'm not sure I agree, but then again, I voted for Lisp (specifically Scheme)
|
|
|
|
|
tlcouger wrote: I voted for Lisp (specifically Scheme)
Very good, but not as a first language IMHO
|
|
|
|
|