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

Автор midul, 14 лет назад, По-английски
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
  • Проголосовать: не нравится

14 лет назад, # |
  Проголосовать: нравится -15 Проголосовать: не нравится
C++ and Java. Together.
14 лет назад, # |
  Проголосовать: нравится +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.
  • 14 лет назад, # ^ |
      Проголосовать: нравится +12 Проголосовать: не нравится
    I agree, because C++ has a lot of obliviousness things as memory leaks, zero-terminated strings, pointers, lack of array border checking and other.
    Java is better, because you don't need to think about memory management, invalid pointers and arrays size
    • 14 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится
      but you must think about time limits:)
      • 14 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится
        Yes, you do.
      • 14 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится
        You must think about time limits for all languages. If there is a sutiation, when an O(nlogn) solution is considered, and a C++ O(n^2) solution passes, while the same algo in Java fails, then it is the oversight of the authors of the problemset.
    • 14 лет назад, # ^ |
      Rev. 2   Проголосовать: нравится +2 Проголосовать: не нравится
      You can avoid most of bad C things.

      > memory leaks
      Don't use pointers. Use std::vector instead of arrays.

      > zero-terminated strings
      Use std::string.

      > lack of array border checking
      Use vector.at method.
      • 14 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится
        and lose all C++'s benefits
        • 14 лет назад, # ^ |
            Проголосовать: нравится 0 Проголосовать: не нравится
          What benefits? I think std::vector and std::string are real benefits of C++. They aren't much slower than C style arrays and strings. At least not slower than Java. And the code is pretty concise. At least not more verbose than Java.
          • 14 лет назад, # ^ |
            Rev. 4   Проголосовать: нравится 0 Проголосовать: не нравится
            No once my code get AC after TL & replacing vectors and strings

            So, It rather slow.

            Sorry, I can't compare with Java, but I think it isn't very faster than Java
      • 14 лет назад, # ^ |
        Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится
        Do use pointers. They don't cause memory leaks themselves. The only thing you should really never use is a dynamic memory allocation — it's slow and leaks the space (especially because of granularity). Also if we're talking about contest programming, there is no need for "new", "delete" and "malloc" because input is always bound by some constants. Static allocation is enough. For example, you can use the following technique as a substitution for "new" keyword:

        Some_structure pool[MAX];

        Some_structure * next = &pool[0];

        Some_structure * New() {
        return next++;
        }

        This technique can be adapted to support "deletion" too. And this will work much faster than heap memory allocation, because static arrays are implemented by mapping virtual memory and real allocation of memory pages is being done inside kernel's code, so it doesn't affect your process's CPU time.
      • 14 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится
        But Java gives you more information about exception: full stacktrace. C++ does not.
14 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
use pascal - be a real pro! kidding-kidding..:)
  • 14 лет назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится
    Hennady disagrees with last two words.
  • 14 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится
    Ты написал в русский интерфейс. И вообще, когда Короткевич пишет контесты на паскале, это по-моему никакой не шутка.
    • 14 лет назад, # ^ |
        Проголосовать: нравится -8 Проголосовать: не нравится
      За интерфейс почему-то не подумал.. 
      А ему ,если я не ошибаюсь, и на С удобно тк писать. Мб просто привык парень..:) не вижу других причин писать на делфи.. ну кроме как банально не знать С, как в моём случае^^
14 лет назад, # |
  Проголосовать: нравится +6 Проголосовать: не нравится
use pascal - be a real pro! kidding-kidding..:)
14 лет назад, # |
  Проголосовать: нравится 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.
  • 14 лет назад, # ^ |
      Проголосовать: нравится +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
    • 14 лет назад, # ^ |
      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.
      • 14 лет назад, # ^ |
        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 :)
        • 14 лет назад, # ^ |
            Проголосовать: нравится 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.
          • 14 лет назад, # ^ |
              Проголосовать: нравится 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.
            • 14 лет назад, # ^ |
              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.

              • 14 лет назад, # ^ |
                  Проголосовать: нравится 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.

                Are you sure? I believe C#'s list speed must be close to C++. 

                So, do you agree that there's no easy and efficient way to work with arbitrary length lists of primitive types in Java like there is in C++? If so then it's a big minus in my opinion, because I often use such lists in C++.
        • 14 лет назад, # ^ |
            Проголосовать: нравится 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?
          • 14 лет назад, # ^ |
              Проголосовать: нравится 0 Проголосовать: не нравится
            Java has very powerful regexps with .split() method. split() and StringTokenizer are very convenient to parse complex inputs
      • 14 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится
        Despite the verbosity of java, my solutions on TC are offen among the fastest, so I think that's not a big deal