origil Posted August 22, 2007 Share Posted August 22, 2007 Hey, I am new to php programming and I come from a C++ background. My general question is how to write my webpages as there is a lot of code reuse. In C++ I would include many files to a page, making many functions accessible to them, thus reusing code efficiently. This greatly speeds up development time and perhaps only slows compilation time by a bit. In Php, however, I am afraid this might slow down the server. For example, I have 2 choices: 1. The ugly and maybe faster for the server way: Copy paste a lot of code and modify small parts. (Example: I have many pages dealing with text input forms - same structure, only different names to forms) 2. The nice clean but maybe slower for the server way: Create functions that generate the desired html code. As well as include some of my php function files I might not use in some pages. I would go with option 2 if I only knew how much extra work is there for the server. Is this a consideration? When a website has 10 users this would not matter. But what if there are a thousand users? How much of an issue is this on the long run? Thanks in advance, Ori Quote Link to comment https://forums.phpfreaks.com/topic/66160-solved-the-server-enemy-or-friend/ Share on other sites More sharing options...
trq Posted August 22, 2007 Share Posted August 22, 2007 The actual execution time between 1 & 2 would be minimal. I wouldn't even worry about it. Of course you should always code for code reuse, includes run as though the code is actually within the same file. As for including functions that you may not use in every page, I wouldn't worry too much about it. Quote Link to comment https://forums.phpfreaks.com/topic/66160-solved-the-server-enemy-or-friend/#findComment-330932 Share on other sites More sharing options...
Fadion Posted August 22, 2007 Share Posted August 22, 2007 I'd go for the second approach without thinking twice. When a website got thousands of users i would care about server hardware (ram and cpu) and bandwidth limits, instead of optimizing nanoseconds in my script. Quote Link to comment https://forums.phpfreaks.com/topic/66160-solved-the-server-enemy-or-friend/#findComment-330935 Share on other sites More sharing options...
tarun Posted August 22, 2007 Share Posted August 22, 2007 Isn't Nice Clean Code Much Easier To Read For The Server Than Ugly Code Well... When It Comes To It I Value The Layout Of My Code.. But Thats Only So It's Easy On My Eyes OFF TOPIC: And Can I Ask - Is C++ Like C#? I Tried A Bit Of C++ And Gave Up And Switched To C# And Also What Software Do You Use? (I Used Visual C# Express + Visual C++ Express) Quote Link to comment https://forums.phpfreaks.com/topic/66160-solved-the-server-enemy-or-friend/#findComment-330936 Share on other sites More sharing options...
origil Posted August 22, 2007 Author Share Posted August 22, 2007 Thank you all for the replies. Phew... Option 2 it is then. No more ugly code! Traun, as for your off topic question, I am not too familiar with C# but as I heard it is a higher level language than C++. Meaning it simplifies many development issues (which leads to faster development) but cannot compete with file sizes and execution time. The syntax is highly similar to C++ but C# also has shares many of the Java features. I guess overall it is an improved version of C++: does more work for the programmer and is more strict on many issues which often lead to many bugs in C++. About slower execution time and file size - a really small price to pay with today's hardware. (Just as assembly is faster than C++). Quote Link to comment https://forums.phpfreaks.com/topic/66160-solved-the-server-enemy-or-friend/#findComment-330950 Share on other sites More sharing options...
tarun Posted August 22, 2007 Share Posted August 22, 2007 ;) ;) Thanks ;) ;) Quote Link to comment https://forums.phpfreaks.com/topic/66160-solved-the-server-enemy-or-friend/#findComment-330960 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.