Regarding C and C++ (64)

1 Name: #!/usr/bin/anonymous : 2008-05-04 22:04 ID:wFp9lX0t

In which order should one learn those languages? C goes first, or C++?
Any essential advise you could give me? Books, docs, good source code?

Thanks and best regards

2 Name: #!/usr/bin/anonymous : 2008-05-04 23:02 ID:ZD8VERXJ

C++ is pretty much C with more. Just learn C++, skip C.

3 Name: #!/usr/bin/anonymous : 2008-05-04 23:42 ID:EBpV+i10

C++ is pretty much C with a lot of dumb crap. Just learn C, don't bother with C++.

4 Name: #!/usr/bin/anonymous : 2008-05-04 23:48 ID:rX0YMtxO

>>1

Hey OP. You will surely get a lot of responses or different opinions on this,

and perhaps that will get you confused. >>2 concludes that you should skip C and
learn C++, based on that C is a subset of C++. However, that is not correct. C
has a lot of differences with C++, which are sometimes quite subtle. You will
find a wonderful page that explains all this here:
<a href="http://david.tribble.com/text/cdiffs.htm">Incompabilities between ISO C and ISO C++</a>
All these are too advanced for you, but just looking at the size of that page,
you can be sure that >>2 is wrong. That, however, does not mean that learning
C++ before C is wrong.

My suggestion is that you go with C first. C is a lot smaller than C++, so

you'll get to completely understand what happends in a C program a lot faster. C
is also more "stable". There's a new C++ standard coming out around 2009. If you
don't know what a standard is, it's okay. Just understand that what you might
learn now about C++ you might have to re-learn in 2009. By 2009, if you take the
C path, you should be a good C programmer, <i>if</i> you follow my advice on
what books to pick and read. Generally, learning either language is no easy
task. Learning a language doesn't mean to be able to write 10 or 20 lines of
code in it. It means to be able to read any code and being able to tell what
happends in every line. Not what the programmer intented to do, but what the
compiler will understand. There's <i>too</i> many C programmers out there that
don't really know C. At all. Which is sad, do not end up like them. Every time
you wonder whether you at last know C or not, ask yourself this:
<i>Do I know most of what's written in ISO 9899:1999?</i>
If you can, then you do. When that time comes, it's up to you to learn C++.

As for the advice, here's my advice:

Obviously go with C. Get books such as K&R - The C programming language, or H&S
C: a reference manual 5th edition. Read them, do the exercises, be patient. It
should take at least 6 months to learn C. When and if you feel like completely
mastering the language, click the third link, and get the C99 standard,
available for free in pdf form (should be called WG14 N1124).

<a href="http://cm.bell-labs.com/cm/cs/cbook/">The C programming language</a>
<a href="http://careferencemanual.com/">C: A reference manual</a>
<a href="http://www.open-std.org/jtc1/sc22/wg14/">ISO/IEC JTC1/SC22/WG14</a>

P.S. Don't give up. When this journey comes to its end a lot of doors will

open, you'll be able to read about most concepts around computers.

5 Name: #!/usr/bin/anonymous : 2008-05-04 23:50 ID:Heaven

>>4
Sorry, I forgot HTML. Here's how the message should've appeared:

Hey OP. You will surely get a lot of responses or different opinions on this,
and perhaps that will get you confused. >>2 concludes that you should skip C and
learn C++, based on that C is a subset of C++. However, that is not correct. C
has a lot of differences with C++, which are sometimes quite subtle. You will
find a wonderful page that explains all this here:
Incompabilities between ISO C and ISO C++
All these are too advanced for you, but just looking at the size of that page,
you can be sure that >>2 is wrong. That, however, does not mean that learning
C++ before C is wrong.

My suggestion is that you go with C first. C is a lot smaller than C++, so
you'll get to completely understand what happends in a C program a lot faster. C
is also more "stable". There's a new C++ standard coming out around 2009. If you
don't know what a standard is, it's okay. Just understand that what you might
learn now about C++ you might have to re-learn in 2009. By 2009, if you take the
C path, you should be a good C programmer, if you follow my advice on
what books to pick and read. Generally, learning either language is no easy
task. Learning a language doesn't mean to be able to write 10 or 20 lines of
code in it. It means to be able to read any code and being able to tell what
happends in every line. Not what the programmer intented to do, but what the
compiler will understand. There's too many C programmers out there that
don't really know C. At all. Which is sad, do not end up like them. Every time
you wonder whether you at last know C or not, ask yourself this:
Do I know most of what's written in ISO 9899:1999?
If you can, then you do. When that time comes, it's up to you to learn C++.

As for the advice, here's my advice:
Obviously go with C. Get books such as K&R - The C programming language, or H&S
C: a reference manual 5th edition. Read them, do the exercises, be patient. It
should take at least 6 months to learn C. When and if you feel like completely
mastering the language, click the third link, and get the C99 standard,
available for free in pdf form (should be called WG14 N1124).

The C programming language
C: A reference manual
ISO/IEC JTC1/SC22/WG14

