Thread: Which language to start with

  1. #16
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by manav View Post
    Do no discourage people who wish to learn C++.
    I think it is perfectly valid and useful to learn C++ even before any other language is learned!

    C++ has some really good stuff to ease the newbies!
    I will recommend C++ for learning how to program, other languages are more like get your work done, the fastest!
    But if you get it wrong in Java or Python, there is (assuming we avoid the bugs in the implementation of the language) a safety-net to catch the user's errors in a way that is normally not available in C or C++.

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

  2. #17
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Quote Originally Posted by matsp View Post
    But if you get it wrong in Java or Python, there is (assuming we avoid the bugs in the implementation of the language) a safety-net to catch the user's errors in a way that is normally not available in C or C++.

    --
    Mats
    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:
    Code:
    double prin;
    float interest;
    int numYears;
    
    cout << "Enter principal amount, interest and number of years: ";
    cin >> prin >> interest >> numYears;
    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!!
    Last edited by manav; 05-14-2008 at 04:34 AM.

  3. #18
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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.

  4. #19
    Banned
    Join Date
    Nov 2007
    Posts
    678
    C++ 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;	
    }
    Python version:
    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 loose!

  5. #20
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Do no discourage people who wish to learn C++.
    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.

    I think it is perfectly valid and useful to learn C++ even before any other language is learned!
    With modern C++ pedagogy, yes, I agree (though it would be good to know at least one natural language before attempting to learn C++ ).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #21
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Quote Originally Posted by laserlight View Post
    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.
    Yeah. I agree!

    With modern C++ pedagogy, yes, I agree (though it would be good to know at least one natural language before attempting to learn C++ ).
    lol! you funny! i know that you know what i meant!

  7. #22
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    > The above simple stuff is damn hard to do in Java
    What?!? It's really simple actually.
    Code:
    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);
        }
    
    }
    Reads like a book. I'm certainly no fan of Java

  8. #23
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Quote Originally Posted by zacs7 View Post
    > The above simple stuff is damn hard to do in Java
    What?!? It's really simple actually.
    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!!!

  9. #24
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by manav View Post
    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.

  10. #25
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Quote Originally Posted by Mario F. View Post
    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.
    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.

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

    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.
    While Java's open dialog was painfully slow, 2D graphics were fast! (Faster than what I could do with Qt).


    Otherwise what you said, I agree!

  11. #26
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    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!!!
    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.

    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.

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

  12. #27
    Banned
    Join Date
    Nov 2007
    Posts
    678
    My general view is that C++ is good for starters!
    My gut feeling is that it is better for starters!!

  13. #28
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by manav View Post
    My general view is that C++ is good for starters!
    My gut feeling is that it is better for starters!!
    But as mike_g says: There are many, many ways that you can screw up in C++ that won't happen in other languages:
    Code:
    int i;
    int arr[10];
    for(i = 1; i <= 10; i++) arr[i] = i;
    Just as one simple, beginner style, example.

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

  14. #29
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Quote Originally Posted by matsp View Post
    But as mike_g says: There are many, many ways that you can screw up in C++ that won't happen in other languages:
    Code:
    int i;
    int arr[10];
    for(i = 1; i <= 10; i++) arr[i] = i;
    Just as one simple, beginner style, example.
    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

  15. #30
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    But we could argue that example is C.
    In C++, you would use a vector and the .at member.
    Preferably, also a safe iterator that can throw if you access out-of-bounds.
    The standard library is sometimes just as unsafe as the C library.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked List Anamoly
    By gemini_shooter in forum C++ Programming
    Replies: 3
    Last Post: 02-28-2005, 05:32 PM
  2. Languages dying
    By Zewu in forum A Brief History of Cprogramming.com
    Replies: 31
    Last Post: 07-29-2003, 10:08 AM
  3. Language Script..
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 03-30-2003, 06:48 AM
  4. One Unique Universal Programming Language ?
    By zahid in forum A Brief History of Cprogramming.com
    Replies: 30
    Last Post: 01-29-2003, 12:36 AM
  5. What language did you start with?
    By Fool in forum A Brief History of Cprogramming.com
    Replies: 31
    Last Post: 09-03-2001, 09:21 AM