+9

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;

2/12/2020 7:27:31 PM

Majid Isaev

22 Answers

New Answer

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

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

+8

Beauty, so they say, is in the eye of the beholder. The way you write your code is referred to as a style. Some companies, software houses, and organisations may specify a particular style and publish a style guide which must be adhered to. For example see... https://google.github.io/styleguide/javaguide.html https://www.oracle.com/technetwork/java/codeconventions-150003.pdf NASA C Style Guide https://ntrs.nasa.gov/search.jsp?R=19950022400 NASA C++ Coding Standards and Style Guide https://ntrs.nasa.gov/search.jsp?R=20080039927 https://www.gnu.org/prep/standards/standards.html https://docs.python-guide.org/writing/style/ So while having your own style may suit you it may be unacceptable if you have to edit someone else's code. To this end there are tools such as "indent", mentioned by Roman J, which will format code to the desired style. Correct formatting of code is of such importance that some revision control systems can actually be configured to run tools like indent automatically prior to committing the code, thus enforcing a particular style on a project.

+5

I really like the compactness of the code! But then it becomes unreadable to others(

+5

Honfu is right

+4

If you like compactness that much, then you can learn Python to embrace the beauty of oneliners 👍

+4

Ipang, Python oneliners, aka code boulders, aren't exactly readable either. 😅

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

+3

Read carefully what HonFu wrote!!

+3

That's right, you can play some serious golf with Python. 😉

+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

+3

For Python code, make it Pythonic.

+2

Create on basis of ur own style Take help from others and Have trust on yourself. Try to make it attractive so people people could find it bright and unique.

+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

+1

HonFu Maybe not, but no one can deny the compactness of oneliners. Everything comes with a price tag, but compactness speaking, oneliners -> unbeatable 😁

+1

Abderrahmane Ahmam, thank you!)

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.

0

I know Python)))

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.

0

HonFu, thanks! It's good idea)