SuprDewd's blog

By SuprDewd, history, 8 years ago, In English

I have a few competitive programming stories that I've been meaning to write up on my "blog". I just finished the first one about my favorite bug. I hope you'll enjoy it.

(I also posted it on reddit in case you'd like to help me fend off lousy comments about competitive programming, or perhaps give me an upvote.)

I'd also like to encourage others with [interesting|funny|sad] competitive programming-related (horror)? stories to do the same. Either post a comment here, make your own post on Codeforces, or post it to your personal blog. I've already seen multiple such stories here on Codeforces, all of which I enjoyed, and I'm sure there are many more in hiding!

  • Vote: I like it
  • +76
  • Vote: I do not like it

»
8 years ago, # |
  Vote: I like it +17 Vote: I do not like it

never use macros
avoid templates
never use legacy C libraries (cstdlib, cstdio, cstring, etc). Use C++ STL
never use C-style arrays (int a[n])
never use implicit integer casts
never use global variables. Use classes
never use new/delete and raw pointers. Use std::unique_ptr and references

compile your code in debug mode with all possible warnings

use various analyzers like clang static analyzer, clang address/ub sanitizer, valgrind, PVS Studio

read books like "Effective C++" and "Effective Modern C++"
try rust. This language will force you to learn a lot of important stuff.

»
8 years ago, # |
  Vote: I like it +29 Vote: I do not like it

That was a very nice article! Reading the comments on reddit was pretty hilarious too, it seems that the coding practices in competitive programming are so horrifying to regular programmers that they can't even laugh about them. ^^

This reminds me of when I discovered that my code for 2-SAT which I had used for 4 different UVa problems (and it was AC every time) was wrong for fundamental reasons: I was listing the SCCs in toposort order (from Kosaraju) and assigning true by default instead of false. I was pretty freaked out when I discovered it. :D

  • »
    »
    8 years ago, # ^ |
      Vote: I like it +12 Vote: I do not like it

    "You should not be allowed near a compiler."

    haha

    • »
      »
      »
      8 years ago, # ^ |
        Vote: I like it +14 Vote: I do not like it

      Oh, man. Apparently I'm a psychopath and not mature enough to use a compiler.

      On the upside, Python is now becoming an accepted contest language, so I don't need a compiler anymore!

  • »
    »
    8 years ago, # ^ |
      Vote: I like it +44 Vote: I do not like it

    Reading the comments on reddit was pretty hilarious too, it seems that the coding practices in competitive programming are so horrifying to regular programmers that they can't even laugh about them. ^^

    Nah, that's just Reddit. The site that bans anti-pedophile subreddits while allowing pro-pedophile subreddits (/r/pedofriends etc, not linking to that shit), where censorship is rampant and the CEO edits comments in the DB, which means it wouldn't be provable if he didn't admit to it himself, then gloats about it on company Slack chat, which was then leaked by someone who didn't approve of it. A treasure trove of lulz.

    Anyway, some comments are really hilarious. "Just treat it as your 45917825th special case!" "arrays with size larger than 32 bits" "I hit the word swag and stopped reading."

    Reddit, the site where everyone is The Expert.

  • »
    »
    8 years ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    Glad you liked it! I also enjoyed the comments (perhaps a bit too much). I think someone summed it up pretty neatly:

    Most people commenting here don't understand "cultural difference" and feel offended that "ignorant" people like you are using C++ ;)

    Also, regarding your 2-SAT story:

    I was pretty freaked out when I discovered it.

    Haha, I definitely know the feeling.

»
8 years ago, # |
  Vote: I like it -13 Vote: I do not like it

My favorite bug is to use C++ instead of Java.