Should perhaps get its own forum. But let’s try it out in a single thread to see if there is any interest.
Any code can be posted, any user can review.
Should perhaps get its own forum. But let’s try it out in a single thread to see if there is any interest.
Any code can be posted, any user can review.
So, JimL, what do you mean Code review? A discussion about PHP code? Or Services?
Code review is normally a step between development and testing where we have code that works but should be checked by another developer to see if it conforms to code styles, or if there are improvements that should be done
I see. Yes, that step is important. I think the issue of “code styles” can open a huge door into a thread
that can go on for years! LOL I find that most programmers have their own styles. I also noticed that
most programmers who work in an organizations have to abide by the company’s rules.
This can also bring up various other interesting issues. Such as MySQL vs MySQLi vs PDO. I get really
very tired of some people trying to push others to use THEIR version of this. I always use MySQL because
my personal programming is fun stuff and I normally do not need to publish it for a company. Therefore,
I now use MySQLi as it is the latest for that code. PDO is best if you use OOP. For anyone who does not
know OOP is Object Orientated Programming. I do feel that OOP is the better way to go and therefore
that PDO is better, too. BUT, most people on this site are learning something. So, mention OOP might be
better in the long run, but, let them use MySQLi if they already have the code set up like that.
I do feel that there are a ton of simple things that should be or even MUST be done in PHP programming.
Some things are simple, like adding comments! Why do people learn code and see comments in every
single example they learn from and then put no comments into their own code? Crazy!!! And, like when
they add in functions. Most people do not understand that PHP searches the current file when it needs to
call a function. Place your functions at the top of the page. Most experienced programmers load all of their
functions into a separate file and use and INCLUDE to add it at the top of the page. I find a lot of newbies
put functions inside of IF clauses. Crazy flow to do that. You want IF’s, FOR’s, While’s and all loops to be
as short as possible.
Well, there is a bit to get the thread started… Hope that is what you were looking for…
Absolutely
Yeah in an organization you kind of have to stick to a common convention.
Sure, as long as you don’t need to support different types of storages then mysqli and pdo are pretty much equal. Then we can argue over the differences later. Like PDO silently falling back to “fake” parameterized queries, and mysqli having a much more verbose bindParam syntax.
Why is PDO better for OOP?
I rarely write comments, I actually get really frustrated when I see code where people have commented everything they do. I suggest you read Clean Code.
Basic jist of the comment issue is, if you have to comment it, then you can probably refactor the code so it’s easier for the next guy to understand it. If you can’t immediately see what is going on, then you are probably doing it wrong. Good code structure, good function and variable names, etc help you with not having to write comments. Of course there are those special cases where you can’t get by without explaining what the *** you are doing. But that’s rare.
With inexperienced/hobby programmers you see all kinds of crazy. Hopefully most professional programmers today structure their code in some oop/mvc type of fashion.
Definitly, actually many guidelines have a strict “max x lines per method” rule
Was actually suggesting people post code they were wondering if could/should be improved ^^
I agree with your comments. The PDO is like OOP comment is the that the general layout with =>'s and
all make it feel a little like OOP’s. I get that comment from many newbies that ask if that is OOP or not,
then have to explain, well sort of in the “look” area, but…
And, I disagree with comments. Yes, a professional does not need much of them. Unless several different
programmers share the code and are at different levels of experience. On this site, I ALWAYS add many
comments. Here, we are mostly helping new programmers or weak ones. They need as much help as they
can get. Therefore, short comments explaining what you and I would think of as simple and straightforward
will help them. Then can delete the comments once they understand the code.
Hmmmmm, want code samples to tear apart?
In one of the posts that I just replied to from Princess, not sure, Web Princess? She, had code where she
was altering a tab system inside of a WP template. I had this same problem before and manually figured
out a work-around. But, her code was, loosely, like this in many places:
<?PHP last code; ?>
<html code>
I just can not see any reason in the world for that type of layout. Even if she was using some sort of
canned programming tool that sticks in code snippets, why would you want to do that? It slows down
the PHP parser. The parse stops, restarts, stops, etc. It adds unneeded chars and slows down loading.
Just makes no sense to me. Any reason you can think of to have that type of formatting?
Hm, I wrote a response to this but it seems to be gone… -_-
I’m not so sure, I think mysqli looks pretty much the same. note that the comparison below isn’t really fair, to make it fair you would have to change the pdo one to use bindParam and bindResult, like the mysqli example. But they all in all look very much the same
[php]$mysqli = new mysqli(“localhost”, “my_user”, “my_password”, “world”);
if (mysqli_connect_errno()) {
printf(“Connect failed: %s\n”, mysqli_connect_error());
exit();
}
$city = “Amersfoort”;
if ($stmt = $mysqli->prepare(“SELECT District FROM City WHERE Name=?”)) {
$stmt->bind_param("s", $city);
$stmt->execute();
$stmt->bind_result($district);
$stmt->fetch();
printf("%s is in district %s\n", $city, $district);
$stmt->close();
}
$mysqli->close();[/php]
[php]$dbh = new PDO(‘mysql:host=localhost;dbname=test’, $user, $pass);
$sql = ‘SELECT name, colour, calories
FROM fruit
WHERE calories < :calories AND colour = :colour’;
$sth = $dbh->prepare($sql);
$sth->execute(array(’:calories’ => 150, ‘:colour’ => ‘red’));
$red = $sth->fetchAll();[/php]
I agree, comments here where you show people how code works makes perfect sense. I was talking about when you normally code/implement stuff though, that’s when you shouldn’t have to use comments.
No
Yes, I agree on all your comments. I think of OOP as creating an object and then using -> to access sub
parts of it. A simple way to look at it, but… So, PREPARED statements remind me of that and PDO, too.
I guess since I do not really use PDO much as my projects are simple ones not for mass consumption, I just
like the simpler looking MySQLi. (And, easier for newbies to follows as most of them use it.) So, I guess I am
not explaining myself very clearly in those comments…
For anyone reading this thread, everyone that I talk to who is a professional programmer have all mentioned
that they feel PDO is the way to go. It is very interesting to note that I am an old fart and have seen about
500+ web programming languages that are long gone and for some reason I really like my PHP and MySQLi.
My 2 cents… That combo does just about anything I want done. Well, with some fancy CSS and maybe
even a little JS/JQuery for animations thrown in… LOL
I will try to come up with some code samples to ask if there are better ways to do for you and the thread.
There is one question about arrays, but, not ready to ask right now… Have to find the code first…