Jump to content

View more

Image of the Day

Adding some finishing touches...
Follow us for more
#screenshotsaturday #indiedev... by #MakeGoodGames https://t.co/Otbwywbm3a
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

C First?

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • This topic is locked This topic is locked
49 replies to this topic

#41 Cornstalks   Members   

7030
Like
0Likes
Like

Posted 08 February 2012 - 06:41 PM

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

Any language whose standard isn't riddled with the words "undefined behavior."
[ 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 ]

#42 Servant of the Lord   Members   

33700
Like
0Likes
Like

Posted 08 February 2012 - 08:24 PM

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! Posted Image

[Edit:] Even better:

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

std::cout << product;

It's perfectly fine to abbreviate my username to 'Servant' or 'SotL' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal | [Fly with me on Twitter]

#43 Slavik81   Members   

360
Like
0Likes
Like

Posted 09 February 2012 - 02:59 PM

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.

#44 AllEightUp   Moderators   

5773
Like
0Likes
Like

Posted 11 February 2012 - 08:25 PM

First off, learn "C" in the context of "C++".

But... why???

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.



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.


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.

#45 Telastyn   Members   

3777
Like
0Likes
Like

Posted 11 February 2012 - 08:58 PM

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

#46 AllEightUp   Moderators   

5773
Like
0Likes
Like

Posted 11 February 2012 - 09:44 PM

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

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.

#47 AllEightUp   Moderators   

5773
Like
0Likes
Like

Posted 11 February 2012 - 10:07 PM

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.

#48 AllEightUp   Moderators   

5773
Like
-1Likes
Like

Posted 11 February 2012 - 10:18 PM

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.

#49 Washu   Senior Moderators   

7819
Like
0Likes
Like

Posted 11 February 2012 - 10:42 PM

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.

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

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.
ScapeCode - Blog | SlimDX


#50 AllEightUp   Moderators   

5773
Like
-7Likes
Like

Posted 12 February 2012 - 12:42 AM

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.

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:

Sorry to say, but that's silly also. The first and only requirement HAS to be that there is a program able to convert compliant source code to executable code. This must absolutely be the core of everything. That of course is vc/gcc/clang/etc compilers. The "core" language is all those restricted keywords previously mentioned. (20ish keywords for C, 30ish for C++) "EVERYTHING" else is built off that core.

Yes, C99 for instance includes the idea that "stdint.h" included all the "int8/32_t" types and for a long time MSVC never conformed. But, it was a fully compliant C99 "compiler", only the libraries/headers were lacking. The "standards" allow this variation, so long as the core language itself (i.e. understood by the compiler) supports the proper keywords and behaves properly. So, MS could claim to have a fully C99 compatible compiler (core language/ability) yet continue to piss everyone off with half assed C99 support in the SDK's.

All said and done, if you don't understand what I mean by "core language" at this point, well... Sorry..




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.