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

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

Hello everyone! In contests when i get the code wrong, one of the things that put me down is styling. In other words,the code works,sometimes,but when something goes wrong and i start debugging, it's very hard to read your own code under the contest conditions. There are lots of top-rated users who have well styled code (eg jiangly) and I just cant write like that.

Questions for you:

How do you manage to have clear variable names that are still easy to type? Do you make many macros/defines or is it a bad practice to do so? Do you have some tips on speeding up debugging process (I write lots of cerrs and doing so is pretty slow)?

Do you use auto-formatter or do manually all formatting? if you use one can you tell me the name or provide the link to it becouse i cant find one. Of course, in CP, clean code doesn't play an as big role as knowledge of algorithms, but I guess it may help me save my time and avoid bugs.

(also my dad said i am writing dirty code and gave me a total of 1000 pages of books about clean coding so i now have to write clean code too)

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

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

solve more problems. if you notice a code pattern keeps causing issues while debugging, try to rethink that habit

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

Learn from other users codes like jiangly

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

Auto comment: topic has been updated by ilexis (previous revision, new revision, compare).

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

Clean code come from practicing and looking at others code (so maybe they use a faster techniques or shorter codes) you can see the names of the variables they use . As you mentioned, Jiangly is the best person to look at their code. I use a VSCode builtin formatter, it helps alot in understanding the code . Am not sure if those books are useful but I didn't use any till now and there is no problem with that I think.

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

You can use Allman programming style like me for easy code understanding. Here is example of the style:

#include <iostream>
using namespace std;

void test(int a)
{
   while(a--) 
      cout << "Hello World!" << endl;
}

int main()
{
   //test(4);
   int x;
   cin >> x;
   test(x);
   return 0;
}
»
3 недели назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

use python