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 | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
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.