Refactoring - Manage Your Code and Layers
When I say Code Management, most people tell me "I know exactly what I wrote... I know exactly where everything lays".
Well.. This sentence usually takes me back to when I was 6 or 7 years old. My mother used to tell me to clean and organize my room and that's exactly what I told her...:
"But mom... I love it when my soldiers are under the carpet, my school books are in the closet, my clothes are on my library and my shoes are where my action figures were.
I'm pretty sure most of you are nodding and agreeing with me. But this is wrong.
Back to development then...
There are several file types that should be in a unique folder (for each) in every project:
- JavaScript
- HTML
- CSS
JavaScript should not be inside "script
" tag.
CSS should not be inside "style
" tag nor inside the element
it's affecting.
And HTML... Well... HTML should be on its own.
Now I want to talk a little about classes. In every language we write, we should have different classes to achieve different functionality.
One of the most important classes out there is the DB Layer - Data Base Layer. Let's go over the basic terms:
DBLayer
- A class containing calls for the Views or Stored Procedures in the database.- Stored Procedure - SP - a function inside the database which is designed to
insert
/update
/delete
/select
from a table or from a number of tables. Stored Procedures can also returnDataSet
/DataTable
/String
/Int
/DateTime
according to specific parameters. Views
- AView
is a static query designed to be activated without any major changes (a view won't usually accept parameters. Stored Procedure will).
So, back to the management of the code.
The basic level is the GUI - Graphic User Interface - Meaning, what the user sees and works with.
The GUI is basically the HTML and CSS (in website development).
After that, we have the client side code - Scripts - JavaScript.
The JavaScript should usually be the one (or plain HTML elements "OnClick
" attributes) to activate the code behind functions.
After a client side element calls a server side function - the function should preform its functionality. Meaning, run through the code.
In most of the cases, a large part of the functions involve calling the datalayer
.
The Data Layer Class (or as I call it "DBLayer
") contains all the functions that should call the database. Since we want a neat and tidy code, we won't write Select
/ Insert
/ Update
/ Delete
/ Drop
inside the code.
This is not meant only for a clean code, this code moderation is basically for security reasons.
Example?
Let's say you have several projects that use the same database. On one of these projects, you have a friend working with you. Giving him full access permissions to Drop
and Truncate
Tables is not the best idea.
Eventually, the whole point of this post was to give a short explanation of how to correctly moderate your code. How it should be designed.
If your code isn't designed that way - That's the exact point of Refactoring... changing the design of the existing code without altering its functionality.
Thanks.
Elad,
Lead Developer at Sports Betting Tech
Post Comment
jpQhP8 Wow, great blog post.Thanks Again. Fantastic.