The dead horse, PHP or asp.net?

Parmenides

Supreme [H]ardness
Joined
Apr 25, 2006
Messages
6,578
I know this dead horse has been beaten dead 10 years ago. There are millions of topics on the subject on google. But I still have to ask as I'm indecisive.

I have a web project that I want to do on the side. I want to have a good variety of data from various database tables served up quickly. The site is not a stackoverflow site, but think similarly. My project will have a variety of relational data served up into a single page. So in the end I want something that scales well and shouldn't struggle with performance.

For my day job, I'm a asp.net C# web developer. About half the time is spent on MVC, which I really like (asp.net "forms" can die). I also I think MVC/C# is pretty elegant stuff to code with for the most part. So I'm comfortable with asp.net.

However, I am curious about learning PHP, and it wouldn't hurt my resume to learn PHP. And since my project would be done during night hours and weekends, it might be a nice variety to write something different than with my day job. Variety is the spice of life. What gets me about PHP a little, is that it is interpreted, so things like for loops take a lot longer than asp.net C#. If I go with PHP I might always get the nagging feeling that my site will would have better performance if if I went with asp.net MVC. As an aside, is this 'hip hop' PHP stuff something that the common man uses yet? (well supported by the community, easy to get hosting for, etc..)

And then there is hosting price. Right now, shared hosting difference between asp.net vs. php is negligible. But what if my project takes off and I need to scale to a virtual private server? MS SQL is expensive! Does asp.net + MS SQL get expensive once you move beyond shared hosting? Would asp.net + MySQL be a viable option? Does the LAMP stack cost much less than the MS solution once you move beyond shared hosting? I suppose you could even throw more hardware at the solution when you don't have to pay software licensing fees.

Well let me know what you think.
 
Last edited:
Don't spend so much time trying to prematurely optimize or rationalize your thoughts on one programming language versus another. It's way to soon to contemplate that.

Since you're more comfortable on the .NET stack, then do your first incarnation there. Once you feel like you've worked out the general "new development" kinks, then re-write it in another language you are trying to learn. Having a blueprint (ie: the working site) would give a decent target to replicate in a new language.

Hosting costs are trivial, and the decent hosts have the ability and knowledge to scale and support different environments. Again, not a major point to worry about.

Good luck with your endeavor! Feel free to post questions as you go.
 
Last edited:
Why PHP?

I work with PHP on a daily basis.
I don't like it. In fact, I hate it. You will hate it, too, since you're coming from a C# environment. PHP is an unholy mess.

PHP is not fully object oriented. For some things, there are procedural ways and object oriented ways. For others, there's procedural only style. Mix and match, how fun...

PHP's syntax is ugly and inconsistent. Some functions / methods use underscores, some use camel case, whatever floats anybody's boat. New language additions often have to use odd and awkward syntax (take a look at namespaces, for example).

Then there are community disputes. In one version you're allowed to use <?=, in others you are not, or it gets flagged by some setting.

Why do you want to learn PHP?

