I think they are related to the language. C++ has many 'fake problems', notably header file inclusion (why not detect which parts of the STL you're using at compilation?), overload resolution (Why should functions be overloaded in the same namespace if we have explicit namespaces anyway? As for sin, cos etc. taking different types of numbers, those should be resolved by inheritance.), and memory management. Simpler, slower languages can eliminate these problems and allow the learner to focus on algorithms, data structures, etc. I think you should start with a language like Perl, Python or Ruby, and then move to C++ when you've solved the real problems and you're ready to deal with fake problems.
I started off with Perl, and then moved to C++ and then C. I'm currently getting good in Ruby.
I think they are related to the language. C++ has many 'fake problems', notably header file inclusion (why not detect which parts of the STL you're using at compilation?)
This is neither common in any language I am aware of, nor does it appear particularily desirable to me.
overload resolution (Why should functions be overloaded in the same namespace if we have explicit namespaces anyway? As for sin, cos etc. taking different types of numbers, those should be resolved by inheritance.)
Uh well, because the point of having namespaces in the first place is to avoid name collisions. And what do you mean by inheritance in this context?
and memory management
... is a problem a beginner usually doesn't have to deal with at all, because C++ allows you to avoid pointers in most cases.
fake problems
At least C++ programs don't break when your spacing isn't what the compiler expects, or when you happen to want to write a class with a lowercase name etc. I am not aware of any languages that do not have any problems. I personally disagree with saying that script languages are better for beginners - and if you'd ever have had to read the code of someone who never learned that having function and class definitions scattered all over the place, mixed with the "main" code, is a bad thing, you'd probably agree.
@rocketboy: I agree with some of the stuff you put there but...
As for sin, cos etc. taking different types of numbers, those should be resolved by inheritance.
I have no idea how inheritance would help you in this case other than making your code obscure for no reason. Overloaded functions are far simpler I believe.
The point is that int, float, double would all inherit from a single Number class. And then sin etc. would take an argument of that class.
And hanst99, please show me how you would code a linked list in C++ without memory management. Programmers need to know more than just how to use libraries.
This is neither common in any language I am aware of, nor does it appear particularily desirable to me.
Actually Perl and Ruby have their whole standard libraries available without any extra stuff, which is why print "Hello, World!"; works in both. Why should a beginner need to see more than that one line for the first program?
please show me how you would code a linked list in C++ without memory management
std::list //exist in c++98, double linked list std::forward_list //c++0x(coming soon) or boost slist, singly linked list
Since you know the existence of stl, I believe you know that we don' have to reimplement linked list
at most of the time.If you do have to do that(what cases?), It means the resources of you environment
maybe very "tight" => ability of memory management would be inevitable(allocator + boost pool should be able to handle most of the cases => we almost don't need to reimplement linked list)
As for sin, cos etc. taking different types of numbers, those should be resolved by inheritance.
Sorry, I can't see the manifest advantages of inheritance in this case
May you show us your way of how to design sin, cos functions by the way of inheritance?
Thanks a lot
I've also started in C++, and I'm very happy I did :D
Currently I'm learning Python after a year of C++.
It's a lot easier now than when I first started with C++.
I think it's easier to go from C++ to Python, than the other way around.
It's good to first learn to implicitly define variables etc than to have them anonymous, which might cause confusion for beginners!
I believe you know that we don' have to reimplement linked list at most of the time.
How is it you can't understand that reimplementing a linked list is a good assignment for a beginner? Same with reimplementing vector, map, etc. In C++ you can't learn data structures without using memory management.
May you show us your way of how to design sin, cos functions by the way of inheritance?
Thanks a lot
class Number {
public:
virtual string typeinfo();//returns what kind of number this is.
virtual Number operator + (Number a,Number b);
//... all the other arithmetic operations
};
classint : public Number {
string typeinfo(){return"int";}
//...stuff
}
classfloat : public Number {
string typeinfo(){return"float";}
//...stuff
}
classdouble : public Number {
string typeinfo(){return"double";}
//...stuff
}
Number sin(Number n){
if(n.typeinfo()=="int")//do integer sin
elseif(n.typeinfo()=="float")//do float sin
elseif(n.typeinfo()=="double")//do double precision sin
//etc
//These if statements would be factored out at compile time based on what was actually passed in.
}
How is it you can't understand that reimplementing a linked list is a good assignment for a beginner?
Sorry, now I know what is your point.
About your solution, for me the overload version is easier to read and more efficient(maybe).
IMHO, this is just a design choice(trade off and coding style). Thanks for your idea
I would not recommend learning Python first; I think C++ makes a fairly good first language. It was my first language, and though I regretted it at first, now I think I made a good choice; though recently I tend to use C# more.