anyone know the best way to code in C? methods? books? websites? i really want to learn but my funds are quite low. ideas? preferably online resources would be great.
Originally posted by Alex:
its written in 1988, old, no?
No, not old, proven.its written in 1988, old, no?
bleh.The best way is to abandon any notion of learning C and learn C++ instead.
I don't think that manually managing C-style "strings" is either required to be a programmer, nor even something particularly desirable to learn.Problem with C++ is there's so many different frameworks you can use to avoid ever really learning how to manually do some things you need to know how to do to be a programmer. For example, using a canned string class is easier than managing C-style strings....
I can't think of any occasions on which I've needed to write my own string (or I/O, or linked list, or set, or map, etc.) class. The classes I (and many others) write are much higher level than that. I'm hard-pressed to see why it's even useful to know. It teaches you more about the inadequacies of C than anything else.or using typesafe I/O(even with iomanip stuff) is usually easier than explicitly writing out a printf() to do what you want...same with new vs. malloc()...but by doing it the C way you learn what's going on at a more fundamental level...so actually implementing the base class itself(where you need the lower level knowledge) would never be a problem.
You can learn to program without ever having to dick around with the annoyances of fixed-size null-terminated strings.Learning to program and writing programs are two different things. Abstraction and OO ain't the answer to everything.
Problem with C++ is there's so many different frameworks you can use to avoid ever really learning how to manually do some things you need to know how to do to be a programmer. For example, using a canned string class is easier than managing C-style strings....or using typesafe I/O(even with iomanip stuff) is usually easier than explicitly writing out a printf() to do what you want...same with new vs. malloc()...but by doing it the C way you learn what's going on at a more fundamental level.
Learning to program and writing programs are two different things. Abstraction and OO ain't the answer to everything.
And even when learing to program, you should learn to not reinvent the wheel.
I can't think of any occasions on which I've needed to write my own string (or I/O, or linked list, or set, or map, etc.) class. The classes I (and many others) write are much higher level than that. I'm hard-pressed to see why it's even useful to know. It teaches you more about the inadequacies of C than anything else.
Right. Once I learn what sorting is and how it works, having a generic algorithm to sort just about any collection of any types is great.
I don't see how your having to write the STL because the STL didn't exist is a justification for anyone else doing the same. Yes, not long ago C++ didn't have such things. It does now. It seems pointless to ignore the facilities now on offer merely because they used not to exist.You're too young, then. It was not very long ago that C++ didn't have any of this capability, and if you wanted good string handling, maps, vectors, hashes, etc., then you had to roll your own using the still-new templates. I've written more implementations of the STL classes than I care to remember.
I'm not sure that it'd be necessarily difficult to do the same with an STL string class anyway.We still use our own implementations in our company, since the base code was developed pre-STL. I'm glad we do. You never know, for example, when a stl::string won't suit your needs properly because of the kinds of manipulations you have to perform. For us, it was easy enough to modify our own internal string class to extend the functionality (say...add a mechanism to cache very large strings to disk) and optimize performance for our special cases.
I'd wager they'd get caught up in the details and ignore that the language they're using has a perfectly good set of standard libraries. There are too many STL-era C++ programmers who ignore the STL for no reason other than they apparently want to tackle everything from the lowest level, even if the extra detail is irrelevent to the task at hand. As far as I can see, those who learn the intricacies are not good at sitting back and saying, "I can just use this string class and it'll do what I need without having to get caught up in how it works".In fact, I'd wager that somebody that knows the intricacies would have an easier time using an abstract model than someone who knows the abstract model could go down.
No, I don't have any customers. Does this render my experience invalid?Or, do you not have any customers?
Wrong. What happens when the customer calls up and complains that the sorting takes way too long? Do you just say, "oh, I'm sorry...we're using the STL and that algorithm can't work any faster!" No, you make your own (or at least find a suitable) algorithm that's optimized for your case.
I have customers.Originally posted by wb:
Wrong. What happens when the customer calls up and complains that the sorting takes way too long? Do you just say, "oh, I'm sorry...we're using the STL and that algorithm can't work any faster!" No, you make your own (or at least find a suitable) algorithm that's optimized for your case. Or, do you not have any customers?
Originally posted by Stephan T. Lavavej:
"Those who claim 'C++ is a better C' are wrong" - Richard Heathfield, C Unleashed
"In C++ it's harder to shoot yourself in the foot, but when you do, you blow off your whole leg." '” Bjarne Stroustrup.
the reason i want to learn C is because i want to eventually branch off and learn other languages as well: PHP, Perl, etc.Originally posted by PeterB:
The best way is to abandon any notion of learning C and learn C++ instead.
Originally posted by PeterB:
The best way is to abandon any notion of learning C and learn C++ instead.
I think merge sort needs extra memory proportional to the number of elements, and I've seen merge sorts that are slower than heapsorts in any case.(as a minor note, you'll almost always find that among assured O(n log n) sorting algorithms, merge sort is the fastest; in every case I've seen it's been faster than heapsort.)
C++ permits one to get just as "close to the metal" as C -- but, unlike C, doesn't require it.If a man wants to learn C, let him learn C -- no other portable language will get him closer to the metal.
I does need extra memory (as much as your dataset) to be fully efficient. There are "in place" merge sorts, but they're slower. The version with extra memory is guaranteed O(n * log n) though, and that might be important in some cases. It has the advantage of being stable. Also, due to its sequential nature, it will probably have a significant advantage over other sorts on large data sets (ie. that don't fit into the cache). Just look at how DBs are sorted: they normally use a variation of merge sort, because it requires lots of bandwith but little random access. That matches what a HD can provide. More and more, processors also benefit from this kind of access to memory. Just something to keep in mindI think merge sort needs extra memory proportional to the number of elements, and I've seen merge sorts that are slower than heapsorts in any case.
C++ permits one to get just as "close to the metal" as C -- but, unlike C, doesn't require it.
No where did I say don't understand various sorting algorithms or be ignorant of computer science because you have all these cool standard library things to do it for you. What I believed I was saying was that these containers and libraries are useful to avoid everyone coding their own lists and queues and sorts from scratch.
I don't see how your having to write the STL because the STL didn't exist is a justification for anyone else doing the same. Yes, not long ago C++ didn't have such things. It does now. It seems pointless to ignore the facilities now on offer merely because they used not to exist.
The classes I (and many others) write are much higher level than that. I'm hard-pressed to see why it's even useful to know.
One compromise I've seen is to e.g. quicksort subsets of the data (as much as will fit in memory), write out that partially-sorted data to disk, then mergesort from disk.Originally posted by euzeka:
I does need extra memory (as much as your dataset) to be fully efficient. There are "in place" merge sorts, but they're slower. The version with extra memory is guaranteed O(n * log n) though, and that might be important in some cases. It has the advantage of being stable. Also, due to its sequential nature, it will probably have a significant advantage over other sorts on large data sets (ie. that don't fit into the cache). Just look at how DBs are sorted: they normally use a variation of merge sort, because it requires lots of bandwith but little random access. That matches what a HD can provide. More and more, processors also benefit from this kind of access to memory. Just something to keep in mind![]()
p.816, B.2, The C++ Programming Language, Third Edition, Stroustrup, BjarneWith minor exceptions, C++ is a superset of C. Most differences stem from C++'s greater emphasis on type checking. Well-written C programs tend to be C++ programs as well. All differences between C++ and C can be diagnosed by a complier.
http://www.research.att.com/~bs/bs_faq.html#C-is-subsetIn the strict mathematical sense, C isn't a subset of C++. There are programs that are valid C but not valid C++ and even a few ways of writing code that has a different meaning in C and C++. However, C++ supports every programming technique supported by C. Every C program can be written in essentially the same way in C++ with the same run-time and space efficiency. It is not uncommon to be able to convert tens of thousands of lines of ANSI C to C-style C++ in a few hours. Thus, C++ is as much a superset of ANSI C as ANSI C is a superset of K&R C and much as ISO C++ is a superset of C++ as it existed in 1985
p.6, C++ Primer Plus, Third Edition, Steven Prata, 1998 Sam's Publishing.Stroustrup based C++ on C because of C's brevity, it's suitability to system programming, it's widespread availability, and it's close ties to the UNIX operating system. ... Stroustrup added OOP features to C without significantly changing the C component. Thus, C++ is a superset of C, meaning that any valid C program is also a valid C++ program, too. ... There are some minor descrepancies, but nothing crucial. C++ can use existing existing software libraries
http://www.research.att.com/~bs/bs_faq.html#differencePlease note that "C" in the paragraphs above refers to Classic C and C89. C++ is not a descendant of C99; C++ and C99 are siblings. C99 introduces several novel opportunities for C/C++ incompatibilities.