ilexis's blog

By ilexis, history, 4 weeks ago, In English

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)

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

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    4 weeks ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    i am pretty blind of a person and i cannot observe myself can you tell me an example of the code patterns you found that slowed you?

    • »
      »
      »
      3 weeks ago, hide # ^ |
       
      Vote: I like it +4 Vote: I do not like it

      if you're not going to put in the effort into finding the pattern, nobody can give you the answer on a silver platter. nobody lives inside your brain to know how you think and code except you

      • »
        »
        »
        »
        3 weeks ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        you cannot know the dark is dark until you see the light

        • »
          »
          »
          »
          »
          3 weeks ago, hide # ^ |
          Rev. 2  
          Vote: I like it 0 Vote: I do not like it

          Read the editorial once after you've solved the question, You'll surely find a better and neat implementation.

          • »
            »
            »
            »
            »
            »
            3 weeks ago, hide # ^ |
             
            Vote: I like it 0 Vote: I do not like it

            Pitiful, that don't work on me. After solving a problem i always find out that I am too lazy to think about editorial way.

  • »
    »
    4 weeks ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it

    I would also say that you should think about the answer clearly before you start writing the code.

»
4 weeks ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

Learn from other users codes like jiangly

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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 weeks ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    thanks bro thanks to you when i googled Allman programming style i saw "Linux style" and realized how familiar i am with it. i will try to ,mplement my next proplem according to it- while also trying not to spend a lot of time styling my code

  • »
    »
    3 weeks ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    allman is just about how to indent and format your code, something that rarely causes issues

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

use python