0
Best Practices For Coding (Intro)
Posted by Danielle Smith
on
12:46
in
Best Practices
I have mentioned previously in past blog posts how important it is to ensure that the names of your tables, views and columns are well thought out and consistent. However, if you are creating transactional statements or using any form of programmable code at all, it is also important to follow guidelines in order to improve the code’s readability, accessibility and re-usability. With SQL – you can get away without doing this but why would you? You’re just making things harder for yourself if another developer has to look at and potentially expand on your code yet they can’t work out what it’s supposed to be doing!
The idea of this blog post is to simply provide an introduction or taster to my next series of blog posts highlighting the best practices for SQL coding (or at least – ones which I have researched in the past and adhered to that appear to work very well).
So when reviewing your code, make sure you ask yourself the following:
What makes SQL so different to other programming languages is that you can’t press a button and it will automatically indent everything to make it look wonderful like you can in Visual Studio (Ctrl K+D). There is no standard layout.
Code that you can’t even access is a complete no-no as it wastes time and effort to implement.
Why would you want to rewrite an entire transaction when you have already got the exact same one referenced in another function on the same database instance?!
As a junior, it's ok to think of these questions after you have coded something before it goes to peer review (after all, providing it works in the first place that's a good thing right? That's the first hurdle jumped). However as you gain more experience, you begin to foresee things more often and you should have those questions in the back of your mind as you're coding. This will make your solutions much more reliable.
Next week I am going to really hone in on what makes your programming code successful and as usable as possible, starting with code readability best practices. Stay tuned for that!
Happy Friday everyone – hope you all have a great weekend!
The idea of this blog post is to simply provide an introduction or taster to my next series of blog posts highlighting the best practices for SQL coding (or at least – ones which I have researched in the past and adhered to that appear to work very well).
So when reviewing your code, make sure you ask yourself the following:
Code Readability
- How easy it is to read the code and follow it through?
- Can you tell what the code is doing at a glance?
- Does the code look neat?
What makes SQL so different to other programming languages is that you can’t press a button and it will automatically indent everything to make it look wonderful like you can in Visual Studio (Ctrl K+D). There is no standard layout.
Code Accessibility
- Is all code accessible at execution time?
- Are there any instances where you know that a part of your code will be skipped and will never be executed?
Code that you can’t even access is a complete no-no as it wastes time and effort to implement.
Code Re-Usability
- Is code concise with no repetition?
- Have you used functions and referred back to them as and when they're needed?
Why would you want to rewrite an entire transaction when you have already got the exact same one referenced in another function on the same database instance?!
As a junior, it's ok to think of these questions after you have coded something before it goes to peer review (after all, providing it works in the first place that's a good thing right? That's the first hurdle jumped). However as you gain more experience, you begin to foresee things more often and you should have those questions in the back of your mind as you're coding. This will make your solutions much more reliable.
Next week I am going to really hone in on what makes your programming code successful and as usable as possible, starting with code readability best practices. Stay tuned for that!
As A Final Word...
Thank you for reading today's blog post! If you have any questions/comments/feedback, please leave them in the comments section below and I will get back to you as soon as I can. Alternatively, please like my SQL Genius Facebook Page and leave a message on there. Thanks! :)Happy Friday everyone – hope you all have a great weekend!
Post a Comment
Please post any feedback or comments here...