Jump to content

Does anyone use PHP like this?


proggR

Recommended Posts

I'm working on an assignment in a Client Server class right now and the teacher wants us to make an include file. Nothing irregular there. Except what she wants it to contain is code like this:

<?php 
function writeHeaders(){
echo '<html>';
echo '<head>';
echo '<title>TITLE</title>';
echo '</head>'
echo '<body>';
}
?>

 

.. and so on with another function for footers, a textbox, button and prompt.

 

Now I could tell right away she isn't the most familiar person with PHP but does anyone ever actually code like this? I can see echoing HTML tags if its a navigation menu or if its for formatting on dynamic content but for that?

Anyway, let me know. I'm debating between sucking it up and writing some of the most efficient code, as requested, that I've ever written or emailing her and explaining that I will not be writing an include file like this and will make one more sensible.

Anyway. I'll be interested in hearing some replies :P

Link to comment
Share on other sites

^- what he says.

 

Of course there are people who code like this and they can probably earn money doing this.

Thing is: I know it's ugly, you know it's ugly. Your teacher doesn't yet, but if you tell her in private, she might not get angry at you, and let it do it your way. If she doesn't, just do how she likes it and refrain from witty remarks. Your goal here is to get best possible score, not to write the best possible code.

Link to comment
Share on other sites

I've never coded exactly like that, but I have on occasion used a similar style with regards to having a single line of HTML on a single line in the file etc. In some circumstances I have just found that it makes the code slightly easier to read.

Link to comment
Share on other sites

Lol good to hear I'm not crazy.

The rest of the assignment is pretty bad too. At least its something I can knock out in an hour and never have to think about again.

I considered benchmarking my code vs her code and including the results in a comment along with a lesson on what things she's doing wrong but I don't think she'd like that :P

Link to comment
Share on other sites

Lol good to hear I'm not crazy.

The rest of the assignment is pretty bad too. At least its something I can knock out in an hour and never have to think about again.

I considered benchmarking my code vs her code and including the results in a comment along with a lesson on what things she's doing wrong but I don't think she'd like that :P

 

Speed isn't everything though. Otherwise you picked the wrong language.

Link to comment
Share on other sites

I've had similar experiences. In fact, currently I'm taking a web design course which is horrible. The course is designed as if the web hasn't changed over the past 10 years, and we're being taught horrible practices left and right. I just have to bite the bullet and take the easy A, I suggest you do the same.

Link to comment
Share on other sites

Speed isn't everything though. Otherwise you picked the wrong language.

I know that there should be a balance of speed and readability. But just because PHP isn't as fast as Perl or Ruby doesn't mean I can't try to make it as efficient as possible.

I've had similar experiences. In fact, currently I'm taking a web design course which is horrible. The course is designed as if the web hasn't changed over the past 10 years, and we're being taught horrible practices left and right. I just have to bite the bullet and take the easy A, I suggest you do the same.

Ya mines the same. I was considering spending some time evaluating all of the courses and mentioning the good things and how to improve the bad as well as mentioning what courses should be dropped and replaced with what and proposing it to the co-ordinator and dean. I mean COBOL on the PC? Really? Why not teach it starting on the mainframe like it should be taught.

Link to comment
Share on other sites

I know that there should be a balance of speed and readability. But just because PHP isn't as fast as Perl or Ruby doesn't mean I can't try to make it as efficient as possible.

 

Ruby is almost as slow as PHP, perhaps even slower since 5.3. What Daniel is trying to say is that you shouldn't go out of your way to try to improve performance, at the expense of software design, readability, maintainability, whatever. Because that sort of micro- optimizations really don't make much difference, doing more harm than good. If you really want well performing applications, write everything in C. Otherwise, focus on more important things during development, profile the performance *afterwards*. Then you can apply some improvements, if needed.

Link to comment
Share on other sites

Create a file like this:

<html>
<head>
<title>My Page</title>

 

And write a simple program to convert it into one your teacher likes:

echo '<html>';
echo '<head>';
echo '<title>MyPage</title>';

 

:)

Lol I should. I saw one like that for javascript before I had ever used PHP. I was going to use it similar to an include(). Thank god I learned PHP instead.

Link to comment
Share on other sites

Create a file like this:

<html>
<head>
<title>My Page</title>

 

And write a simple program to convert it into one your teacher likes:

echo '<html>';
echo '<head>';
echo '<title>MyPage</title>';

 

:)

 

And put the preprocessor with the files you hand in.

Link to comment
Share on other sites

This is how I do it:

 

<?php
$path = "";
$title = "Home";
include ($path."core/main.php");
echo "<b>".getHomeValue("title")."</b>";
echo "<HR>";
echo getHomeValue("content");
$footer = true;
include ($path."core/main.php"); 
?>

 

I like it.

Link to comment
Share on other sites

I include it twice because when $footer = true then shows the footer. I got to thinking though, I could include it once then write a function. what it really does is call the footer include file.

 

I think the getHomeValue pulls content from the DB, can't remember.

Link to comment
Share on other sites

HTML in business logic is bad in my opinion. It should be completely separated. The main reason for this is that if you are working in a team where there are developers and designers and you the developer writes code like this you are expecting the designer to also understand code so that they can ammend the website template.

Designers should work with templates only and not delve into your business logic.

Link to comment
Share on other sites

Here is the handout. I didn't have a digital copy of it until now. Look at this mess. Rather than using auto increment she wants us to calculate the ID values in the table. I'm taking it up with the coordinator after the assignment and test. Other people in my class that have used PHP are just as baffled as me. And I feel bad for the students who haven't used it.

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

Remember this stuff is case sensitive.

 

Uh... PHP is not case sensitive when it comes to function and class names, and the case sensitivity of identifiers in MySQL depends on the lower_case_table_names setting. As for case sensitivity in field values in MySQL, that depends on the collation you're using. Unless you pick a binary collation it will most likely be set to a case insensitive one.

 

Also, why the hell is she sending you a .doc file with macros in it? Send a PDF or something like that.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.