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,
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
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,
Name |
---|
John Dethridge in TopCoder.
Its hard to find topcoder submissions, seems he is not much active these days as well, btw thanks, your codes are also elegant :)
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.
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).
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.
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.
Goto status page and use the 'Status filter' to filer submissions according to problem and programming language.
Goto bottom of the page and click 'Solution Size'.
Note — This will give you codes sorted according to their length. This way you can learn how to write short and neat code.
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
Yes ignore first few because people remove spaces to get on top.
Did you miss Petr?
I always write my variable names all the way out and spam comments. That's never a bad idea, especially when you are debugging.
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.