C First?

Started by
48 comments, last by All8Up 12 years, 2 months ago

[quote name='SiCrane' timestamp='1328737987' post='4911080']
One thing that gets me about a lot of these posts is that they're approaching this from the direction of C or C++ as a first language for programming, which is a horrible idea for both languages. A lot of the arguments used on both sides aren't particularly applicable if someone learns programming with an actual sane language first and only then goes after C or C++.

What do you mean by 'a sane language'?
[/quote]
Any language whose standard isn't riddled with the words "undefined behavior."
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
Advertisement
std::vector<int> vec;
vec.push_back(1);
vec.push_back(2);
vec.push_back(3);
int product = 1;
for(std::vector<int>::iterator it = vec.begin(); it != vec.end(); ++it)
{
product = product * (*it);
}
std::cout << sum;



C++11:
std::vector<int> vec = {1, 2, 3, 4};

int product = 1;
for(int value: vec)
{
product *= value;
}

std::cout << product;


I win! tongue.png

[Edit:] Even better:


int product = 1;
for(int value: {1, 2, 3, 4})
{
product *= value;
}

std::cout << product;
(Never mind, it was a bad joke anyway...)

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.


One thing that gets me about a lot of these posts is that they're approaching this from the direction of C or C++ as a first language for programming, which is a horrible idea for both languages. A lot of the arguments used on both sides aren't particularly applicable if someone learns programming with an actual sane language first and only then goes after C or C++.

I found this very interesting. Python as a First Language:
http://mcsp.wartburg.edu/zelle/python/python-first.html

I have to say, I think I agree with it on a number of fronts.

[quote name='AllEightUp' timestamp='1328706617' post='4910880']
[quote name='Cornstalks' timestamp='1328671639' post='4910754']
[quote name='AllEightUp' timestamp='1328669158' post='4910744']
First off, learn "C" in the context of "C++".

But... why???
[/quote]
The question is "learn C before C++?", take the baby steps into C++ but learn the core language "FIRST". All the rest of your arguments get the same answer: "because you need to learn the basics first". Do so in the context of C++ so you are not learning the wrong things since, as you say, the languages *are* different to a certain degree. The whole pointer thing was just a very common basic missed knowledge that continually comes up, so I suggest learning that specifically if nothing else.
[/quote]


Isn't it kinda like suggesting people learn French before learning English? They share a number of words and use the same alphabet, but are completely different languages. Sure, knowing one will make learning the other a bit easier, but it seems like a downright wasteful use of time.
[/quote]

Absolutely not. C and C++ share the same basic core language with minor differences, so I don't see the issue. I can write anything I normally write in C++ by using the "subset" which is C. There are a couple issues going backwards but they are generally minor. So I really don't see the French versus English being even vaguely correct. It is not much different than trying to write C without any support libraries versus writing C and using the libraries. Each step in the chain B/C/C++ makes things easier as you upgrade, but the core of the language is still "mostly" the same. Yes, there are differences, but as I stated, learn it within the context of the newest and best variation, just to learn the core of the language before moving forward.
If you think that c++ has a c core, you're not writing good c++ code. Modern idiomatic c++ has diverged wide and far from "c with classes".

[quote name='Tachikoma' timestamp='1328678773' post='4910785']
In all honestly, I can only speak for myself here. The learning approach I mentioned earlier was very useful, particularly syntax part. When you have never written a line of code before, syntax is everything, and learning it is one of the first fundamental steps for understanding what you are looking at. And when you switch over to some other language with a familiar syntax, learning that will be also a hell of a lot easier. I probably would have struggled with C++ if it weren't for C.

And yet, you didn't have to learn B in order to learn C. But yes, syntactically understanding one language will usually help in parsing and reading another language, and I have no doubt that your knowledge of C helped you when learning C++.
[/quote]
Actually I did learn B first (kinda, not very well), then moved to C, then to C++. The core of the language, the way you write simple code, etc, is the same in all cases. The expanded techniques such as replacing arrays with STL containers, avoiding raw pointers almost completely , etc etc etc. Those are just expansions of what B started out as. B was mostly a formalization of common assembly "patterns" in it's time, C pulled in high level concepts (at that time) and C++ is pulling in higher level concepts to this day. But the core of the language has remained fairly consistent with only minor changes/upgrades and differences.

