I see, from time to time, that people say that SQL query that is sent to a server from client application should not contain any extra linebreaks or spaces. One of the reason I've heard is "why waste network traffic?".
Is there a real reason to make code harder to read and edit in favor of removing all spaces?
With spaces:
$q = 'SELECT
`po`.*,
`u`.`nickname`,
`u`.`login`
FROM
`postponed_operations` AS `po`
LEFT JOIN `users` AS `u` ON `u`.`id` = `po`.`user_id`
ORDER BY `will_be_deleted_after`';
return mysql_query($q);
Without spaces:
$q = 'SELECT '.
'`po`.*,'.
'`u`.`nickname`,'.
'`u`.`login`'.
'FROM '.
'`postponed_operations` AS `po` '.
'LEFT JOIN `users` AS `u` ON `u`.`id`=`po`.`user_id` '.
'ORDER BY `will_be_deleted_after`';
return mysql_query($q);
It is true, it will cost network traffic and server time; but it will be negligible on all except the most extreme cases. Now, if you are editing the code of FaceBook (or Google, or similar), and optimize in this way the 10 most common queries, then there is a point, since they will be run billions of times per day. But in all the other cases I think it is a waste of time to consider removing spaces.
This is subjective, but readability beats the few extra spaces and line breaks anytime in my opinion. And if coding standards would dictate to break of out the string every time, I'd probably go insane.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With