Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
How nice to know them from the start! The newbie is not under pressure of making the first release of his software before the last week of the first month!
Besides C++ is really easy for newbie like stuff:
Write a program to calculate simple interest:
The above simple stuff is damn hard to do in Java, and Python also needs a lot of understanding to do this. Even further info will be needed to avoid the invalid input problems!!Code:double prin; float interest; int numYears; cout << "Enter principal amount, interest and number of years: "; cin >> prin >> interest >> numYears;
Last edited by manav; 05-14-2008 at 04:34 AM.
I haven't got Python on this machine, but I thought the Python code to do the same as your C++ example would be about the same number of lines.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
C++ version:
Python version:Code:#include <iostream> using namespace std; int main() { cout << "Simple Interest Calculator" << endl; cout << "Enter Principal amount, interest rate and number of years: "; double prin; float rate; int numYear; cin >> prin >> rate >> numYear; double intr = (prin * rate * numYear) / 100.0; cout << "Interest: " << intr << endl; return 0; }
I loose!Code:print "Simple Interest Calculator" print "Enter Principal amount, interest rate and number of years: " prin, rate, numYear = raw_input().split(' ') prin, rate, numYear = float(prin), float(rate), int(numYear) intr = (prin * rate * numYear) / 100.0 print "interest:", intr
I have never discouraged anyone from learning C++. I merely recommended that slats concentrate, for now, on the programming languages that he/she already has some knowledge of.Do no discourage people who wish to learn C++.
With modern C++ pedagogy, yes, I agree (though it would be good to know at least one natural language before attempting to learn C++ ).I think it is perfectly valid and useful to learn C++ even before any other language is learned!
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
> The above simple stuff is damn hard to do in Java
What?!? It's really simple actually.
Reads like a book. I'm certainly no fan of JavaCode:import java.util.Scanner; class Blah { public static void main(String[] args) { Scanner stdin = new Scanner(System.in); double prin = 0.0; float rate = 0.0f; int numYear = 0; double intr = 0.0; System.out.println("Simple Interest Calculator"); System.out.print("Enter Principal amount, interest rate and number of years: "); prin = stdin.nextDouble(); rate = stdin.nextFloat(); numYear = stdin.nextInt(); intr = (prin * rate * numYear) / 100.0; System.our.println("Interest: " + intr); } }
I did not know about Scanner New addition I guess =_=
No excuse, but arranged by the size of code, smallest to largest:
Python
C++
Java
C++ is behind Python because of 3 lines declaring just variables, plus, 2 braces, can be ignored, i feel, so, C++ code is shorter than Java and no point for guessing, much faster!!!
You are not going there if all there is to reach a conclusion is one example. Ultimately what determines the size of the code and how fast it runs is the programmer skills and to some extent the problem it's trying to solve. I could for instance, resize your C++ example to maybe 5 lines inside of main, but the results could be questionable in terms of code correctness. On the other hand I could add maybe 15 lines outside of main and the result could mean code reuse, or I could even add an entire library with maybe a hundred lines of code and the result would mean I would be in control of float precision.
As for speed, this has been discussed numerous times. My position was always that the speed requirements of an application can almost always be handled by any language (interpreted or not). From the user perspective, they will not perceive any differences in performance or if they do, it will most always be irrelevant to them. This is true for a wide range of applications running in our computers - the gross in fact.
It's when speed requirements are critical, that the choice of programming language may have an impact on performance. And even then, only when the problem domain proves to loose from some choice after testing. For instance, it's quiet common knowledge Java will not handle 2D programming satisfactorily enough to build a modern 2D game or a 2D graphics application without a perceived loss in performance. However, it's quiet acceptable as a choice for the number crushing necessary to run a weather prediction application.
The operative word here is critical. We tend to misplace that word all too often and not fully appreciate that some problems will not benefit from a "faster language".
Last edited by Mario F.; 05-14-2008 at 06:57 AM.
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
Well that basically applies to all the languages, Java, C++ or Python!
But newbies need to write small programs to get started! I found C++ version to be smaller, more clear, easy!
I was saying that a newbie programmer is not concerned with the very high level stuff that the languages may do, (s)he just needs to learn some programming tricks, how to dissect a number into digits, etc. just small stuff, getting started.
And also no harm if with these tiny practices the newbie also gets a taste of, type info, variable declaration, etc.
Though for some reasons naturally Java is a bit slow, and as you said it does not matter either, just depends on the type of application!As for speed, this has been discussed numerous times. My position was always that the speed requirements of an application can almost always be handled by any language (interpreted or not). From the user perspective, they will not perceive any differences in performance or if they do, it will most always be irrelevant to them. This is true for a wide range of applications running in our computers - the gross in fact.
But Java is slow for most inefficient task also, would you like to optimize a file open dialog any further! Nah! Java's file open dialog takes very long time to open, and changing the drive is painfully slow! The file dialog is not critical, by any means, and we do not need super fast speed of a compiled language in this case, but, anyway it is so slow, it can turn off the programmer from the start!
While Java's open dialog was painfully slow, 2D graphics were fast! (Faster than what I could do with Qt).For instance, it's quiet common knowledge Java will not handle 2D programming satisfactorily enough to build a modern 2D game or a 2D graphics application without a perceived loss in performance. However, it's quiet acceptable as a choice for the number crushing necessary to run a weather prediction application.
Otherwise what you said, I agree!
I really wouldent judge a language on such a limited scope. And for the kind of program that you wrote it really would not make a difference if it was done in C++, java, or Python.C++ is behind Python because of 3 lines declaring just variables, plus, 2 braces, can be ignored, i feel, so, C++ code is shorter than Java and no point for guessing, much faster!!!
IMO, C++ has a lot more flexibility than the other 2 languages you can also write programs that run very fast with it. The bad points are that it takes longer to learn and theres so many extra ways you cn screw up with it if youre not careful. Java is object orientated and strongly typed, so you are going to end up with a lot of code. Whle Java lacks some of C++'s features it has a huge set of standard libraries that can do almost anything you want, so for bigger projects it can make life much easier and programs I have written in Java generally tend to end up with less bugs. I havent used Python for much so I can't really say that much about it except that its very high level you can generally get away with specifying much less but it comes with speed and flexibility limitations.
You can use SDL with java and many other C/C++ APIs. But yeah, you can make code that runs faster than Java in lower level laguages.It's when speed requirements are critical, that the choice of programming language may have an impact on performance. And even then, only when the problem domain proves to loose from some choice after testing. For instance, it's quiet common knowledge Java will not handle 2D programming satisfactorily enough to build a modern 2D game or a 2D graphics application without a perceived loss in performance. However, it's quiet acceptable as a choice for the number crushing necessary to run a weather prediction application.
My general view is that C++ is good for starters!
My gut feeling is that it is better for starters!!
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
That's the point of ignorant learner/teacher, you teach/learn arrays, but did not teach/learn that array start from 0, and end at size-1, if you count in head 0...9 is already 10 elements, so there is no valid index 10, which means there is no 11th element, because you declared a 10 element array!
simple!
and the newbie will respect the fact, from the start, that (s)he has limited resources and should respect bounderies