What exactly is best practices in programming? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 12

What exactly is best practices in programming?

Please can someone explain clearly with example?

24th Mar 2017, 1:42 PM
Wisdom Abioye
Wisdom Abioye - avatar
5 Answers
+ 40
I don't have high experience also @Agus just a person interested in programming and read related book. The best answer would be read books like code complete, The Pragmatic Programmer . @Ace sir please post your view also. What is best practices? --> Best practices are simply the most recommended way of writing a segment of code. Here are some practices that i try to follow. 0. Naming: Few weeks ago SoloLearn gave a notification for Learn Ruby app "Declare Variables Not War". Try to name your variable and classes understandable. 1. Comment as per necessity means don't write comments for cases which is self explanatory. Nowdays IDE you use will generate better comment than you. 2. "Format" is necessary for readablity. eg. Try to use private variables instead of Public "Working on this one' Use proper indentation(I prefer 4) and style K&R, Allman, PEAR but stick to one throughout your code. Use ternary operator : result = testCondition ? value1 : value2 Put a space after each comma in comma-delimited lists Avoid Deep Nesting Best one "Break large, complex sections of code into smaller, comprehensible modules." Use RETURN statements in stored procedures Read others code. Programming practices will develop as you get more and more experienced "from hard-learned lessons". There are so many things i haven't talked about, > OOP vs Procedural > Code Refactoring > Design Patterns >Principles like KISS, DRY, YAGNI 2. Is the best practice always good? --> No for me. eg. We should write test code, but writing it everywhere would not be good. Design Patterns are over used and under utilised. 3. Conclusion: Using the best programming practice in the wrong context can cause more harm than good. Using solid coding techniques and good programming practices to create high quality code plays an important role in software quality and performance. This is just my opinion you may disagree with my answer. I would've written more examples from my threads also. @Agus Thanks.
24th Mar 2017, 4:59 PM
Ram chandra Giri
Ram chandra Giri - avatar
+ 12
The answer is in your question: Practicing is the best practice!
24th Mar 2017, 1:52 PM
Dev - avatar
+ 10
i can't answer this because i am lack of experience. Platinum Member (@Hatsey, @Ram, or @Krishna) will be more appropriate to give the best practices guide. However, in my opinion, you must always keep your code explicitly short.😺
24th Mar 2017, 2:15 PM
Agus Mei
Agus Mei - avatar
+ 5
produce working programs
24th Mar 2017, 2:26 PM
Cole Reizenberg
Cole Reizenberg - avatar
A brief seminar about clean code: https://m.youtube.com/watch?v=UjhX2sVf0eg
8th Sep 2017, 6:08 AM
Haris - avatar