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

Автор Confused101, история, 7 лет назад, По-английски

Can someone suggest me what are good practices to write more readable codes? Indentation, variable naming, spaces, alignment etc.. also some users who write good looking codes?

thanks,

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

»
7 лет назад, # |
  Проголосовать: нравится +26 Проголосовать: не нравится

John Dethridge in TopCoder.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Its hard to find topcoder submissions, seems he is not much active these days as well, btw thanks, your codes are also elegant :)

»
7 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

competitive programming make us write hard-to-understand codes !

As the time is one of variables that affect your points ( the more faster your submission the higher rank you get ) so if you need to make variable Friend just write f , distance just write d .... etc.

in competitive , just make clear steps in your code and don't write many steps in one line. thus , any one read the problem and read your code will — almost — understand it.

the best way to write more readable codes is the real-life projects , almost we work in a team so you can't make a variable called f to refer to "friend" , and if you have to make a short name you will have to write a comment to explain what is this refer to.

also reading readable projects will help you.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    You stop being able to manage badly written code as soon as its length reaches ~200-300 lines. It gets a lot harder to modify/extend it (yes, might need it in the contests).

    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      And also keeping good coding style doesn't waste much time. Especially with modern IDEs that have autocompletion.

      So it's better to write more understandable code even in competitive programming. This way you can save time while debugging big codes.

»
7 лет назад, # |
  Проголосовать: нравится -12 Проголосовать: не нравится

Most of the IDE provide indentation. For spacing, you can use IDE like Pycharm because you can reformat your code according to pep8 convention in single click.

For good looking codes, you can codeforces filter + sorting feature.

Steps
  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    By your steps, you might end up getting python codes or codes which are compressed!. I randomly picked few problems and checked shortest solutions, here are some solutions 1 2

»
7 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

Did you miss Petr?

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I always write my variable names all the way out and spam comments. That's never a bad idea, especially when you are debugging.

»
7 лет назад, # |
  Проголосовать: нравится +11 Проголосовать: не нравится

I always thought that tourist solutions were simples and easy to read. I like his style very much. Take do some time to solve old contests which he took place. Compare your solutions with his.