With that out of the way...
Learn something useful that you will enjoy working with. A Ruby framework (Rails, Sinatra, Pedrino) or perhaps go for Groovy (Grails, haven't work with it).
 
wow a lot of PHP haters here.
it is not perfect but he wasn't asking about that.

OP, if you want to learn PHP for the fun of it then go ahead.
as far as performance, you won't see any performance difference unless you have a very large amount of traffic.

There are some good PHP frameworks, my favorite is CodeIgniter

Hosting for Linux is definitely cheaper, there are no MS fees
It's also much easier to find Linux hosting companies
A LAMP stack is very common and extremely easy to set up, I personally use nginx instead of apache.
 
Why PHP?

I work with PHP on a daily basis.
I don't like it. In fact, I hate it. You will hate it, too, since you're coming from a C# environment. PHP is an unholy mess.

PHP is not fully object oriented. For some things, there are procedural ways and object oriented ways. For others, there's procedural only style. Mix and match, how fun...

PHP's syntax is ugly and inconsistent. Some functions / methods use underscores, some use camel case, whatever floats anybody's boat. New language additions often have to use odd and awkward syntax (take a look at namespaces, for example).

Then there are community disputes. In one version you're allowed to use <?=, in others you are not, or it gets flagged by some setting.

Why do you want to learn PHP?

With that out of the way...
Learn something useful that you will enjoy working with. A Ruby framework (Rails, Sinatra, Pedrino) or perhaps go for Groovy (Grails, haven't work with it).

what about python/django? is that a good alternative to PHP?

Excuse the noob question. :p
 
PHP is a tragedy to learn and use.. it makes me sad that it's in such wide adoption.
Want to learn new web technologies? Focus on HTML5.
 
PHP's syntax is ugly and inconsistent. Some functions / methods use underscores, some use camel case, whatever floats anybody's boat. New language additions often have to use odd and awkward syntax (take a look at namespaces, for example).

Then there are community disputes. In one version you're allowed to use <?=, in others you are not, or it gets flagged by some setting.
.

I recently started working with PHP I found what you mentioned to be the case but jesus I picked up the language quickly, faster than any .net language(of course I would not know all it's, PHP, idiosyncrasies).
 
PHP is a tragedy to learn and use.. it makes me sad that it's in such wide adoption.
Want to learn new web technologies? Focus on HTML5.
HTML5 has its place, but the recommendation shouldn't be worded as an alternative to the options suggested thus far, but as an "in addition to ____".
 
I recently started working with PHP I found what you mentioned to be the case but jesus I picked up the language quickly, faster than any .net language(of course I would not know all it's, PHP, idiosyncrasies).

The only reason you picked it up quickly is because it doesn't care what you do.

Throw a bunch of php tags in with your html and js. Mix in db queries with conditionals that output different html, etc..

If you program with this mentality (and this is the #1 thing most new web programmers would do) then it does produce fast results and it seems painless to setup and get into. It's not that the language is easy to use, it just doesn't try to impose any form of structure on how you go from a blank slate to a finished web page. You might not even be aware of needing structure. You just code and hit F5, then see the results.

It's a dangerous path to go down and it's not a problem with php (you can structure php code), it's just most prevalent with php.
 
I myself am a .NET developer for my day job but enjoy using PHP for my personal projects. Haters are gonna hate. Don't let anyone turn you off from learning different things just because they don't like them.
 
The only reason you picked it up quickly is because it doesn't care what you do.

Throw a bunch of php tags in with your html and js. Mix in db queries with conditionals that output different html, etc..

If you program with this mentality (and this is the #1 thing most new web programmers would do) then it does produce fast results and it seems painless to setup and get into. It's not that the language is easy to use, it just doesn't try to impose any form of structure on how you go from a blank slate to a finished web page. You might not even be aware of needing structure. You just code and hit F5, then see the results.

It's a dangerous path to go down and it's not a problem with php (you can structure php code), it's just most prevalent with php.


The other thing is I find php easier to read/understand coming from an HTML mindset. I dunno why, but it just is.

I am not a developer, but I have to tweak code and make slight modifications often in web development. PHP by far was easier for me to pickup from reading and looking at than asp.
 
It's a dangerous path to go down and it's not a problem with php (you can structure php code), it's just most prevalent with php.

Right, it's part of PHP's user-culture. It's also possible to write excellent VB apps; most people just don't.

I don't seen any reason not to learn PHP. I feel diversifying your knowledge and experiences is always valuable to some extent. However, I would advise learning fundemental programming concepts in a more strict, mistakes-are-painful environment so that when you reflect back to PHP you will know how to write excellent code.
 
Last edited:
The only reason you picked it up quickly is because it doesn't care what you do.

Throw a bunch of php tags in with your html and js. Mix in db queries with conditionals that output different html, etc..

If you program with this mentality (and this is the #1 thing most new web programmers would do) then it does produce fast results and it seems painless to setup and get into. It's not that the language is easy to use, it just doesn't try to impose any form of structure on how you go from a blank slate to a finished web page. You might not even be aware of needing structure. You just code and hit F5, then see the results.

It's a dangerous path to go down and it's not a problem with php (you can structure php code), it's just most prevalent with php.

I program in C++. I am not a new programmer here and your statement is a gross exaggeration.
 
I program in C++. I am not a new programmer here and your statement is a gross exaggeration.

How is it a gross exaggeration? If you Google for "learn php" or "php tutorials", the first results you'll see are examples where everything is mixed up. Heck, even the tutorial of the official documentation does it too.

Guess what new programmers are going to do when they want to learn php? Yep, they are going to be searching for those terms most likely. What happens when new programmers search for those terms and then follow the tutorials they viewed? They produce mixed up spaghetti code but they are happy because it's easy to get into.
 
How is it a gross exaggeration? If you Google for "learn php" or "php tutorials", the first results you'll see are examples where everything is mixed up. Heck, even the tutorial of the official documentation does it too.

Guess what new programmers are going to do when they want to learn php? Yep, they are going to be searching for those terms most likely. What happens when new programmers search for those terms and then follow the tutorials they viewed? They produce mixed up spaghetti code but they are happy because it's easy to get into.

Just develop on a solid state drive and get used to "Find in Files" search. Ctl + Shift + F, then your'e all good. Who cares about the mess. :p (Just joking)




Thanks a lot guys!, continue on the debate / banter / advice giving. I might try something along the lines of what PTNL said, and start things off in .NET while I'm still working out my basic ideas for the site. That way I don't have to learn and plan ideas at the same time (though I do enjoy doing a little bit of that too on occasion). Then maybe move stuff over to PHP at some point. At least I'm leaning that way, anyways, carry on with the discussion!

There does seem to be conflicting information on hosting comparisons. My guess is the operating system isn't what costs. It's the database that gets expensive, particularly MS SQL. no?
 
There does seem to be conflicting information on hosting comparisons. My guess is the operating system isn't what costs. It's the database that gets expensive, particularly MS SQL. no?
It's a pointless debate, especially since your own budget isn't specified. If you can afford up to $20/month, then don't worry. The quality hosts have their own software, maintenance, and support costs with their vendors -- MS, Redhat, MySQL, Dell, HP, etc. Debating about their costs is beyond out-of-scope of this thread.

The one point I would stress, however, is to register your domain name yourself -- don't let a host register it. If you need to jump from one host to another in the future, the process could be much easier for you when you have account control of the domain name.
 
godaddy.com has .net/mssql for $5/mo... that's dirt cheap for any hosting.
 
Just develop on a solid state drive and get used to "Find in Files" search. Ctl + Shift + F, then your'e all good. Who cares about the mess. :p (Just joking)

You know, even as a joke that type of mentality is kind of true. I used to think like that a while back. Long story short, it really is a waste of time but can produce results and might not even seem that bad on the surface if you work alone.
 
as far as performance, you won't see any performance difference unless you have a very large amount of traffic.
It's easy to see the perf problems in PHP without having traffic. Just use a profiler or benchmarking tool.
 
I'll just leave this here:
http://www.codinghorror.com/blog/2012/06/the-php-singularity.html
http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/

I don't want to discourage anybody from learning new languages and implementation practices. That said, though, I want to encourage people to learn practical and sustainable languages which promote cleaner coding habits.
If you need to use PHP for a project, for whatever reason, then great... the strength of a good programmer is in their versatility. Nothing annoys me more than a coder coming into an interview and talking about how they refuse to work in language-X (and this happens, really).
 
How is it a gross exaggeration? If you Google for "learn php" or "php tutorials", the first results you'll see are examples where everything is mixed up. Heck, even the tutorial of the official documentation does it too.

Guess what new programmers are going to do when they want to learn php? Yep, they are going to be searching for those terms most likely. What happens when new programmers search for those terms and then follow the tutorials they viewed? They produce mixed up spaghetti code but they are happy because it's easy to get into.
I totally dissagre with this, everything you said is just based on the assumption that coders never evolve or never learn how to code "right".

Who cares if the code is messy and sloppy the first month or 2 while learning a new language, if someone still write ugly and inconsistent after a couple of month, then its the programmers fault, not the language.

When i learned PHP a couple of years ago i did exactly like you said, i followed random tutorials all over the internet, far away in the dark corner of the internet and if you would compare the code i write today with those tutorials there is no similarities at all.
 
I totally dissagre with this, everything you said is just based on the assumption that coders never evolve or never learn how to code "right".

Who cares if the code is messy and sloppy the first month or 2 while learning a new language, if someone still write ugly and inconsistent after a couple of month, then its the programmers fault, not the language.

When i learned PHP a couple of years ago i did exactly like you said, i followed random tutorials all over the internet, far away in the dark corner of the internet and if you would compare the code i write today with those tutorials there is no similarities at all.

How can you disagree with something you've done first hand? Also I made sure I included the phrase "new programmers" more than once to hopefully get the point across that I'm actually talking about new programmers looking to get into php. I'm not sure how I could have been more clear.

I would care that the first 2 or 6 months of writing code was essentially wasted because the initial tutorials I was given by the developers of the language told me to write my code in a such a naive way. There are multiple other languages and frameworks out there that teach you good practices as you go straight from the beginning.
 
It's not even about good coding practices. PHP is broken from ground up, plagued by legacy code or assumptions made by developers of the language >10 years ago. Programming has evolved since then.

Want examples? I can gladly provide you with a wide variety.

That's the story. If you disagree, then you simply haven't used anything better (there are worse tools out there...).
 
How can you disagree with something you've done first hand? Also I made sure I included the phrase "new programmers" more than once to hopefully get the point across that I'm actually talking about new programmers looking to get into php. I'm not sure how I could have been more clear.

I would care that the first 2 or 6 months of writing code was essentially wasted because the initial tutorials I was given by the developers of the language told me to write my code in a such a naive way. There are multiple other languages and frameworks out there that teach you good practices as you go straight from the beginning.
I disagreed because it is pretty weird to not recommend a language just because some of the tutorials are shit, its pretty easy to get hold of good tutorials, phpAcademy have some pretty nice tutorials for beginners so they can kickstart their coding and focus on good practices right from the start.

Those first months is definitely not wasted, usually people learn how to do stuff right by doing it wrong first, its so easy so learn from mistakes. Also, the basics learned in the first month is obviously still used alot in the future to so its definitely not a waste of time. PHP isnt so bad as some people want it to be.

Also, this is a person that wants to complement his resume, knowing PHP is probably the language he have most use of, PHP is still one of the most used language out there, and even if new projects with PHP is starting to decline there is still use for it a very minimum of 10 years, companies that have a products written in PHP will most likely not rewrite their product in another language anytime soon. So yeah, in a career perspective i wouldnt discourage him from learning PHP.
 
It's not even about good coding practices. PHP is broken from ground up, plagued by legacy code or assumptions made by developers of the language >10 years ago. Programming has evolved since then.

Want examples? I can gladly provide you with a wide variety.
I think I'd benefit from hearing a few.
 
I think I'd benefit from hearing a few.

Constructs versus functions:
Let's save we have a function named foo that returns something.
Code:
if( empty(foo()) ) {
  // oh no, foo is empty
}
Will not work as one would think. empty() has to take a variable for it's argument. isset() works the same way. If you have worked with PHP for more than 5 minutes, you'd see this issue arise.

Syntax with functions and constructs:
Code:
echo 'good';
echo('good');
Both are equivalent. Again, confusion between language constructs and functions.

Weird decisions with printing to standard output:
Code:
print_r($myvar);
Why not let echo do the work? Some function output to standard output, some don't... Why the discrepancies? To make the situation event better, some functions let you redefine what they do:
Code:
print_r($myvar,true);
Will return the value instead. Nice.

TRUE vs true
Do you know the differences between the two? I don't. Don't know if there are any. Why should the developer care?

Beautiful modern syntax
Code:
\Foo\Bar\foo::mymethod();
Using namespaces couldn't be any more intuitive.

System discrepancies
Well, I learned it the hard way. Although this useful tag might be supported, <?= ?>, it might or might not be disabled on the system. Contact your system administrator. :rolleyes:

Okay... So these were *some* annoyances that I could name from the top of my head. I know Ruby quite well, so let me compare that to PHP. Let's say I want to capitalize each letter in a string. In Ruby, I could accomplish this with the following one liner:
Code:
"I am walking home".split(' ').map { |w| w.capitalize }.join(' ')
# I Am Walking Home
In PHP... Err, let me start by saying that PHP does not have an interactive shell. I came up and tested the above example in Ruby irb in a few seconds. And don't mention php -a or whatever it is, it is beyond poor. So, here's my best bet:
Code:
$myvar = 'I am walking home';
$myar   = str_split($myvar);
$newstr = '';
for($i = 0; $i < count($myar); $i++) {
  $newstr .= ucfirst($myvar[$i]);
}
... I guess I could have used foreach, now that I think about it. Either way - PHP code is 4 lines, Ruby is 1.

This also shows another strength or Ruby vs PHP - Ruby is fully object oriented. PHP is not. This allows for nice one liners like this.

One last thing that I want to mention... What about "the cloud"? It seems to be the future of web development at this point. PHP is not a good choice for the cloud.

Ruby rack based web applications: reside in RAM
PHP web applications: typically reside on a hard drive

So let's say we have couple thousand pcs to deploy an application on. All Ruby host servers can load the application from the main server, and that's it. No more reading from the primary application storage, as the application is now in RAM, unless you want static files.

In PHP, these thousand pcs that we speak of have to either copy the web app over or hammer the central location. I don't think either choice is good, but I am sure there are alternatives, as I am no expert in the field (facebook being an example?).

Alright, so that's my .02 on PHP. It's no good by today's standards.

EDIT:
Oh, forgot to mention. How about that one giant global namespace where thousandths of functions reside in?
 
Oh, forgot to mention. How about that one giant global namespace where thousandths of functions reside in?
I was waiting for that one... Oh and it does have a ToUpper function (strtoupper) - yeah they don't use camalCase (or anything to break up function names) either, well somtimes they do.:eek:

As far as I'm aware facebook only uses the php syntax, but it is compiled into C++ with their own compiler.

Back on topic: Overall the language isn't that bad, it isn't very complex so you can pick it up fast, the downside is the code files can get very big. It doesn't encourage you to split things up the same way as you would in MVC and as Krogen mentioned it isn't a pure object orientated language. But it doesn't hurt to learn with a new language.

If I was in your shoes, I'd get it live using tools I enjoy (MVC) and worry about optimisation later. SQL Server Express is free and it can handle 10gigs of data - I'm sure you will hit other performance problems before you outgrow that and need to look at other options.
 
Code:
$myvar = 'I am walking home';
$myar   = str_split($myvar);
$newstr = '';
for($i = 0; $i < count($myar); $i++) {
  $newstr .= ucfirst($myvar[$i]);
}

Since php treats strings like arrays as default, I don't understand what the purpose of the str_split() function even is. Maybe php didn't always treat strings as arrays and it is a leftover from that? That being said you could alternatively write it like this:
Code:
$myvar = 'I am walking home';
$newstr = '';
for($i = 0; $i < strlen($myvar); $i++) {
	$newstr .= ucfirst($myvar[$i]);
}

You could also use strtoupper() like Wiseguy2001 said.

One of the biggest problems I've run into with php is that it doesn't do garbage collection until after the script has finished. One would expect unset() to free memory once a variable is destroyed, or variables going out of scope to have their memory reclaimed.

On a side note the php developers added goto in version 5.3, I'm not sure why.
 
strtoupper() just makes the entire string in caps. He only wanted to cap the first letter of each word.

I don't program in PHP anymore but a quick Googling shows that they do have a function for this called ucwords(). That is one benefit of PHP. There's so much documentation. Back when I was actively programming with it, I didn't even know that function existed but to be fair I never needed that functionality.
 
I guess it really comes down to whether you prefer working with nix servers or do you prefer working with windows servers? asp.net is windows only. While I prefer windows 7 for my desktops, I think unix is mandatory for anything server related yeah?
 
Since php treats strings like arrays as default, I don't understand what the purpose of the str_split() function even is. Maybe php didn't always treat strings as arrays and it is a leftover from that? That being said you could alternatively write it like this:
Code:
$myvar = 'I am walking home';
$newstr = '';
for($i = 0; $i < strlen($myvar); $i++) {
	$newstr .= ucfirst($myvar[$i]);
}

You could also use strtoupper() like Wiseguy2001 said.

One of the biggest problems I've run into with php is that it doesn't do garbage collection until after the script has finished. One would expect unset() to free memory once a variable is destroyed, or variables going out of scope to have their memory reclaimed.

On a side note the php developers added goto in version 5.3, I'm not sure why.

Why would PHP treat strings as arrays? I didn't know that. That's not very intuitive. If it does - my point that I was making is even more obvious. There's obviously a big difference between an array and a string. If a string is treated as an array - an assumption has to be made - the split character.

Why make language-specific assumptions? I'm guessing this was one of the hurdles with PHP 6.

Sorry - none of this was directed towards you.

And, yes, as ShoeLace pointed out I wanted to capitalize first letter of every word in my sentence.
 
Why would PHP treat strings as arrays? I didn't know that. That's not very intuitive.
Strings are naturally arrays. Lots of languages allow for that kind of access, so it shouldn't be surprising (and certainly isn't a defficiency) that PHP does, too. You can see the strings page for more details; start at the "String access and modification by character" heading. There's no need for a split character -- each character of the string is in an element of the array.
 
I guess it really comes down to whether you prefer working with nix servers or do you prefer working with windows servers? asp.net is windows only. While I prefer windows 7 for my desktops, I think unix is mandatory for anything server related yeah?
Mono support and functionality is growing by leaps and bounds. PHP works adequately on IIS. Unix isn't the mandatory choice for servers -- that decision should be based more on the web applications you want/need to run.
 
Strings are naturally arrays. Lots of languages allow for that kind of access, so it shouldn't be surprising (and certainly isn't a defficiency) that PHP does, too. You can see the strings page for more details; start at the "String access and modification by character" heading. There's no need for a split character -- each character of the string is in an element of the array.

Ok. Based on Sgraffite example I assumed that PHP treats each word as an element of an array, hence my reference to the split character. (My example was uppercasing first letter of each word... I assumed his loop did the same thing.)

When talking about each character, I wouldn't go as far as calling a word a "natural array". UTF-8 word wouldn't be a good example as each character can take up multiple bytes. It's up to the language the abstract that at that point.
 
In Javascript you can do something like: var myString = "hello";

myString[1] returns "e". That is array-like behavior. I always thought strings were just an array of characters and was common across most languages.
 
I always thought strings were just an array of characters and was common across most languages.
And you're right.

Ok. Based on Sgraffite example I assumed that PHP treats each word as an element of an array, hence my reference to the split character. (My example was uppercasing first letter of each word... I assumed his loop did the same thing.)
I can't guess how you made that assumption as strlen() returns the number of characters in the string, not the number of words, so the loop uses a numeric index to index character within the string.

When talking about each character, I wouldn't go as far as calling a word a "natural array". UTF-8 word wouldn't be a good example as each character can take up multiple bytes. It's up to the language the abstract that at that point.
Variable length encoding makes things interesting, but the string is still an array. It might be considered an array of bytes (instead of an array of characters), or an array of 16-byte characters.

Tell me; if a string is not an array, how do you envision it being represented?
 
Last edited:
And you're right.

I can't guess how you made that assumption as strlen() returns the number of characters in the string, not the number of words, so the loop uses a numeric index to index character within the string.

At first glance I assumed that's what he was saying - PHP classifying strings as array of words. I didn't look if he used a for loop, a for each, or an iterator. Sorry for not examining his example better.

Variable length encoding makes things interesting, but the string is still an array. It might be considered an array of bytes (instead of an array of characters), or an array of 16-byte characters.

Tell me; if a string is not an array, how do you envision it being represented?

In an object oriented world, a string is it's own class. That's how it's represented. A string is not an array. Even low level languages such as C++ make a distinction (implement a string class). Only if you truly want to go low-level you can represent a string as an array of characters, but then your whole world falls apart due to character length that you mentioned. That's the purpose of the string class - so that you don't have to think of a string as an array.

And, if you really wanted to get technical with this, I could write a String class using a linked list. Or some other data structure. So, no, even internally you could avoid arrays altogether.

Side note: in a pure object oriented language, an array is almost always a class (Ruby, for example). Again, a string is not an array. For a giggle, here's what Ruby irb tells me:
Code:
['a','b','b'] == 'abc'
# false
 
To continue my last thought, if PHP arrays were strings, this should probably print true, but it doesn't. It prints false.

Code:
<?php
var_export( (array('a','b','c') == 'abc') ); ?>
 
Back
Top