Yes, learning C++ means learning C++ but you need to learn things with some form of basic to advanced patterning. If you don't know how to write a std::vector styled managed buffer and simply learn to use std::vector, you will miss a very basic "common" piece of coding that you really should know how to do within the language. (I.e. if they come from Python, Lua, Java, etc, pointers and memory management are going to be new to them.) Stl doesn't fit all uses, they should be able to do it manually when/if needed to customize things to needs.

I'll backstep just a bit, and say that learning C before C++ is just a manner to learn the core language (no it is NOT French versus English) instead of starting from day one relying on stl and related (boost, etc). What I mean is that if, as the original question mentioned, you know how to program in other languages, then the one and only goal of learning C before C++ is to re attune your standard everyday algorithm coding to the new core language. There is no "foreach" if you came from other languages (ignoring boost), you need to learn to deal with that, there is no "ToString" in most cases, get used to it, etc etc etc.. Those are simply two obvious examples, there are hundreds or thousands of things you should be able to do in ANY language without relying on libraries if the need arises, if you can't, you are a very limited programmer in that language.

Maybe this helps narrow down the "but why" further. Before I jump into any language I write "hello world", then I write a simple "sort algo" then etc etc. Usually it only takes a couple hours to go through that stuff. The idea is to get fundamentally comfortable with the new syntax, way to think in the language etc. But, for someone coming from another language I always suggest just C which removes all the class/template/library/etc stuff from consideration, just learn the core way to think/write code in the language.

Moving to C++ might be a couple hours for some folks and may be days for others. The "fundamental" thought process of C and C++ is much lower than many other languages, "if" you have a problem not solved by common libraries.

One thing that gets me about a lot of these posts is that they're approaching this from the direction of C or C++ as a first language for programming, which is a horrible idea for both languages. A lot of the arguments used on both sides aren't particularly applicable if someone learns programming with an actual sane language first and only then goes after C or C++.

Totally agree'd, pretty sure the first post said "programs in other language". Hence, hopefully my follow up posts cleared up why "I" think programming in C first makes sense. As a first language without school to drive things, please don't learn C/C++, that's just scary.

If you think that c++ has a c core, you're not writing good c++ code. Modern idiomatic c++ has diverged wide and far from "c with classes".

That's just a silly comment. C++ "has" a core, it is the basic set of reserved words in the language which you can not use as variable names. C++ is only 10-15 more reserved words than C and only a couple of the originals have changed meaning in any notable manner. Libraries are written with the language, they are not "part" of the core language though, they are standard support "code", not language.

[quote name='Telastyn' timestamp='1329015497' post='4912160']
If you think that c++ has a c core, you're not writing good c++ code. Modern idiomatic c++ has diverged wide and far from "c with classes".

That's just a silly comment. C++ "has" a core, it is the basic set of reserved words in the language which you can not use as variable names. C++ is only 10-15 more reserved words than C and only a couple of the originals have changed meaning in any notable manner. Libraries are written with the language, they are not "part" of the core language though, they are standard support "code", not language.
[/quote]
A language, at least any standardized language, is defined by it's standard. Not by your wishes, or your definitions, or anything like that. By it's standard. In this case we're talking about the C++ standard, which, as of right now, is 14882-2011. Now, the nice thing about standardized languages is we can ASK the standard of the language to tell us what a conformant implementation of the standard is. Interestingly enough the C++ standard happens to include such a section, in which it states, and this is a direct quote of section 1.4 paragraph 7:


Two kinds of implementations are defined: a hosted implementation and a freestanding implementation. For
a hosted implementation, this International Standard defines the set of available libraries. A freestanding
implementation is one in which execution may take place without the benefit of an operating system, and
has an implementation-defined set of libraries that includes certain language-support libraries (17.6.1.3).
[/quote]
Section 17.6.1.3 is even more explicit, as it even names the required headers for freestanding implementations.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

This topic is closed to new replies.

Advertisement