P.S. Don't give up. When this journey comes to its end a lot of doors will
open, you'll be able to read about most concepts around computers.

6 Name: #!/usr/bin/anonymous : 2008-05-05 00:16 ID:Heaven

go with c. c++ was built for large-scale heavy duty apps involving many programmers. everything thats in c++ not in c serves that purpose.
programming in c by kochan is a great book.

7 Name: #!/usr/bin/anonymous : 2008-05-05 00:26 ID:rX0YMtxO

Just how the hell can I compile scheme or common lisp to actual executables?

8 Name: #!/usr/bin/anonymous : 2008-05-05 00:41 ID:Q5bXlgbg

>>7 Depends on the compiler, becuase that particular feature isn't standardized.

In SBCL you use:

(sb-ext:save-lisp-and-die "filename" :executable t)

In ECL you use:

(c::build-program "filename"
:lisp-files (list (compile-file-pathname "file.lisp" :type :object)))

In MZScheme you can use "mzc" to compile:

mzc --prim --exe src.ss

9 Name: #!/usr/bin/anonymous : 2008-05-05 00:44 ID:Heaven

Lispworks has a special "application builder" which not only compiles but prepares the application for distribution by removing definitions that aren't used. I think ACL has something similar.

The reason this "feature" isn't easy to figure out is because it isn't a normal part of Lisp application development. The fact that you're trying to figure this out first lends itself to the idea you're trying to figure out how to Lisp using your C/C++ knowledge. You probably want a build procedure kindof like C/C++ where you "build" your application as a separate state from developing it.

Don't do that. By the time you have an application you want to deliver in exe-form to other people, it'll be a lot easier to explain. Waste your time trying to figure this out now and you're just going to frustrate yourself needlessly, and you're going to avoid "getting" some of the most useful aspects of Lisp programming.

10 Name: 7 : 2008-05-05 00:48 ID:Heaven

>>8,9
That post >>7 was for http://4-ch.net/code/kareha.pl/1209513777 this thread. Sorry

11 Name: #!/usr/bin/anonymous : 2008-05-05 12:18 ID:kyJ8Nbmx

>>5
Thank you very much for your informing reply.

12 Name: #!/usr/bin/anonymous : 2008-05-07 08:48 ID:Heaven

>>1

Let C kick your ass for a good amount of time before moving over to any object oriented languages

13 Name: #!/usr/bin/anonymous : 2008-05-08 14:34 ID:TfePZxUZ

OP here, I checked few C books and "The C Programming Language" was the most unclear one. I learned the basics of C before, but never beyond them, and the book I mentioned above looks more like a style guide, having the ANSI C code in it. Should I stick to this book though I don't get it, or continue through another, not ANSI C but more clear ones? I can always go back to it after I learned a fair amount to improve my coding style.

Thanks again

14 Name: #!/usr/bin/anonymous : 2008-05-08 19:22 ID:Heaven

FUCK YOU 4-CH.NET.
I WROTE THIS GOD DAMN HUGE REPLY TO OP AND WHAT DO I GET IN REPLY?
MY COMMENT WAS TOO LONG BY 1200 CHARACTERS. BECAUSE I WROTE THIS WITH w3m
NOW I HAVE TO REWRITE IT. NO. FUCK YOU 4-CH, FUCK YOU.

15 Name: #!/usr/bin/anonymous : 2008-05-08 19:29 ID:Heaven

>>14

Maybe you should get a real browser.

16 Name: #!/usr/bin/anonymous : 2008-05-08 20:50 ID:Heaven

>>5,14 here. I will attempt to write my post again, posting in parts.

>>13
OP here, I checked few C books and "The C Programming Language" was the
most unclear one. I learned the basics of C before, but never beyond
them, and the book I mentioned above looks more like a style guide,
having the ANSI C code in it.


Which books have you checked? As a rather experienced C programmer, I can tell
you right now that K&R is crystal clear. Please post further details, such as
the paragraphs/sentences that you found unclear, the other books that you have
read and anything that will aid us in helping you better. C does not have
basic and complex semantics. There are only two types of C
programmers in this world: those who know C and those who think they do. Feel
free to join the latter group, though I don't advice it for a number of reasons.
Please follow my advice, or any reasonable advice for that matter. K&R is
not a style guide. It appears that you are rather confused about what
programming standards are, so please let me explain.

17 Name: #!/usr/bin/anonymous : 2008-05-08 20:50 ID:Heaven

