“What’s in a name? That which we call a rose by any other name would smell as sweet.” - Juliet
Well Romeo, try calling her by a different name and thy shalt see ! Anyway, let’s talk about contemporary programming - and how polyglottic it has become. It is not uncommon for a developer to think in more than one language at the same time.
Just like you have a Mother Tongue, you have a programming language that you are more biased towards. It is but natural that your style of programming is heavily influenced by that language. Let’s call it “C”.
NO-SQL not withstanding, you are pretty good at oracle databases and a database scripting language called “PL/SQL” . You are currently working on a PL/SQL script that needs to update the user name in a table called “USER” with following columns
The function you have written in PL/SQL to do this.
PROCEDURE prc_update_user_name(i_id IN NUMBER, user_name IN VARCHAR2) IS
BEGIN
UPDATE user
SET user_name = user_name
WHERE id = i_id;
COMMIT;
END prc_update_user_name;
Now like a good PL/SQL citizen, you have named your input variable for “id” as i_id , however being a better “C” citizen, you have used a variable name called “user_name”
What’s in a name, right ?
Now, let’s take another look at the update statement you have come up with.
UPDATE user
SET user_name = user_name
WHERE id = i_id;
You had all the good intention of setting the user name in table to the value being sent to the procedure. But if you notice the set statement, it has “user_name = user_name” , which is essentially a “no-op” in SQL. You are setting a column to it’s own value.
You will not get any compiler warning while compiling this code but when the code is executed, the column user_name will never be updated.
The example is trivial and hence easy to spot the problem. However, if you are writing complex functions with multiple parameter and multiple statements, this error can easily go unnoticed until you really test your code for every column that is being updated.
Bottom line – Coding conventions are important and it is important to take some effort and learn coding style recommended for each language. Your code will look cleaner, professional and you will avoid problems like this.