+ 12
What exactly is best practices in programming?
Please can someone explain clearly with example?
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.
+ 12
The answer is in your question:
Practicing is the best practice!
+ 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.đș
+ 5
produce working programs
0
A brief seminar about clean code:
https://m.youtube.com/watch?v=UjhX2sVf0eg