When C was first visualized and conceptualized by Kernigham and Ritchie (surely
and others too, such as K. Thompson, who played an important role in C's history)
they had to introduce the language to other programmers. As such, they decided
to document its features as best as they could, and they wrote a book called
"The C programming language", also known as K&R1. The book standed as a
reference and guide to anyone interested in C programming. Every compiler
developer or programmer was using <i>the de facto</i> book to learn C and study its
aspects. The book was quite ambiguous, and incomplete in many ways. As such,
different compilers behaved differently, and different programmers wrote
different code. The implementation was unclear, and the diagnostic messages
where absent. It was hard to tell whether a bug was in the implementation or the
programmers fault, because there was no "official" reference. C was an
unofficial language used by hackers (not in todays sense hackers). So where do
the standards come in? A standard thoroughly and exhaustingly documents a
subject, and sets the <i>rules</i>. Anyone who is interested in the subject is
expected to use the standard as a reference. ANSI decided to publish a standard
on C, commonly known as C89 (though its official name is ANSI X3.159-1989). The
document was clear and well thought, and compilers quickly adopted it. Now, it
was easy to tell whether an implementation was conforming or not, because the
rules of the standard made all implementations behave the same; That does not
mean it limited their functionality, but rather, it documented the very
functionality expected! You could write code for system/operating system A and
expect it to behave the same on B. However, there were problems with that
standard too, as it wasn't available to the average Joe because it was quite
expensive. Moreover, it could not be used as a tutorial for the language.
Kernighan and Ritchie decided to write another book, K&R2, which served as an
introduction, tutorial, guide and reference to ANSI C. The second book was
<i>excellent</i> and sold millions of copies. Now, almost 20 years later, the
book still stands as an excellent resource for C, and one of the best books
written for it. Still, there were problems with ANSI C. The standard was not
widely available because ANSI is not an international organization. ISO decided
to take charge of C, and published ISO 9899:1990, 9899:1995 and 9899:1999. (also
known as C90, C95 and C99) in chorological order. ISO made C99 freely available
in pdf form. Standards are not only for programming language; they can, for
example, document a file type, such as JPEG; or the representation of
floating-point values in computing. Indeed, there are; Former as ISO 10918-1 and
latter as IEEE-754, which are also widely used.

18 Name: #!/usr/bin/anonymous : 2008-05-08 20:51 ID:Heaven

So, do ask yourself now, <i>should I read a book written 20 years ago that's still
appreciated by experts worldwide, or shall I read a tutorial I found on some
fools blog?</i>
Do not fall into the hedonically appealing temptation of taking the sunny road.
Take my advice as is, read K&R (the alternative is to read H&S). Study, be
patient. Otherwise, you'll be of the second kind of C programmers, which will
also reflect on you as a whole; You'll be a <i>lazy</i> programmer, that prefers
the job done quickly, than the job done properly. Such programmers serve no real
purpose, one could rightfully claim that they don't belong in the computer
world. If C seems to hard for you, try PHP or similar first. Get a sense of what
writing in an imperative programming language feels like, and then try C agai

<dd><blockquote>Should I stick to this book though I don't get it, or continue
through another, not ANSI C but more clear ones? I can always go back to
it after I learned a fair amount to improve my coding style.</blockquote></dd>

You got an answer in the previous paragraph for this question, but I shall
repeat just in case. ANSI C is not a coding style, it's a standard. K&R merely
adheres that standard and explains its virtues. A C book that doesn't adhere to
a C standard is quite useless. You can indeed go back, but when you pass the
point of no return, turning back seems so distant. <i>Do you know what that is,
OP? That's the point in a journey where it's longer to go back to the
beginning. It's like when those astronauts got in trouble. Somebody messed up,
and they had to get them back to Earth. But they had passed the point of no return.
They were on the other side of the moon and were out of contact for like hours.
Everybody waited to see if a bunch of dead guys in a can would pop out the other
side. Well, that's me. I'm on the other side of the moon now and everybody is
going to have to wait until I pop out.</i>
There's no reason to go that far if you intent on turning back.

<dd><blockquote>Thanks again</blockquote></dd>
You are most welcome my friend.

19 Name: #!/usr/bin/anonymous : 2008-05-08 20:51 ID:Heaven

FUCKS SAKE I GOT HTML WRONG AGAIN.
Excuse me while I suicide.

20 Name: #!/usr/bin/anonymous : 2008-05-08 22:45 ID:wodfxWfq

>>19
No problem at all, thank you very much for your replies, I really appreciate it. The things that were unclear to me solved by themselves when I switched back to gcc, an exercise that didn't work.
I have some programming experience other than C and it is not related to that - in fact, when I started self-learning programming C++ was my first pick, an advice by some friend, and I learned C along it. I soon abandoned both of them for other language picks but I had no problem learning them to a basic level. I soon started relearning C by the 'Teach yourself C in 24 days' book, but abandoned it after the 10 or so day, for an unclear reason, probably because the book was really for dummies.
My most recent language that I learned beyond the basics is Perl, that has roots in C. Somehow, after coding it some time, it feels harder to code C. I'm sure that it will improve though.
Except the material purpose, how is C going to affect my other languages knowledge, or general programming thinking? You mentioned imperative programming and not being lazy, but I heard more good things, such as a better syntax and functionality.
And a little question regarding some exercise in the book recommended by you:
How is getchar() and putchar() different from scanf() and printf()? I heard the latter consumes more time and power because it parses the variables, while getchar() and putchar() work with any type, whether it is an integer or a char.

Thanks again and best regards

21 Name: #!/usr/bin/anonymous : 2008-05-09 00:29 ID:Heaven

>>20
How is getchar() and putchar() different from scanf() and printf()? I
heard the latter consumes more time and power because it parses the
variables, while getchar() and putchar() work with any type, whether it
is an integer or a char.

Ah, such question asks for a really long reply. I'm not up for it as my fingers
hurt, however I will briefly answer.

First of all, the C standards do not mention how long a function should take. So
the implementation is free to make getchar() faster than printf(). Anyone who
would tell you that getchar() is faster than printf() has obviously never done
any low-level or kernel work; Or any real programming anyway. I don't mean to
insult or degrade your friend thought; Perhaps you misinterpreted what he had to
say, or maybe his expertise is not C and programming in general. Anyway, my
point is that the bottleneck of both getchar() and printf() is not
`parsing' the format string; It's locking the stream, it's calling the system
call, it's switching from usermode to kernel, it's writing to the disk (when
that is done). However there are certain optimizations such as buffering that's
done from all the printf(), fprintf() etc functions. (man 3 setvbuf) so it
doesn't have to switch to kernel, it doesn't have to do the system call, it
doesn't have to actually write anything to the disk (the system call itself
doesn't have to anyway). printf("%c", 'A') and putchar('A') could differ by
10.000 instructions and you couldn't be able to tell a difference on a modern
PC. You are also not aware of the bigger picture, nor all the optimizations that
the implementation might employ. So my suggestion to you is not to worry about
the function speed in standard C, but rather, if you have to worry about
efficiency, worry about the efficiency of your own functions, and be
reasonable: whether you use 'short' or 'int' won't make a difference, unless you
are coding on a micro-processor which you are not anyway. Just try to write
clear code, and don't worry about efficiency. Learn C, then learn about
algorithm complexity.

As for the last thing you said, getchar() does not work with any type. That
doesn't even make sense. the prototype for getchar is:
int getchar(void)
The description is that getchar returns the next byte read from stdin or EOF on
error or end of file. It doesn't have to do anything with types;
Moreover, char is an integer; char is not int, but char is an integer. short,
int, long are also integers. float and double are floating-point types. Get it?

22 Name: #!/usr/bin/anonymous : 2008-05-09 05:48 ID:gSVjbuys

I think the OPs initial question is flawed.

What is your goal?

If it is to learn computer programming, you should understand that C and C++ were made to solve programming problems of decade sgone by. They are old and showing their age. Better languages have been released.

If your goal is to support legacy code, or modify the linux kernel you should learn C and C++.

If you want to make modern desktop apps, then you need to go with a different langauge and/or programming platform. C++ (as a language) is ill suited for the task. By default objects are passed by value, which isn't object oriented at all. Threading (which is becomming so important these days) is a pain in the ass.

If you want to make Windows/Web/some mobile/limited Linux apps, go with C#/VB.Net and the .Net framework.

Or go with Java. The platform absolutley sucks, but the language isn't half bad.

The CS types are saying now that all languges in the future will be dynamic. So why not learn Python or similar.

23 Name: #!/usr/bin/anonymous : 2008-05-09 10:06 ID:HD27Z4Bc

>>21
Got it.
>>22
My goal is to prepare for an actual job. It is a bit early for me, but as a person who just learned most languages and almost never did a whole big program used by someone, I want to do so now.
I saw multiple languages used on Sourceforge, C++ the most popular among them. But now that you mention the actual usability in real world, C and C++ lose their stance as a strongly used language. The world is advancing, perhaps the kernel will be rewritten in another, more modern language, or we will use some other GNU/Kernel written in Java or C#.
Everyone are spitting around 'Learn C' or 'Learn Scheme/Lisp/Haskell', so I thought there's more magic behind programming, but now I understand it won't help me in my current level.
A functional language for me is a language that is used in real life, beyond the magic of Lisp and such, and one that I can code for fun and profit in on Sourceforge.
People all go 'Java is bloated' and "C#'s memory management is bad" and maybe, or it is true. But your Scheme book or the Linux kernel won't change your boss' view on your job, or the standards, in most cases.
I know it is unrelated to my first question, but how would one improve his knowledge? I lurk on the web for source code, but all I find is usually some cracker's tool Perl code, which is written badly. Yes, this question is asked really often, but I'm in that stage where exercises are simple, and bigger projects thrown at me such as 'Write a simple HTTP server' (which I understand in theory is a socket listening on a port for data) but I can't write them yet. I have to advance somehow from this begginer level, which lays between a book-reading newbie to intermediate coder which can do tasks given to him, and he doesn't question himself how to.
I really am a starter, I never participicated in a real coding job, but I am eager to do big projects, or even a one, small, open-source projects such as a module for Perl or a library, but with in my current level it seems a little less impossible than the level before.
A side note - I mentioned Sourceforge few times. I did so just because it seems the best coding area for intermediate coders, where I do not fit yet. No particular reason.

Thank you for your answers very much again, and best regards.

24 Name: #!/usr/bin/anonymous : 2008-05-09 11:35 ID:Heaven

Post split again.
>>22
What absolute twaddle.

What is your goal?

If it is to learn computer programming, you should understand that C and C++
were made to solve programming problems of decade sgone by. They are old and
showing their age. Better languages have been released.


That's absolute bullshit. C was originally written for low level work with unix.
If you believe that in 2008, unix isn't relevant anymore, you are absolutely
delusionary. C's problem is that it's too simple; it's missing things
every program would use. C++ was designed (and is) as a more complete alternative
to C. And your claim that both languages are old is outrageous! C++ isn't old!
(An example of an old language still used would be lisp, and not C or C++)


If your goal is to support legacy code, or modify the linux kernel you should
learn C and C++.

Yes you should, so you can take the legacy code and write a better portable
solution in C or C++.


If you want to make modern desktop apps, then you need to go with a different
langauge and/or programming platform. C++ (as a language) is ill suited for the
task. By default objects are passed by value, which isn't object oriented at
all. Threading (which is becomming so important these days) is a pain in the
ass.


Again, bullshit. Why is C++ ill-suited? Why would it want to be "object oriented
by default"? Objects can be passed by reference in C++ (not in C thought)

int zero(int &i) { return i = 0; }

Moreover, the new C++ standard is going to include threads, and you'd know that
if you were a C++ programmer, which apparently you are not and you're talking
out of your ass. C++ is a multi-paradigm language, and includes OOP in the list.
It's not forcing OOP down your throat.

Just when was threading not important? Please help me recall.
Also, explain briefly the issues you have encountered with libraries such as
pthreads. Do you even know when to use threads and when not?


If you want to make Windows/Web/some mobile/limited Linux apps, go with
C#/VB.Net and the .Net framework.

Why would you go with C# and .NET for linux apps? What about BSD, solaris,
other? OP: Don't learn C#.


Or go with Java. The platform absolutley sucks, but the language isn't half bad.


No, don't go with java. Stick to C as it's more portable, it's controlled by ISO
(and not Sun), it has very good implementations and it can do things Java
wouldn't imagine of (embedded programming, low level stuff).
Java sucks, but I can understand learning it. Sun is a good company. C#? C# is
horrible. It's controlled by microsoft. For fucks sake, OP, do not learn
C#. If you want, try java after learning C, do not concurrently learn them as it
might confuse you.

25 Name: #!/usr/bin/anonymous : 2008-05-09 11:35 ID:Heaven

>>22


we will use some other GNU/Kernel written in Java or C#.

OP, stop. You're making a fool of yourself. There's no such thing as GNU/Kernel.
GNU is developing a kernel, namely Hurd. It is not (and will never be) in Java
or C#. For FUCKS SAKE.



Everyone are spitting around 'Learn C' or 'Learn Scheme/Lisp/Haskell', so I
thought there's more magic behind programming, but now I understand it won't
help me in my current level.
A functional language for me is a language that is used in real life, beyond the
magic of Lisp and such, and one that I can code for fun and profit in on
Sourceforge.

There is more magic to programming, and no, you are not in a place to
understand your current situation and what programming is. A functional language
(assuming functional programming) is not what you think it is. If you meant
'functioning' as capable of performing, then tell me in what language crash
bandicoot was written in. Lisp. Amazon? Lisp. Reddit was written in lisp.
There's a 3D shooter game in Haskell, there's a superior window manager in
Haskell, and a text editor in Haskell (Yi). There are more notable projects in
lisp/haskell. Even learning lisp to discover that 'magic' is worth it. Please
understand, you're a newbie. You cannot know what's going on with programming
just because you know a bit of this and a bit of that.



I know it is unrelated to my first question, but how would one improve his
knowledge? I lurk on the web for source code, but all I find is usually some
cracker's tool Perl code, which is written badly.

R E A D B O O K S.
Not some fools code, and most exploits in perl really involve a TCP connection
and shellcode. It doesn't need to be written nicely as the actual work is to find
the exploit and then write the shellcode for it. (that's obviously only a small
portion of exploits. There are all kinds of exploits)



and bigger projects thrown at me such as 'Write a simple HTTP server' (which I
understand in theory is a socket listening on a port for data) but I can't write
them yet.

No, it's not about that. Remember what I said about standards? It's about
writing an application that conforms to what's described in rfc 2616.
It's also about doing it efficiently.
The reason you cannot write them is because you haven't taken my advice
apparently and you haven't learned C yet (only a day passed :P). When you know
C, you can move to POSIX. POSIX describes a socket interface (commonly known as
BSD sockets, because that's where it derived from - 4.2BSD). POSIX also
describes other interfaces, such as pthreads, IPC, other shit. POSIX is a
standard and there are books serving as a guide through it. (like C)



I have to advance somehow from this begginer level, which lays between a
book-reading newbie to intermediate coder which can do tasks given to him, and
he doesn't question himself how to.

No matter how much you'll search, you won't find such person. If a programmer
stops learning, he or she ceases to be a programmer, and degrades to a code
monkey. If you want to become someone who, when given a task knows where to look
for to learn how to do it, then by all means follow MY GOD DAMN ADVICE.

26 Name: #!/usr/bin/anonymous : 2008-05-09 17:38 ID:gSVjbuys

>>24

>C was originally written for low level work with unix.

Which is why I went on to say "modify the linux kernel". Sorry the list isn't exhaustive, but its easy to infer a list of appropriate unix related work with C from that.

>Again, bullshit. Why is C++ ill-suited?

That's the problem with C++, jack of all trades master of none situation. It's flexibility means it has to make sacrifices.

>Why would it want to be "object oriented

by default"?

C++ may not want to be OO by default, but OO is here to stay. You can't avoid it. You are going to use it. So you might as well have it implemented well. Other languages implement it better.

>Objects can be passed by reference in C++

Of course they can. The problem as I and some others see it is that C++'s OO add-ons don't go far enough. They can't. They did for when it was made, but these days better alternative have been implemented. Enforcing value and reference type variables make sense (that is, all objects are pointers by default).

>Moreover, the new C++ standard is going to include threads

It's going to. Then it needs to be adopted etc. etc. etc.

>Just when was threading not important? Please help me recall.

Years ago, beginning programmers didn't even touch threading. It used to depend on what level you were at. These days, you can't avoid it.

>Also, explain briefly the issues you have encountered with libraries such as

pthreads.

The issue is that better threading exists as far as programming it.

>Why would you go with C# and .NET for linux apps?

Portability with other platforms. The fact that the development environment is good.

>What about BSD, solaris, other? OP: Don't learn C#.

Mono is on those too.

>C# is horrible. It's controlled by microsoft.

It is controlled by Microsoft, but its also a published EMCA and ISO standard. Forgoing any irrational MS hate, that is a good thing.

27 Name: #!/usr/bin/anonymous : 2008-05-09 17:59 ID:gSVjbuys

>My goal is to prepare for an actual job.

The demand for C and C++ in the job market is small compared to other languages/platforms.

>The world is advancing, perhaps the kernel will be rewritten in another, more modern language, or we will use some other GNU/Kernel written in Java or C#.

No idea about the Linux kernel. By MS has written a functioning kernel in C#, Singularity, with a windows command line like shell. It's open source (or maybe reference I ca't remember off the top of my head) at the moment, you can download it, run it, play with it. It's a canidate to be the new Windows kernel a couple versions down the road.

>People all go 'Java is bloated' and "C#'s memory management is bad" and maybe, or it is true.

I dislike Java platform, bloated isn't the term I would use but it is one of them.

People who say C#s memory management sucks don't really understand it. Memory management is handled by the .Net framework. Your app automatically gets a low priority thead that the garbage collector uses to clean up memory when it determines it need to. Some people lament this automatic behavior an infer that they have no control over the process, but that's just not true.

If you want to force it to clean up unreferences variables, just call
CG.Collect()
This will instuct the thread to start working

If you want to wait until all garbage is freed before continuing
CG.Collect()
GC.WaitForPendingFinalizers()
Your current thread will wait until the memory is free before continuing.

This is just some simple examples, there is a lot more to it. And I have notice those who dis memory management in .Net are completley unaware that one can intereact with the GC.

>I know it is unrelated to my first question, but how would one improve his knowledge?

Pick a project you really want to make. Figure out what language and platform(s) you want to make it for. Then go for it. Learn the ins and outs of your chosen language. Learn the platforms libaries. Then use that knowledge to come up with a solution you want to implement.

28 Name: #!/usr/bin/anonymous : 2008-05-10 13:20 ID:Heaven

hay guys whats going on in this thread

29 Name: #!/usr/bin/anonymous : 2008-05-11 20:24 ID:VLlaw8ZE

Stroustrup said it doesn't make a difference what order you learn them in The C++ Programming Language.

30 Name: #!/usr/bin/anonymous : 2008-05-12 21:57 ID:/uL43YOY

>>29
no, he definitely said you should learn c++ first. and i quote (pg 7, 3rd par):

>In the continuing debate on whether one needs to learn C before C++, I am firmly convinced that it is best to go directly to C++

he then goes on to list a billion points as to why, and finally (pg 14, 1st par):

>the better one knows C, the harder it seems to avoid writing C++ in C style...

31 Name: #!/usr/bin/anonymous : 2008-05-12 22:05 ID:Heaven

>>30
> the better one knows C, the harder it seems to avoid writing C++ in C style...
That's not true. There's no "C style" and "C++ style", perhaps you mean it's hard to learn and use properly other paradigms, which isn't true.

32 Name: #!/usr/bin/anonymous : 2008-05-13 00:49 ID:Heaven

>MS has written a functioning kernel in C#, Singularity, with a windows command line like shell. It's open source (or maybe reference I ca't remember off the top of my head) at the moment, you can download it, run it, play with it. It's a canidate to be the new Windows kernel a couple versions down the road.

After looking up some more information about it, it makes me feel disgusted. First of all, having an OS kernel running in managed code is going to be hugely inefficient, wasting a lot of potentially available processing power. It also seems too concentrated on "security" and "safe code" and nothing else, making me believe that this is eventually going to be an OS where only "trusted" (read: Microsoft-approved) programs are allowed to run. Another case of trading freedom for security.

33 Name: dmpk2k!hinhT6kz2E : 2008-05-13 01:29 ID:Heaven

> having an OS kernel running in managed code is going to be hugely inefficient

But more efficient than having a language runtime sitting on top of a kernel.

For example, one of the problems garbage collectors face is that they don't communicate with the operating system about the pages they hold, although there have been some attempts. Your typical GC is only aware of is this large virtual space available to them.

What happens to the disk when it's time to collect, and your live set is larger than physical memory? What happens to CoW if the process is forked, but you have a moving collector? How about inter-process communication?

If you have a safe language you no longer need to worry about user processes using ring0 assembly instructions or accessing the memory spaces of other processes. This makes many operations, including context switching, a lot cheaper. Dangerous code is limited to one place, which makes the OS more stable as well.

The language as the OS is an old idea. So are microkernels. That Microsoft wrote one with a mix of assembly, C++ and C# isn't something to mutter about.

34 Name: #!/usr/bin/anonymous : 2008-05-13 16:16 ID:Heaven

> It also seems too concentrated on "security" and "safe code" and nothing else, making me believe that this is eventually going to be an OS where only "trusted" (read: Microsoft-approved) programs are allowed to run.

The mind of a fanboy:

Microsoft writes unsafe code => Microsoft is evil and stupid.
Microsoft writes safe code => Microsoft is evil and stupid.

Now tell us: Seeing as how Windows' one single strength over other OSes is the huge amount of third-party software available only for Windows, that people rely on, why exactly would they want to kill all that off?

35 Name: #!/usr/bin/anonymous : 2008-05-13 16:52 ID:Heaven

>>34 That's disingenuous.

It looks more like this:

Microsoft is untrustworthy and quite possibly evil. When they have a monopoly, they write unsafe code and try and blame the user. When they don't have a monopoly, they try and reengineer words like "safe" to recover it.

Microsoft Safety I can do without.

> why exactly would they want to kill all that off?

Because the Microsoft Developer Lock-In strategy works best when developers are investing in Windows. Once they're already invested, they might broaden their horizons, but while they're actively putting effort into learning new technologies from Microsoft, they're not doing anything else.

Windows code that ran in 3.1 doesn't run anymore. Windows code that run on Windows95 doesn't run anymore. I have TV cards whose drivers were Windows98-only and will not run on Windows anymore. Windows NT4 has many programs that don't work anymore.

Not only has Microsoft "done this before", they do it with every release. Except maybe Windows ME. I'm not aware of any significant breakage there.

36 Name: #!/usr/bin/anonymous : 2008-05-13 18:20 ID:Heaven

>>34
The mind of the fanboy and the truth are the same in this case.

37 Name: #!/usr/bin/anonymous : 2008-05-14 07:02 ID:Heaven

"He who sacrifices freedom for security deserves neither."

That's the first thing I thought of when I read the last few posts. From the point of MS' view, the various unices which have all of the kernel written in languages like C and Asm would be considered "dangerous" and "unsafe", but yet they are still more secure than MS' own OSs, clearly showing that you don't need a whole mess of "checked" and "managed" code to have a secure and still flexible OS.

And... C first. Once you get the basic syntax of the language, then you add objects (C++). Makes sense that "procedural" code which will be what you're writing in class methods anyway is what's learned first, then the object abstraction is employed on top of it.

38 Name: #!/usr/bin/anonymous : 2008-05-15 01:05 ID:Heaven

>>31
what do you mean me? that was a quote from stroustrup.

39 Name: #!/usr/bin/anonymous : 2008-05-15 05:29 ID:Heaven

>>38
Well, it's still wrong.

40 Name: #!/usr/bin/anonymous : 2008-05-15 05:33 ID:Heaven

> If you have a safe language you no longer need to worry about user processes using ring0 assembly instructions or accessing the memory spaces of other processes. This makes many operations, including context switching, a lot cheaper. Dangerous code is limited to one place, which makes the OS more stable as well.
What absolute load of bullshit!

41 Name: dmpk2k!hinhT6kz2E : 2008-05-15 17:33 ID:Heaven

Oh, do elaborate, >>40.

42 Name: #!/usr/bin/anonymous : 2008-05-15 23:07 ID:Heaven

>>41
I assume he's referring to the "guilty-until-innocent" view that MS seems to be taking.

43 Name: #!/usr/bin/anonymous : 2008-05-17 00:24 ID:Heaven

>>35

Dude, Windows is one of the most backwards-compatible OSes around. Their whole business model requires them to retain support for ancient software used by businesses. You're severely delusional if you think otherwise.

44 Name: #!/usr/bin/anonymous : 2008-05-18 01:09 ID:V+a/6Cwu

Wow, look at all of the assumptions.

MS wrote a kernel using a "safe" or managed language (C#) and that's it. No C++ or ASM. They said to get it to work they needed about a 100 lines of unsafe code (you can run unsafe C# code).

The ported over C++ stuff to manged C# and found it ran with less resources (faster) on this kernel.

The kernel does not force that code be managed, its doesn't have to and it would make no sense to make it that way.

The whole thing is a huge subject, you need to read up on the materials written about it and watch their videos before you make uninformed assumptions and sound stupid like >>37 >>35 >>32

I see all the in-built MS hate leading to such stupid assumption all the time. Some people just can never wrap it around their heads that MS might actually make some useful technologies, instead of just regurgitating uninformed blogs they have read.

45 Name: dmpk2k!hinhT6kz2E : 2008-05-18 02:57 ID:Heaven

> No C++ or ASM.

Almost none:

Like the previous Cedar [26] and Spin [4] projects, the Singularity project enjoys the safety and productivity benefits of writing a kernel in a type-safe, garbage-collected language. Counting lines of code, over 90% of the Singularity kernel is written in Sing#. While most of the kernel is type-safe Sing#, a significant portion of the kernel code is written in the unsafe variant of the language. The most significant unsafe code is the garbage collector, which accounts for 48% of the unsafe code in Singularity. Other major sources of unsafe Sing# code include the memory management and I/O access subsystems. Singularity includes small pockets of assembly language code in the same places it would be used in a kernel written in C or C++, for example, the thread context switch, interrupt vectors, etc. Approximately 6% of the Singularity kernel is written in C++, consisting primarily of the kernel debugger and low-level system initialization code.

Ref: http://research.microsoft.com/os/singularity/publications/OSR2007_RethinkingSoftwareStack.pdf

46 Name: #!/usr/bin/anonymous : 2008-05-18 07:35 ID:Heaven

"unsafe code" just makes it seem like putting huge restrictions on what programs can do is a panacea. Think of the "shaving with a bowling pin" analogy.

47 Name: dmpk2k!hinhT6kz2E : 2008-05-18 16:49 ID:Heaven

Can you give some examples, outside of a kernel or drivers, where enforcing safety is a substantial restriction?

48 Name: #!/usr/bin/anonymous : 2008-05-19 03:20 ID:Heaven

>>47
code which generates and executes the code that it generates. memory protection etc. should be left to the hardware anyway. i'm sure there are other examples too.

49 Name: dmpk2k!hinhT6kz2E : 2008-05-19 05:06 ID:Heaven

Generating executable code on the fly is obscure outside of JITs, but true enough. Safe code doesn't prevent doing the same with bytecode though.

Memory protection is already handled by both hardware and software. The operating system creates page tables and handles page faults, after all.

50 Name: #!/usr/bin/anonymous : 2008-05-19 05:46 ID:V+a/6Cwu

Given that an Operating System's primary function is to provide resources to applications, I can't really see how providing managed code resources in the kernel is a bad thing.

An OS that provides more resources and more kinds of resources is always the logical progression of OS development.

51 Name: #!/usr/bin/anonymous : 2008-05-21 03:14 ID:IE2eTPKt

printf("daysue\n");

52 Name: #!/usr/bin/anonymous : 2008-05-21 05:02 ID:Heaven

53 Name: #!/usr/bin/anonymous : 2008-05-21 08:58 ID:Heaven

>>51,52
same person

54 Name: #!/usr/bin/anonymous : 2008-05-21 11:20 ID:Jjgdz/zE

>>50
...and consumes more and more resources?

55 Name: #!/usr/bin/anonymous : 2008-05-21 12:34 ID:Heaven

YA WELL MY KERNELZ HAV XML IN THEM YOU FUKKEN NOOBZ

56 Name: #!/usr/bin/anonymous : 2008-05-21 14:23 ID:k2W5oF8u

I apologize for butting in on the discussion, but did somebody seriously suggest learning .net to develop apps for the linux desktop?

Kind sir, please keel over and die. Mono is not a good thing(tm).

57 Name: #!/usr/bin/anonymous : 2008-05-22 06:02 ID:ueGZ4m2d

Can you already grasp OOP? (Object Oriented Programming) If you can get the concepts, and don't know either, start with C, strict C. It will make you a better programmer down the line. If you dont understand OOP, go with C++ first to understand it, cause if you dont understand OOP and you learn C, you'll make only a mediocre C++ programmer ;)

58 Name: #!/usr/bin/anonymous : 2008-05-22 06:14 ID:Heaven

>>57
C++ is a horrible language for learning OOP.

59 Name: #!/usr/bin/anonymous : 2008-05-22 11:59 ID:Heaven

>>58
C++ is a horrible language.

60 Post deleted.

61 Post deleted.

62 Name: #!/usr/bin/anonymous : 2008-05-27 12:12 ID:cc/iKWJV

>>59
C++ is a horrible.

63 Name: #!/usr/bin/anonymous : 2008-05-27 12:54 ID:Heaven

>>62
Please don't bump silly topics with sillyness, it's considered silly around here.

64 Name: apples!KsVRqPgmrg : 2008-08-11 12:44 ID:Heaven

Why the lot of you bash C++? Do you even have a reason for it, or are you just trolling? A lot of cool shit was made in C++(at least a lot of the cool shit I've heard of).

This thread has been closed. You cannot post in this thread any longer.