Блог пользователя midul

Автор midul, 15 лет назад, По-английски
i want to start participating in contest.
but i can not make decide which language to pick up c++/java.

please help me to make decision.
thanks.
  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

15 лет назад, скрыть # |
 
Проголосовать: нравится -15 Проголосовать: не нравится
C++ and Java. Together.
15 лет назад, скрыть # |
 
Проголосовать: нравится +15 Проголосовать: не нравится
I think it is bad idea to learn both languages simultaneously. It is better to start with one of them, and personally suggest to start with java.
15 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
use pascal - be a real pro! kidding-kidding..:)
15 лет назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится
use pascal - be a real pro! kidding-kidding..:)
15 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
I noticed that C++ teaches you well how stuff works (including standard data structures). Besides, starting with C++ gives you basic skills in all C-style languages.
Java is good for it's wide functionality. However, it can often be somewhat messy — I think C++ is cleaner.
  • 15 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +5 Проголосовать: не нравится
    > However, it can often be somewhat messy — I think C++ is cleaner.
    It seems exactly opposite for me) C++ is too low-level to have clean code
    • 15 лет назад, скрыть # ^ |
      Rev. 2  
      Проголосовать: нравится +3 Проголосовать: не нравится
      I tried to use Java instead of C++ on TopCoder but I didn't feel myself comfortable with it because Java is too verbose. Does verbosity of Java affect you in any way? For example, it's a pain for me to type "System.out.println" instead of "printf" or "Map<Integer, Integer> m = new HashMap<Integer, Integer>()" instead of "map<int,int> m". These differences may seem subtle but in a big enough program they add up together and make expressing my thoughts in Java much harder than in C++. Or maybe I just didn't get used to programming in Java?

      Another aspect of Java that I don't like is that Java collections can't contain primitive values. They need to be wrapped in objects. In C++ I often use vector<int>-s, but in Java I'd have to use ArrayList<Integer>. Sequential processing of all elements of ArrayList may be much slower because of cache misses.
      • 15 лет назад, скрыть # ^ |
        Rev. 2  
        Проголосовать: нравится 0 Проголосовать: не нравится
        Why do you think using objects instead of primitive types is a drawback of Java? Just because you need to type Integer instead of int?
        If you feel that Java is too verbose, Ctrl + space is the help.
        HashMap, HashSet are the things which C++ doesn't possess, and in some cases they really can help you. Existence of StringBuilder, Comparator, java.awt.geom.*, BigInteger, BigDecimal cover the fact that java is verbose.
        Epic fail :)
        • 15 лет назад, скрыть # ^ |
           
          Проголосовать: нравится 0 Проголосовать: не нравится
          Here is an example where Java's ArrayList is slower than C++'s vector. The algorithm is simple. Fill a vector with numbers from 1 to n, then random shuffle the elements of the vector, then calculate the sum of elements. 


          For n = 1000000 the Java version is 10 times slower than C++.

          The verbosity is not just problem of typing. It's also harder to read such program and find errors in algorithm or implementation.
          • 15 лет назад, скрыть # ^ |
             
            Проголосовать: нравится 0 Проголосовать: не нравится
            Now, if we replace vector<int> with array of ints in C++ program (http://ideone.com/1QHHy) then the execution time almost doesn't change. 

            But if we replace ArrayList<Integer> with int[] array in Java version (http://ideone.com/jf7F6) the execution time becomes much lower, about 1.5 times of C++ program.

            So what I want to say is that using vector<int> instead of int[] in C++ doesn't add any overhead, but using ArrayList<Integer> instead of int[] in Java makes program much slower. And that's primarily because integers in ArrayList are stored in wrapper objects.
            • 15 лет назад, скрыть # ^ |
              Rev. 2  
              Проголосовать: нравится 0 Проголосовать: не нравится
              Integer is 32 bit, as well as int. Try to test C# List: it stores primitive types, but the speed is not much better than in Java.
              I remember the times when replacing vector with an array in C++ solved the problem with TLE. 
              ArrayList really sucks. And in most cases it can be replaced by the functionality with faster arrays or HashSet. Remember that arrays in java are much more sophisticated: jagged int [][] a = new int [n][]; is not possible in c++.
              Anyway, it's the question of tastes. Everyone supports the language he knows best of all.

        • 15 лет назад, скрыть # ^ |
           
          Проголосовать: нравится 0 Проголосовать: не нравится
          I never met any C++ compiler that doesn't support stdext namespace which contains stdext::hash_set and stdext::hash_map.

          java.awt.geom.*, BigInteger, BigDecimal — well, you don't have'em in C++, but what can StringBuilder and Comparator do that std::string and STL generic algorithms cannot?
      • 15 лет назад, скрыть # ^ |
         
        Проголосовать: нравится 0 Проголосовать: не нравится
        Despite the verbosity of java, my solutions on TC are offen among the fastest, so I think that's not a big deal