+ 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 ?

3rd Mar 2019, 6:45 AM
Bono
Bono - avatar
27 Respuestas
+ 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.
3rd Mar 2019, 7:45 AM
KrOW
KrOW - avatar
+ 27
Use Comment After Each Section Dear!!!😊✌
5th Mar 2019, 4:01 PM
K͜͡ɩnɢ・ムzizi 🖤
K͜͡ɩnɢ・ムzizi 🖤 - avatar
+ 18
Could also use a code formatter/beautifier. There are several free online for different code languages.
4th Mar 2019, 7:35 PM
Candyopoly
Candyopoly - avatar
+ 16
- Use indentation neatly - Name your function sensibly - Organize your code, don’t have bits and pieces all over the place
3rd Mar 2019, 7:04 AM
Rowsej
Rowsej - avatar
+ 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.
3rd Mar 2019, 8:20 AM
HonFu
HonFu - avatar
+ 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 !
4th Mar 2019, 2:08 AM
Bono
Bono - avatar
+ 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.
3rd Mar 2019, 11:22 AM
HonFu
HonFu - avatar
+ 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.
4th Mar 2019, 12:10 AM
Da2
Da2 - avatar
+ 10
Just keep practicing and look others expert code then you will be see the pattern which one is clean
3rd Mar 2019, 11:06 PM
Irwan Sulistyo
Irwan Sulistyo - avatar
+ 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.
4th Mar 2019, 1:26 AM
Sonic
Sonic - avatar
+ 10
Hey missdials, please don’t spam in SoloLearn! https://www.sololearn.com/discuss/1316935/?ref=app
7th Mar 2019, 6:01 AM
Rowsej
Rowsej - avatar
+ 8
That is a very subjective question. Please re phrase it
3rd Mar 2019, 10:26 AM
Da2
Da2 - avatar
+ 8
Read others codes
4th Mar 2019, 8:35 AM
reza
reza - avatar
+ 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.
4th Mar 2019, 1:07 PM
Marcin Siniarski
+ 8
With Determination, Effor, Passion... AND COMMENTS!!!
8th Mar 2019, 8:43 AM
Tadeo Deluca
Tadeo Deluca - avatar
+ 7
Also write comments in the code to tell the details and what a part of code does
3rd Mar 2019, 7:26 AM
Aditya Kannojia
Aditya Kannojia - avatar
+ 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.
4th Mar 2019, 2:18 PM
keivan Ipchi
keivan Ipchi - avatar
+ 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
3rd Mar 2019, 10:06 PM
Ilgam
Ilgam - avatar
+ 6
i. Follow proper indentation. ii. Don't use random variable and function names. iii. Comment your code.
4th Mar 2019, 6:23 AM
Veda Shree S
Veda Shree S - avatar
+ 6
Write in a properway to look codes beautiful!
4th Mar 2019, 3:05 PM
Imran Alam
Imran Alam - avatar