proggR Posted April 16, 2010 Share Posted April 16, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/198781-does-anyone-use-php-like-this/ Share on other sites More sharing options...
Daniel0 Posted April 16, 2010 Share Posted April 16, 2010 Seems sort of pointless to me. Also, I prefer my functions to have as little side effects as possible, so I would prefer if it returned the HTML instead of outputting it. Quote Link to comment https://forums.phpfreaks.com/topic/198781-does-anyone-use-php-like-this/#findComment-1043280 Share on other sites More sharing options...
Mchl Posted April 16, 2010 Share Posted April 16, 2010 ^- 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. Quote Link to comment https://forums.phpfreaks.com/topic/198781-does-anyone-use-php-like-this/#findComment-1043307 Share on other sites More sharing options...
cags Posted April 16, 2010 Share Posted April 16, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/198781-does-anyone-use-php-like-this/#findComment-1043333 Share on other sites More sharing options...
Mchl Posted April 16, 2010 Share Posted April 16, 2010 On a side note, for a writeHeaders() function, I would only put inside <head></head> tags (with whatever is between them) Quote Link to comment https://forums.phpfreaks.com/topic/198781-does-anyone-use-php-like-this/#findComment-1043336 Share on other sites More sharing options...
ignace Posted April 16, 2010 Share Posted April 16, 2010 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. If I only got that advice sooner.. Quote Link to comment https://forums.phpfreaks.com/topic/198781-does-anyone-use-php-like-this/#findComment-1043341 Share on other sites More sharing options...
Mchl Posted April 16, 2010 Share Posted April 16, 2010 It's experience speaking here... Quote Link to comment https://forums.phpfreaks.com/topic/198781-does-anyone-use-php-like-this/#findComment-1043347 Share on other sites More sharing options...
proggR Posted April 16, 2010 Author Share Posted April 16, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/198781-does-anyone-use-php-like-this/#findComment-1043359 Share on other sites More sharing options...
Mchl Posted April 16, 2010 Share Posted April 16, 2010 You can do that AFTER your score recorded in documents. Preferably AFTER you're sure you won't ever need to deal with her. Quote Link to comment https://forums.phpfreaks.com/topic/198781-does-anyone-use-php-like-this/#findComment-1043362 Share on other sites More sharing options...
Daniel0 Posted April 16, 2010 Share Posted April 16, 2010 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 Speed isn't everything though. Otherwise you picked the wrong language. Quote Link to comment https://forums.phpfreaks.com/topic/198781-does-anyone-use-php-like-this/#findComment-1043363 Share on other sites More sharing options...
Alex Posted April 16, 2010 Share Posted April 16, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/198781-does-anyone-use-php-like-this/#findComment-1043372 Share on other sites More sharing options...
proggR Posted April 16, 2010 Author Share Posted April 16, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/198781-does-anyone-use-php-like-this/#findComment-1043375 Share on other sites More sharing options...
448191 Posted April 16, 2010 Share Posted April 16, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/198781-does-anyone-use-php-like-this/#findComment-1043399 Share on other sites More sharing options...
roopurt18 Posted April 17, 2010 Share Posted April 17, 2010 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/198781-does-anyone-use-php-like-this/#findComment-1043449 Share on other sites More sharing options...
proggR Posted April 17, 2010 Author Share Posted April 17, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/198781-does-anyone-use-php-like-this/#findComment-1043570 Share on other sites More sharing options...
Daniel0 Posted April 17, 2010 Share Posted April 17, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/198781-does-anyone-use-php-like-this/#findComment-1043619 Share on other sites More sharing options...
Lamez Posted April 17, 2010 Share Posted April 17, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/198781-does-anyone-use-php-like-this/#findComment-1043751 Share on other sites More sharing options...
Mchl Posted April 17, 2010 Share Posted April 17, 2010 Why do you include main.php twice? What does getHomeValue() function do? Quote Link to comment https://forums.phpfreaks.com/topic/198781-does-anyone-use-php-like-this/#findComment-1043752 Share on other sites More sharing options...
Lamez Posted April 17, 2010 Share Posted April 17, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/198781-does-anyone-use-php-like-this/#findComment-1043755 Share on other sites More sharing options...
JonnoTheDev Posted April 19, 2010 Share Posted April 19, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/198781-does-anyone-use-php-like-this/#findComment-1044545 Share on other sites More sharing options...
448191 Posted April 19, 2010 Share Posted April 19, 2010 Screw the designers needs, just do it for the sake of SOC. Un- SOC leads to un- DRY code, leads to omfg who wrote this piece of shit (un- manageable).. Quote Link to comment https://forums.phpfreaks.com/topic/198781-does-anyone-use-php-like-this/#findComment-1044606 Share on other sites More sharing options...
TeddyKiller Posted April 19, 2010 Share Posted April 19, 2010 Whatever she asks, do it. Don't mess with the women! There deadly! Personally it's a bad idea... I prefer it tidier.. but yeah. You don't particularly want to do something better than what she suggests.. and totally fail because you didn't do what you was told. Quote Link to comment https://forums.phpfreaks.com/topic/198781-does-anyone-use-php-like-this/#findComment-1044609 Share on other sites More sharing options...
proggR Posted April 19, 2010 Author Share Posted April 19, 2010 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] Quote Link to comment https://forums.phpfreaks.com/topic/198781-does-anyone-use-php-like-this/#findComment-1044764 Share on other sites More sharing options...
Mchl Posted April 19, 2010 Share Posted April 19, 2010 Oh boy... where will you find MySQL DOS client? Quote Link to comment https://forums.phpfreaks.com/topic/198781-does-anyone-use-php-like-this/#findComment-1044773 Share on other sites More sharing options...
Daniel0 Posted April 19, 2010 Share Posted April 19, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/198781-does-anyone-use-php-like-this/#findComment-1044792 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.