How to learn to write code beautifull? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 10

How to learn to write code beautifull?

3 years I worked on one game engine, where I have a different programming language! There you haf to write the cofe closely. That wad the syntax! So I'm used to write the code closrly, and this is very harmful to the beauty of the code. For example: 1) Closely: int x; cout << "PIN Lock One \n\n"; do {cout << " Enter PIN code: ";cin >> x; if (x != 31254 ) {cout << "False! \n";} while (x != 31254); cout << "True!"; return 0; 2) Beauty: int x; cout << "PIN Lock One \n\n"; do { cout << " Enter PIN code: "; cin >> x; if (x != 31254 ) { cout << "False! \n"; } } while (x != 31254); return 0;

12th Feb 2020, 7:27 PM
Majid Isaev
Majid Isaev - avatar
19 Answers
+ 10
The source code is only that - a source. From there it gets compiled and becomes the actual executable machine code, that hardly anyone (no one?) would be able to read. It doesn't matter how the source code looks, it's got nothing to do with the program anyway. So you can do with it what you want. However, what if you want to change the code months later, after you have forgotten many details of what you wrote there? What if you want to add new functionality, improve an algorithm, find a bug? What would make this most easy for you? And what would make it harder? There are different styles how you can format code. But if you don't care about formatting at all, not only will it be hard for yourself to understand your own code (weeks or months later), but also it will be even harder for other people, for example when you're working on a team. And yeah, some parts are confusing even if you format them well. In these cases, comments will help.
12th Feb 2020, 8:19 PM
HonFu
HonFu - avatar
+ 10
Find your own style. There is no absolute truth. It is ok if you think it is ok. But your opinion will change during the years. add comments if you become too compact.
12th Feb 2020, 7:52 PM
Oma Falk
Oma Falk - avatar
+ 5
I really like the compactness of the code! But then it becomes unreadable to others(
12th Feb 2020, 7:30 PM
Majid Isaev
Majid Isaev - avatar
+ 4
If you like compactness that much, then you can learn Python to embrace the beauty of oneliners 👍
12th Feb 2020, 11:15 PM
Ipang
+ 4
Ipang, Python oneliners, aka code boulders, aren't exactly readable either. 😅
12th Feb 2020, 11:20 PM
HonFu
HonFu - avatar
+ 4
Good indentation, adequate whitespace, methods/functions for repeating code blocks, not cramming too many statements in one line, relevant and succinct comments are a start.
13th Feb 2020, 2:40 AM
Sonic
Sonic - avatar
+ 3
Read carefully what HonFu wrote!!
12th Feb 2020, 8:21 PM
Oma Falk
Oma Falk - avatar
+ 3
That's right, you can play some serious golf with Python. 😉
13th Feb 2020, 12:21 AM
HonFu
HonFu - avatar
+ 3
You can learn it by experience and using OOP for writing a clean code and also u can use some extension in ur Editor for help you organized ur code I think that's help u and good luck
14th Feb 2020, 6:09 PM
Abderrahmane Ahmam
Abderrahmane Ahmam - avatar
+ 3
For Python code, make it Pythonic.
15th Feb 2020, 1:24 PM
Sonic
Sonic - avatar
+ 2
Host: localhost:3001 Accept: text/html Accept-Language: en-US,en;q=0.5 Connection: keep-alive Content-Type: multipart/form-data; boundary=-1233445 Content-Length
15th Feb 2020, 10:07 AM
Yohanes Belau
Yohanes Belau - avatar
+ 1
HonFu Maybe not, but no one can deny the compactness of oneliners. Everything comes with a price tag, but compactness speaking, oneliners -> unbeatable 😁
13th Feb 2020, 12:19 AM
Ipang
+ 1
Abderrahmane Ahmam, thank you!)
14th Feb 2020, 6:55 PM
Majid Isaev
Majid Isaev - avatar
0
It is really explainable about the coding.I want to add on that I am unable to take screenshot from my mac book for a couple of days.I have tried out the manual configurations as instructed by the support team to figure out this consequences regarding the https://applemacsupportnumbers.com/blog/imessage-not-working-on-mac/ Suggest what to include to resolve this issue permanently.
13th Feb 2020, 3:52 AM
Valucia Morris
0
I know Python)))
13th Feb 2020, 10:02 AM
Majid Isaev
Majid Isaev - avatar
0
It's all on hands-on experience. Or that's the case with me at least. 3 months ago, I had trouble creating tables in HTML. Now, I just fished creating my first website. You can learn all you want, but I believe that the way to actually get used to it is by just starting new projects and creating codes. Experiment to what you like and how things are more comfortable for you. For example, I like inserting my CSS right into my HTML instead of creating a .css file.
13th Feb 2020, 2:15 PM
Kristofer Schultheis
Kristofer Schultheis - avatar
0
HonFu, thanks! It's good idea)
13th Feb 2020, 3:31 PM
Majid Isaev
Majid Isaev - avatar
0
Ipang, I studied python about a year ago. There I didn't bother with this question) I used the standard IDE. It's easy to work with syntax.
13th Feb 2020, 3:39 PM
Majid Isaev
Majid Isaev - avatar
- 1
Does anyone know how to cout and cin char variables to cout all the variables together?
13th Feb 2020, 9:26 PM
alex
alex - avatar