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 | 4009 |
2 | jiangly | 3773 |
3 | Radewoosh | 3646 |
4 | ecnerwala | 3624 |
5 | jqdai0815 | 3620 |
5 | Benq | 3620 |
7 | orzdevinwang | 3612 |
8 | Geothermal | 3569 |
8 | cnnfls_csy | 3569 |
10 | gyh20 | 3447 |
# | User | Contrib. |
---|---|---|
1 | awoo | 161 |
2 | maomao90 | 160 |
3 | cry | 158 |
4 | atcoder_official | 156 |
4 | nor | 156 |
6 | -is-this-fft- | 155 |
7 | maroonrk | 154 |
8 | adamant | 153 |
8 | Um_nik | 153 |
10 | djm03178 | 146 |
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.