+ 27
How to write a beautiful code ?!
Codes are seen in many different ways , in people's eyes it is just a random letters written by an alien , but in programmer's eyes it contains a lot of meaningful words , so how to make my code looks more elegant and organized ?
27 Antworten
+ 27
Your code would more self-explanatory possible without comments.
Comments would be used only for explaining motivations behind code.
Names have to follow one preferred style and have to explain, at basic, to what name referring.
Remove use of anonymous names (like lambda functions) except in very simple and oblivious cases.
Appropriated indentation and spacing between block codes and/or global names (like class definitions).
Make the code more modular possible.
Make the code modular to file level also.
Every module (logical and/or file) would have only definitions of names needed for that module and nothing more.
+ 27
Use Comment After Each Section Dear!!!😊✌
+ 18
Could also use a code formatter/beautifier. There are several free online for different code languages.
+ 16
- Use indentation neatly
- Name your function sensibly
- Organize your code, don’t have bits and pieces all over the place
+ 15
Don't write very long lines, it can seriously increase reading difficulty, and it's annoying if you have to scroll right to see everything.
+ 15
Da2 OK , i rephrased the question, I was talking about JavaScript , but all the answers that the community gave me was useful, so thanks to all !
+ 12
May have some subjectivity, but still important for coding, because code has to be read and understood and maintained. No waste of time thinking about this.
+ 11
HonFu I said subjective because, it depends on the target language. Clean code is about technique. To my mind, what is more important is the system documentation. In the case of OOP, UML help articulate what the code is all about.
+ 10
Just keep practicing and look others expert code then you will be see the pattern which one is clean
+ 10
Also don't use source code files with thousands of lines of code. Conversely don't use too many files with just a few lines of code either. Strike a balance.
+ 10
Hey missdials, please don’t spam in SoloLearn!
https://www.sololearn.com/discuss/1316935/?ref=app
+ 8
That is a very subjective question. Please re phrase it
+ 8
Read others codes
+ 8
1. Follow naming convention.
2. Name functions short but descriptive and provide a general comment.
3. Limit amount of comments. Too much - code hard to read, too few - no understanding what code does.
4. Organize your code, use multiple files if possible.
+ 8
With Determination, Effor, Passion... AND COMMENTS!!!
+ 7
Also write comments in the code to tell the details and what a part of code does
+ 7
I would strongly recommend the followings:
1. (The most important one) Commenting your code helps you understand the codes and the algorithms.
2. Separate the whole program into separate classes. This helps debugging your program.
+ 6
* Write simple and clear code, at least for yourself.
* Practice, practice and practice again, solve problems.
* Read forums, develop, programming does not stand still.
* Create code, because only this way you can develop the skills of beautiful code writing
+ 6
i. Follow proper indentation.
ii. Don't use random variable and function names.
iii. Comment your code.
+ 6
Write in a properway to look codes beautiful!