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

Автор dzhi, история, 10 месяцев назад, По-английски

It appears that Codeforces' judgement system uses a rather huge stack size (maybe 256 MB or even more). A typical example is a DFS solution on a large tree with 200000 nodes, potentially a stick/chain of 200k nodes so the call stack has 200k frames!

Such a huge stack size, likely was introduced to allow DFS or other recursive solutions, which is considered as a bad practice and usually discouraged in production software system:

  • Software systems are usually multi-threaded (dozens or even hundreds of threads) to leverage all the CPU cores and be flexible to network/disk IO delays. Individual threads can not have a huge stack size due to memory limits.
  • With a huge stack size, most of the memory reserved for the stack is likely wasted most times.
  • More importantly, recursive code has the risk of hitting stack overflow at runtime at unpredictable and inconvenient times (like a mine in the field). It is usually discouraged or even forbidden to implement recursive code with unbounded or huge layers.

I wonder what other people's opinion about this, and/or a good reason Codeforces uses a huge stack size.

  • Проголосовать: нравится
  • -14
  • Проголосовать: не нравится

»
10 месяцев назад, # |
  Проголосовать: нравится +69 Проголосовать: не нравится

This is competitive programming, not "real" programming.

  • »
    »
    10 месяцев назад, # ^ |
      Проголосовать: нравится +37 Проголосовать: не нравится

    Can't wait until OP learns about top competitive programmers using global variables, bits/stdc++.h, dozens of C++ macros, etc...

»
10 месяцев назад, # |
  Проголосовать: нравится +43 Проголосовать: не нравится

On a more serious note, I don't follow the justification for why competitive programming should try to emulate actual software production. Indeed, several trends over the past five years or so (e.g. shifting away from problems with long implementations, providing more comprehensive samples and pretests, etc) indicate that Codeforces is trying to emphasize the process of solving problems conceptually rather than the practical details associated with implementation. A small stack size limit would make certain types of solutions more annoying to implement without making the actual process of solving problems more interesting, and hence contestants are allowed to use large stack sizes.

I'll also add that this is far from the biggest factor separating Codeforces contests from the process of actual software development. For example, when solving problems in Codeforces rounds, contestants are encouraged to prioritize speed above essentially all else, whereas when working on real-world development it's usually better to take more extensive measures to write code that is clean, maintainable, extensible etc. In my opinion, the format of typical programming contests (short time frame, lots of problems, scored based on passing fixed test cases with clearly specified constraints, etc) is incompatible with realistically simulating actual development. Instead, it makes more sense to view programming contest problems as a way of training a very specific skill (algorithmic problem-solving) that is in some ways useful to software engineers (and in many other careers!) but is not a substitute for other skills necessary for real-world software development.

  • »
    »
    10 месяцев назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    As an aside, can we not downvote this blog? At time of writing, it's at -4 votes, and while I disagree with the suggestion implied by the post, the author is making a valuable contribution to the community by publishing a well-articulated post about his thoughts.

    More generally, it would be nice if we could separate "I agree/disagree with this post" (or "I think this contest was good/bad") from upvotes and downvotes and instead let the voting system reflect "I think this is a positive/negative contribution to the community." Perhaps this is an argument for more blogs to use the polling feature; likewise, maybe fewer rounds would be downvoted if they instead left a poll on the announcement where people could express whether they liked/disliked the contest while upvoting the announcement in appreciation of the effort the authors put in.

    • »
      »
      »
      10 месяцев назад, # ^ |
        Проголосовать: нравится -17 Проголосовать: не нравится

      An upvote/downvote system allows us to be toxic, and that is one of the most fundamentally desirable features of using the internet.